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: emacs
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.
Why not just use use M-x term (or M-x ansi-term) instead?
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. :-)
Ah, I wasn't aware ansi-term is not available in XEmacs.
I think I like M-x ansi-term better. I use it on Emacs-Gtk most of the time
Thanks! Works great!
Emacs shell is my IDE for almost everything. It's very very powerful and convenient. I have multiple shells open, renamed to something nice. And I can cut and past between them, save output as "log" files, instantly create shell scripts. Better than bash for sure.
Start using that shell and continue.
For special cases, use "ansi-term" which provides a nice display, with lots less flexibility (handles "man ls" for example).
I don't suppose anybody's got colors working for shell on emacs 27?
Post a Comment