【问题标题】:Modify face under cursor in Emacs, including on ansi-term在 Emacs 中修改光标下的面,包括在 ansi-term 上
【发布时间】:2013-01-08 18:06:06
【问题描述】:

有没有办法轻松修改光标下的font-face

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

                          

以上是

的输出
ipython --color "Linux"

tango-darkEmacs 24.1 中运行ansi-term,即(load-theme 'tango-dark t)

如果我在上图中运行what-cursor-position(此处描述:Get font face under cursor in Emacs),我会得到:

             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 是另一张脸:

                       

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

                                        

【问题讨论】:

    标签: emacs ipython emacs-faces


    【解决方案1】:

    M-x customize-face 将光标悬停在您要修改的特定内容上。还可以使用set-face-foregroundset-face-background,这取决于您想要做什么(有时最好更改背景颜色以使字体更容易在终端中看到)。

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

    【讨论】:

    • 谢谢,但是当我调用M-x customize-face 时,它会提示我Customize face (default 'all faces')。我认为all faces 不是指我上图中光标下的脸。我错了吗?
    • @user273158 应该是font-lock-string-face
    • 谢谢。为什么emacs没有提示我那张脸?那不应该是default问我的那个吗? (即光标下的那个)。还有,你怎么知道font-lock-string-face就是我光标下的那张脸?
    • @user273158 我不使用 IPython,所以我不确定,但我可以帮你查一下 :)
    • @user273158 似乎 ipython 使用 ansi-colors 在 Emacs 之外进行了自己的着色。因此,我认为除了描述的 3 种颜色集之一之外,您不能修改颜色。我查看了ipython.el,发现没有办法做到这一点:\
    【解决方案2】:

    可以更改 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
    

    【讨论】:

    • 谢谢萨博夫。然后我可以假设我在发布的第一张图片中看到的深蓝色文本是term-color-blue?还有,ansi-term是否只支持你列出的9种颜色?
    • term-color-blue,是我的猜测。是的,据我所知是这 9 个。如果使用上述表单不起作用,您可以尝试使用 custom-face,或将它们添加到您的主题定义中。
    • 我列了两次红色,实际上是 8
    【解决方案3】:

    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"])
    

    【讨论】:

    • 谢谢!您知道如何从颜色外观测试/查找十六进制代码吗? (即像一个显示十六进制代码的调色板)
    • 在“html 调色板”上的谷歌搜索应该会给你成千上万的结果。这里有几个例子:colorschemer.com/online.html - colorcombos.com - fillster.com/colorcodes/colorpalette.html
    • 我明白了。谢谢。我不知道这是一个html 规范。你知道有没有办法让ansi-term 支持更多的颜色而不仅仅是 8 种颜色?
    • 据我所知,对应颜色的ansi转义码只有8个(如果你认为正常和明亮的颜色不同,则有16个)。请参阅我的编辑以获取有关 ansi 转义序列的维基百科文章的链接。
    猜你喜欢
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多