在Emacs中修改光标下的面部,包括在ansi-term中。

3

有没有一种方便地修改光标下的font-face的方法?

例如,下面蓝色的文本很难阅读:

                           enter image description here

以上是输出结果。

ipython --color "Linux"

Emacs 24.1中使用tango-dark主题的ansi-term上运行,即(load-theme 'tango-dark t)

如果我在上面的图像(在此处描述:在Emacs中获取光标下的字体)上运行what-cursor-position,我会得到:

             position: 30385 of 30477 (100%), column: 22
            character: / (displayed as /) (codepoint 47, #o57, #x2f)
    preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x2F
               syntax: _    which means: symbol
             category: .:Base, a:ASCII, l:Latin, r:Roman
          buffer code: #x2F
            file code: #x2F (encoded by coding system nil)
              display: by this font (glyph code)
    xft:-unknown-DejaVu LGC Sans Mono-bold-normal-normal-*-11-*-*-*-m-0-iso10646-1 (#x12)

Character code properties: customize what to show
  name: SOLIDUS
  old-name: SLASH
  general-category: Po (Punctuation, Other)
  decomposition: (47) ('/')

There are text properties here:
  face                 (:weight bold :foreground "blue2" :background unspecified)

我该如何修改这个字体?

如果你想知道,IPython 只支持三种颜色集:

  • Nocolor
  • Linux(我在上面使用的那个)
  • LightBG(适用于浅色背景)

更新:

我认为 font-lock-string-face 是一个不同的面孔:

                        enter image description here

事实上,我认为这不是 IPython 用来表示字符串的面孔,而是 python-mode 在带有常规 python 代码的缓冲区中表示字符串的面孔(在 tango-dark 中)--见下图--。

                                          enter image description here

3个回答

5

要修改特定的内容,您可以将光标放在该内容上,然后使用M-x customize-face。如果您想执行其他操作,则可以使用set-face-foregroundset-face-background命令(有时更改背景颜色可以使字体在终端中更易于查看)。

我在下面的评论中提到了IPython,并检查了它,但是ipython.el本身没有突出显示任何内容。所有着色都是通过使用终端ANSI颜色完成的。在某些终端中,可以通过.bashrc.zshrc或您使用的任何其他shell并从M-x term运行来更改颜色。通过Emacs本身,我无法找到任何更改它的方法,因为IPython只有3种默认方案,而且据我所知没有指定任何特定方案的方法。


@user273158 你得相信我,我不确定为什么你的Emacs无法正确检测它,我的在终端和X中都可以工作。 - Jesus Ramos
谢谢耶稣。我已经更新了原帖,提供了更多关于此事的信息(请参见“更新”部分)。 - Amelio Vazquez-Reina
1
@user273158 我没有使用IPython,所以我不确定,但我可以为您检查一下 :) - Jesus Ramos
1
@user273158 看起来 ipython 在 Emacs 外部使用 ansi-colors 进行自己的着色。因此,我认为您不能修改颜色,除非是描述的三个颜色集之一。我查看了 ipython.el,但没有找到任何方法来实现这一点 :\ - Jesus Ramos
@Dualinity 他可以尝试使用 TERM=xterm-mono 来禁用 ANSI 颜色输出。 - Jesus Ramos
显示剩余4条评论

3
可以更改ansi颜色的显示方式:
(defface term-color-red
    '((t (:foreground "#ff0000" :background "#ff0000")))
  "Unhelpful docstring.")

以下是全部内容:

term-color-red
term-color-green
term-color-black
term-color-yellow
term-color-blue
term-color-magenta
term-color-cyan
term-color-white

谢谢sabof。那么我可以假设我在我发布的第一张图片中看到的深蓝色文本是“term-color-blue”吗?此外,“ansi-term”只支持您列出的9种颜色吗? - Amelio Vazquez-Reina
“term-color-blue”应该是我猜的。是的,据我所知就是这9个颜色。如果使用上述形式无法工作,您可以尝试使用“customize-face”,或将它们添加到您的主题定义中。 - sabof
我把红色列了两次,实际上是8。 - sabof

1

sabof一样,我认为你看到的颜色是由ansi-term设置的,而不是由Emacs的颜色主题设置的。

配置这些颜色的一种方法是设置ansi-term-color-vector变量。查看term.el中的代码有助于理解此变量的含义:它包含8个ansi color escape codes的颜色规范。

(defvar ansi-term-color-vector
  [unspecified "black" "red3" "green3" "yellow3" "blue2"
   "magenta3" "cyan3" "white"])

这是我的设置(也许适合你,因为我也使用了一个黑色的Tango主题):

;; ANSI Term colors
(setq ansi-term-color-vector
      [unspecified "#000000" "#b21818" "#18b218" "#BE5F00"
                   "#6D85BA" "#b218b2" "#18b2b2" "#b2b2b2"])

谢谢!您知道如何测试/查找十六进制颜色代码吗?(例如,像一个颜色调色板,显示给我十六进制代码) - Amelio Vazquez-Reina
在谷歌上搜索“HTML颜色调色板”应该会给你成千上万的结果。以下是一些例子:http://www.colorschemer.com/online.html - http://www.colorcombos.com/ - http://fillster.com/colorcodes/colorpalette.html - François Févotte
我明白了,谢谢。我不知道它是一个 html 规范。你知道有没有办法让 ansi-term 支持超过8种颜色吗? - Amelio Vazquez-Reina
据我所知,只有8个ansi转义码对应颜色(如果您认为正常和亮色不同,则为16个)。请参见我的编辑,链接到维基百科上的ansi转义序列文章。 - François Févotte

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