In shell buffers inside Emacs (M-x shell), many programs want to use color in useful ways. For example, grep can highlight the portion of the line that matches the search pattern. Here's what I use to make Emacs and XEmacs show colors in shell windows:

;;; Shell mode
(setq ansi-color-names-vector ; better contrast colors
      ["black" "red4" "green4" "yellow4"
       "blue3" "magenta4" "cyan4" "white"])
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

I also use these settings to turn off word wrap and to make the prompt read-only:

(add-hook 'shell-mode-hook '(lambda () (toggle-truncate-lines 1)))
(setq comint-prompt-read-only t)

Shell mode is handy but I find that I often just switch to a terminal window, mainly because I can pipe commands through less. If the output is very short, either Emacs or a terminal is fine. If it's of medium length, Emacs is usually nicer, since it lets me search and cut and paste easily. If the command has very long output, the terminal is nicer, because less lets me see just parts of the output. I haven't found a way in Emacs to deal with processes that output lots of lines.

Labels:

5 comments:

Alok wrote at April 25, 2007 6:18 AM

That is curious. I don't use the Emacs shell. But looks like obviously entering a command which can read keyboard input or dump terminal code output does not work well with emacs.

Matt wrote at May 01, 2007 7:42 AM

Why not just use use M-x term (or M-x ansi-term) instead?

Amit wrote at May 01, 2007 8:40 AM

Matt, the main reason I haven't used M-x term is that I learned about it after I formed my habits. I should try it though and see if it's worth changing my habits. :-)

Matt wrote at May 01, 2007 12:08 PM

Ah, I wasn't aware ansi-term is not available in XEmacs.

Arky wrote at February 11, 2009 7:12 AM

I think I like M-x ansi-term better. I use it on Emacs-Gtk most of the time

Post a Comment