在新的Emacs 24.3中调整术语面板

13
如何在新Emacs中调整term字体以获得与ansi-term-color-vector相同的控制?Emacs 24.3的一个新特性似乎是改进了控制term缓冲区的字体机制,即:

变量term-default-fg-colorterm-default-bg-color现在已弃用,使用可自定义的字体term代替。

您可以通过自定义相应的 term-color-COLOR,term-color-underlineterm-color-bold字体来自定义如何显示ANSI终端颜色和样式。

Mastering Emacs 的 Mickey 评论道:

如果像我一样,您自定义了ansi-color-names-vector以更改默认的 term 颜色,则建议您现在切换到使用字体。好消息是,您可以根据需要更改每种ANSI颜色的不仅仅是颜色,这样就可以强制某些颜色使用不同的字体。

像Mickey一样,我也使用ansi-color-names-vector来确保我的term缓冲区在深色主题(如tango-dark)下颜色看起来不错。
(setq ansi-term-color-vector [unspecified “black” “red3” “lime green” “yellow3” “DeepSkyBlue?3” “magenta3” “cyan3” “white”])

但是现在这会导致一个错误:

"error in process filter: Invalid face; unspecified" 

为了使用新的字体 term,当我输入命令 M-x describe-face term 时,我看到以下内容:

Translated text:

为了使用新的字体 term,当我输入命令 M-x describe-face term 时,我看到以下内容:

[] Font Family
[] Font Foundry
[] Width
[] Height
[] Weight
[] Slant
[] Underline
[] Overline
[] Strike-through
[] Box around text
[] Inverse-video
[] Foreground
[] Background
[] Stipple
[x]  Inherit

但是我该如何调整这些设置才能获得使用ansi-term-color-vector所实现的相同效果呢?

更新

我仍然无法修复颜色。这是我使用M-x customize-theme tango-dark得到的菜单:

enter image description here

这是终端中难以看清的一种颜色/面的示例:

                              enter image description here

3个回答

10
在Emacs 24.3.1中,这对我设置term和ansi-term的颜色起作用了。只需将颜色更改为您喜欢的值(相应地调整背景),即可实现。
;; term
(defface term-color-black 
  '((t (:foreground "#3f3f3f" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-red
  '((t (:foreground "#cc9393" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-green
  '((t (:foreground "#7f9f7f" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-yellow
  '((t (:foreground "#f0dfaf" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-blue 
  '((t (:foreground "#6d85ba" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-magenta 
  '((t (:foreground "#dc8cc3" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-cyan
  '((t (:foreground "#93e0e3" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-white
  '((t (:foreground "#dcdccc" :background "#272822"))) 
  "Unhelpful docstring.")
'(term-default-fg-color ((t (:inherit term-color-white))))
'(term-default-bg-color ((t (:inherit term-color-black))))

;; ansi-term colors
(setq ansi-term-color-vector
  [term term-color-black term-color-red term-color-green term-color-yellow 
    term-color-blue term-color-magenta term-color-cyan term-color-white])

5
在Emacs 24.3中,您需要调整以下面部特征:
   ;; term
   `(term-color-black ((t (:foreground ,zenburn-bg
                                       :background ,zenburn-bg-1))))
   `(term-color-red ((t (:foreground ,zenburn-red-2
                                       :background ,zenburn-red-4))))
   `(term-color-green ((t (:foreground ,zenburn-green
                                       :background ,zenburn-green+2))))
   `(term-color-yellow ((t (:foreground ,zenburn-orange
                                       :background ,zenburn-yellow))))
   `(term-color-blue ((t (:foreground ,zenburn-blue-1
                                      :background ,zenburn-blue-4))))
   `(term-color-magenta ((t (:foreground ,zenburn-magenta
                                         :background ,zenburn-red))))
   `(term-color-cyan ((t (:foreground ,zenburn-cyan
                                       :background ,zenburn-blue))))
   `(term-color-white ((t (:foreground ,zenburn-fg
                                       :background ,zenburn-fg-1))))
   '(term-default-fg-color ((t (:inherit term-color-white))))
   '(term-default-bg-color ((t (:inherit term-color-black))))

这段代码来自Zenburn的最新版本。 个人认为,新的自定义面部的方式比使用晦涩的向量更加优越。

谢谢。您有什么想法或指点,我如何为像“tango-dark”这样的主题完成此操作?(即,我如何找出我的主题支持的不同颜色?例如“zenburn-bg-1”等,但针对“tango-dark”) - Amelio Vazquez-Reina
2
只需执行 M-x describe-theme tango-dark 命令,即可查看 tango-dark-theme.el 文件中的颜色定义。 - Bozhidar Batsov
1
谢谢 @Bodzhidar。我相信你是正确的,我可以按照你的步骤来解决这个问题,但是不幸的是我无法弄清楚如何使其在tango-dark中工作。看起来tango-dark已经在tango-dark.el中将ansi-color-names-vector设置为给定的一组颜色(请参见此处的代码:http://fossies.org/unix/misc/emacs-24.3.tar.gz:a/emacs-24.3/etc/themes/tango-dark-theme.el)。此外,当我查看'M-x describe-theme tango-tark'(请参见我在原帖中发布的图像)时,这些颜色似乎看起来很好,但由于某种原因它们在终端中无法正常工作。 - Amelio Vazquez-Reina
我不理解的另一件事是,为什么你在zenburn中定义的背景颜色对于每个“term-color”都不同(它们不应该设置为继承终端的背景颜色吗?) - Amelio Vazquez-Reina
对于每种颜色,您需要一个较浅的前景版本和一个较暗的背景版本。这就是在term.el中定义面孔的方式(这不是我为zenburn发明的)。实际上,term中没有直接使用这些面孔,它们只用于派生其他面孔。 - Bozhidar Batsov
将此内容粘贴到theme.el文件的正确位置即可解决问题。我需要从.emacs.d/init.el手动删除ansi-color-names-vector和ansi-term-color-vector。在term上运行“customize-group”会重新创建它们,然后再次出现错误,我必须再次删除这些行。我使用的是emacs 25.0.50.2版本。 - Gauthier

3
我建议使用 M-x customize-group RET term RET 作为最简单的入口点来自定义这些颜色。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接