终端 emacs 颜色仅适用于 TERM=xterm-256color [英] Terminal emacs colors only work with TERM=xterm-256color

查看:23
本文介绍了终端 emacs 颜色仅适用于 TERM=xterm-256color的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现终端 emacs 不会呈现正确的颜色,除非我明确设置 TERM=xterm-256color.我使用 gnome-terminal,据我所知,TERM 应该设置为 gnome-256color.同样,我倾向于经常使用 tmux,它建议不要使用除 screen-256color 以外的任何 TERM 设置.不幸的是,这两个设置(在它们各自的上下文中 - gnome-terminaltmux)导致 emacs 具有错误的颜色,而 vim 正确显示颜色.但是,如果我 export TERM=xterm-256color,颜色在 emacs 中工作得很好.

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 be set to gnome-256color. Similarly, I tend to use tmux a lot, which advises against any TERM setting other than screen-256color. Unfortunately, both of those settings (within their respective context - gnome-terminal or tmux) result in emacs having wrong colors, whereas vim displays colors correctly. However, if I export TERM=xterm-256color, the colors work just fine in emacs.

谁能解释一下发生了什么,或者提供解决方案?

Can anyone explain what's going on, or offer a solution?

这是我正在处理的:

通过将以下内容添加到我的 init.el 中,我可以使终端中的颜色看起来正确:

I can get the colors to look correct in the terminal by adding the following to my init.el:

(defun terminal-init-gnome ()
  "Terminal initialization function for gnome-terminal."

  ;; This is a dirty hack that I accidentally stumbled across:
  ;;  initializing "rxvt" first and _then_ "xterm" seems
  ;;  to make the colors work... although I have no idea why.
  (tty-run-terminal-initialization (selected-frame) "rxvt")

  (tty-run-terminal-initialization (selected-frame) "xterm"))

这感觉真的,真的错了.对此必须有一个合乎逻辑的解释......

This feels really, really wrong though. There has to be a logical explanation for this...

我对 terminfo 和 $TERM 在彩色终端行为过程中所扮演的确切角色知之甚少.如果始终使用 xterm-256color 是安全的(即使 $TERM 应该"是 gnome-256colorscreen-256color),我会去的.

I have very little knowledge of terminfo and the precise role that $TERM plays in the process of color terminal behavior. If it's safe to always use xterm-256color (even when $TERM "should" be gnome-256color or screen-256color), I'll go with that.

推荐答案

也许我不明白什么,买你为什么不像这样运行 emacs:

Maybe I'm not understanding something, buy why don't you run emacs like this:

TERM=xterm-256color emacs -nw

这样 Emacs 就有自己的 TERM 设置,你知道它是有效的.您也可以创建别名或将其包装在 shell-script 中.

This way Emacs has its own TERM setting that you know works. You can also make an alias or wrap this in shell-script.

这篇关于终端 emacs 颜色仅适用于 TERM=xterm-256color的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆