Terminal emacs colors only work with TERM=xterm-256color

前端 未结 6 1432
攒了一身酷
攒了一身酷 2020-12-07 16:12

I\'ve found that terminal emacs does not render the correct colors unless I explicitly set TERM=xterm-256color. I use gnome-terminal, and from what I understand, TERM should

6条回答
  •  旧时难觅i
    2020-12-07 16:30

    Add this to your ~/.emacs:

    (add-to-list 'term-file-aliases
        '("st-256color" . "xterm-256color"))
    

    It tells emacs that if it sees TERM=st-256color then it should initialize the terminal as if it had seen TERM=xterm-256color.


    Longer answer:

    Emacs is showing strange colors because it thinks your terminal can only support 8 colors. In Emacs, run M-x list-colors-display to see the colors it thinks are available. The correct number of colors is detected during terminal-specific initialization. It says, in part:

    Each terminal type can have its own Lisp library that Emacs loads when run on that type of terminal.

    On my machine, the terminal-specific initialization files are in /usr/local/share/emacs/25.*/lisp/term. It has files for xterm, rxvt, screen, etc. but nothing for st. We need to help Emacs find the right initialization file. The documentation further says:

    If there is an entry matching TERM in the term-file-aliases association list, Emacs uses the associated value in place of TERM

    So that association list is a recommended way to handle unknown terminals. It works without you having to manually override the TERM environment variable.

提交回复
热议问题