When I am coding or doing other stuff, I usually run emacs on an X window. And I set the background to white. But sometimes I prefer to run it from the terminal. For example, in non-graphical ssh sessions (duh), and specially when I invoke emacs from within mutt, my beloved e-mail reader.
The problem is that in the terminal, running emacs from the console, I would prefer to switch the colors, and have a black background. I was setting this by changing the colors in the mail mode, which I only entered when usng mutt. But today I wanted it to get back to black regardless of the mode, because I was configuring mutt to talk to org-mode.
So what I needed was some kind of hook that was activated when emacs was run in text mode (console, terminal, not the emacs “text-mode”). Well, turns out there is no hook like that, but emacs has something even better. You can actually create files for
terminal specific configuration. All you need is to put the file in the proper place!
First I had to discover the value of the TERM environment variable, used by emacs to know what to do. From within emacs tried
and it returned me “dumb”, which was incorrect. (Unless it was talking about me! 😛 ) The correct value in the end was “xterm”. (Note that I use xterm as my terminal…)
So all I had to do in the end was to place this term/xterm.el file in my lisp path, and put there the color configurations I wanted, and voilá, black background emacs for console sessions… Isn’t that great? 🙂 (Yeah, great, but took me the whole afternoon to find out! 😦 )
This is my terminal mode configuration for emacs…
(set-background-color "black") (set-face-background 'default "black") (set-face-background 'region "black") (set-face-foreground 'default "white") (set-face-foreground 'region "gray60") (set-foreground-color "white") (set-cursor-color "red")