74

I program with Emacs on Ubuntu (Hardy Heron at the moment), and I like the default text coloration in the Emacs GUI. However, the default text coloration when Emacs is run in the terminal is different and garish.

How do I make the colors in the terminal match the colors in the GUI?

3
  • 2
    I'd like to achieve the opposite. I like syntax colours in -nw mode. Is that possible?
    – aL3xa
    Dec 28, 2010 at 1:50
  • You need to know What the default color theme when running Emacs with -nw is.
    – SabreWolfy
    Feb 20, 2012 at 20:54
  • 2
    I too would like to know the solution to the opposite problem, how do I set the color theme in emacs to resemble the color theme in emacs -nw?
    – Bart Snapp
    Apr 6, 2014 at 18:13

5 Answers 5

124

You don't have to be stuck to your terminal's default 16 (or fewer) colours. Modern terminals will support 256 colours (which will get you pretty close to your GUI look).

Unfortunately, getting your terminal to support 256 colours is the tricky part, and varies from term to term. This page helped me out a lot (but it is out of date; I've definitely gotten 256 colours working in gnome-terminal and xfce4-terminal; but you may have to build them from source.)

Once you've got your terminal happily using 256 colours, the magic invocation is setting your terminal type to "xterm-256color" before you invoke emacs, e.g.:

env TERM=xterm-256color emacs -nw

Or, you can set TERM in your .bashrc file:

export TERM=xterm-256color

You can check if it's worked in emacs by doing M-x list-colors-display, which will show you either 16, or all 256 glorious colours.

If it works, then look at color-theme like someone else suggested.

(You'll probably get frustrated at some point; god knows I do every time I try to do something similar. But stick with it; it's worth it.)

4
  • 2
    This is great, I added "export TERM=xterm-256color" to my .profile so I don't need to run it every time. Oct 1, 2010 at 5:55
  • 1
    You can also do TERM=xterm-256color emacs to launch Emacs with a 256-color terminal without exporting the environment variable.
    – SabreWolfy
    Feb 20, 2012 at 20:53
  • My emacs changes its palette if was run from an 88 or 256-color terminal as well as with TERM=xterm-256color or TERM=rxvt-unicode-256color. But no one of those palettes is one I customized in X version.
    – tijagi
    Jan 17, 2013 at 5:04
  • 2
    In case someone else comes here while searching for a solution to running emacs -nw inside an iTerm window on Mac OS X, note that you can tell iTerm to report the terminal type as xterm-256color. Go to Preferences ➜ Profiles ➜ Terminal and set the field "Report Terminal Type".
    – mhucka
    Feb 8, 2014 at 19:08
2

I'm not sure if it is possible, as the GUI may have more capabilities than the terminal (yes, I've seen GUI terminals with only 16 colors very recently). It may depend on how the terminal is set. At any rate I would play with Color Theme.

Anyway, why are you using Emacs in both, the terminal and the GUI? Generally people find one or the other appealing and use only that one. If you are using Emacs remotely, maybe you want to run it locally and use Tramp to open files remotely, or as root.

1
  • 1
    A common use case is to use the gui version locally and on the command line remotely, maybe nested through several layers of ssh connections, on a diversity of machines.
    – quazgar
    Sep 8, 2017 at 8:53
0

A little late response but I had the problem with the black background showing up as grey. I fixed it by playing around with palette.

edit > Profile Preferences > Color > Palette

0

I was able to get pretty close with emacs 26.

I followed the Emacs FAQ to get 24-bit colors working: https://www.gnu.org/software/emacs/manual/html_mono/efaq.html#Colors-on-a-TTY

And then I changed the xterm-standard-colors variable:

(set 'xterm-standard-colors
  '(("black"          0 (  0   0   0))
    ("red"            1 (255   0   0))
    ("green"          2 (  0 255   0))
    ("yellow"         3 (255 255   0))
    ("blue"           4 (  0   0 255))
    ("magenta"        5 (255   0 255))
    ("cyan"           6 (  0 255 255))
    ("white"          7 (255 255 255))
    ("brightblack"    8 (127 127 127))
    ("brightred"      9 (255   0   0))
    ("brightgreen"   10 (  0 255   0))
    ("brightyellow"  11 (255 255   0))
    ("brightblue"    12 (92   92 255))
    ("brightmagenta" 13 (255   0 255))
    ("brightcyan"    14 (  0 255 255))
    ("brightwhite"   15 (255 255 255)))
  )

(I did not change the "bright*" colors because I don't use them, and they don't seem to be available in list-colors-display in X11 emacs, anyway)

With those two changes, colors look pretty much identical between X11 and terminal for me.

-1

I don't think that is possible in such a general way. With the terminal you are usually bound to some pre-defined colors (with things like gnome-terminal you can adjust these colors -- but you are still stuck to a predefined, limited number of colors).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.