在Emacs中获取光标下的字体

时间:2009-08-07 00:56:26

标签: emacs fonts emacs-faces

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

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

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

有什么想法吗?

6 个答案:

答案 0 :(得分:160)

带有前缀参数的

what-cursor-position可以显示面部,以及其他信息。

键盘快捷键为 C-u C-x =

示例输出(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]

答案 1 :(得分:62)

M-x describe-face

答案 2 :(得分: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))))

之后,

M-x what-face

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

(感谢thedz指出what-face未内置。)

答案 3 :(得分: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))))

答案 4 :(得分:2)

“what-face”代码中存在一个错误:该函数将“pos”作为参数但在获取面部时不使用它 - 而是使用“(point)”,即使消息后来声明 pos在“没有面对%d”的情况下。

答案 5 :(得分:0)

我尝试了 @tray 函数,但没有用,@thedz 定义确实有效:

(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))))

经过一番研究,我找到了原因:

  • (point) 是一个以整数形式返回 point 值的函数。
  • pos 获取 (interactive "d") 返回的值,即点的位置,作为整数。
  • get-char-property 需要一个位置,在本例中由函数 (point) 给出。
相关问题