在Emacs中获取光标下的字体

the*_*edz 94 emacs fonts emacs-faces

我一直在开发自己的自定义颜色主题,如果我能得到一个影响光标下文本的字体列表,那将非常有用.

类似Textmate的显示当前范围命令.

这样可以省去Mx自定义面部和查看可用选项的麻烦,猜测哪一个会影响我当前的单词.

有任何想法吗?

jlf*_*jlf 169

what-cursor-position 带有前缀参数显示面下的点,以及其他信息.

键盘快捷键是Cu Cx =

示例输出(face属性显示在最后一段中):

             position: 5356 of 25376 (21%), column: 4
            character: r (displayed as r) (codepoint 114, #o162, #x72)
    preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x72
               syntax: w    which means: word
             category: .:Base, L:Left-to-right (strong), a:ASCII, l:Latin, r:Roman
          buffer code: #x72
            file code: #x72 (encoded by coding system undecided-unix)
              display: by this font (glyph code)
    nil:-apple-Monaco-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1 (#x55)

Character code properties: customize what to show
  name: LATIN SMALL LETTER R
  general-category: Ll (Letter, Lowercase)
  decomposition: (114) ('r')

There are text properties here:
  face                 org-level-2
  fontified            t

[back]
Run Code Online (Sandbox Code Playgroud)

  • 其中调用`what-c​​ursor-position`. (11认同)
  • 我很高兴我找到了这个,有一些未知的命令和击键组合,我得到了`emacs`来显示我喜欢它的方式而不是如何在我下一次重启时取回它 (2认同)
  • 它显示Emacs GUI上的字体名称.在终端上,Emacs不负责设置字体,因此当在终端上运行的Emacs中执行`Cu Cx =`时,如`emacs -nw file.txt`,这些信息不可用. (2认同)

Yoo*_*Yoo 63

Mx describe-face

  • 这还包括很好的链接,可以立即自定义光标下的面 (5认同)
  • 这在大多数情况下运作良好,但有时由于我无法弄清楚的原因,有时它并不表示我正在寻找的面孔.例如在eshell中,当有ansi颜色时,它只是说"默认". (2认同)
  • 这向我显示了我可以输入内容的提示.为了描述光标下的字体,我还需要输入什么? (2认同)

Tre*_*son 41

您可以what-face使用以下代码进行定义:

(defun what-face (pos)
  (interactive "d")
  (let ((face (or (get-char-property (pos) 'read-face-name)
                  (get-char-property (pos) 'face))))
    (if face (message "Face: %s" face) (message "No face at %d" pos))))
Run Code Online (Sandbox Code Playgroud)

之后,

M-x what-face
Run Code Online (Sandbox Code Playgroud)

将打印当前点找到的面部.

(感谢thedz指出它what-face没有内置.)

  • 我更喜欢jlf的答案,因为它使用了内置命令. (10认同)
  • 这会忽略设置为文本属性的面.如果启用`hl-line-mode`,你只能看到`hl-line`作为面,而不是其他面.考虑https://gist.github.com/Wilfred/f7d61b7cdf9fdbb1d11c (3认同)
  • `pos` 不是一个函数;为了使代码片段正常工作,您应该将第 3 行和第 4 行的“(pos)”替换为“pos” (3认同)
  • [Karl Fogel](http://stackoverflow.com/users/247145/karl-fogel)指出了此代码中的错误[在单独的答案中](http://stackoverflow.com/a/20844370/578288):输出消息说它是在`pos`参数处描述人脸的,但是实际上是在`(point)`而不是在`pos`处读取人脸的。 (2认同)

the*_*edz 8

Trey的脸是在正确的轨道上.它让我收到邮件列表上的一封电子邮件:

(defun what-face (pos)
    (interactive "d")
        (let ((face (or (get-char-property (point) 'read-face-name)
            (get-char-property (point) 'face))))
    (if face (message "Face: %s" face) (message "No face at %d" pos))))
Run Code Online (Sandbox Code Playgroud)