代码之家  ›  专栏  ›  技术社区  ›  thedz

在Emacs中获取光标下的字体

  •  90
  • thedz  · 技术社区  · 17 年前

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

    类似于Textmate的show current scope命令。

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

    有什么想法吗?

    5 回复  |  直到 12 年前
        1
  •  182
  •   dbr    13 年前

    what-cursor-position

    C-u C-x=

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

                 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]
    
        2
  •  69
  •   Yoo    17 年前

    M-x描述人脸

        3
  •  44
  •   Community Mohan Dere    9 年前

    你可以定义 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 感谢你指出 什么面孔 不是内置的。)

        4
  •  8
  •   thedz    17 年前

    特雷的脸在正确的轨道上。这让我找到了邮件列表上的一封电子邮件,上面写着:

    (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))))
    
        5
  •  2
  •   Karl Fogel    12 年前

    “what face”代码中有一个错误:该函数将“pos”作为参数,但在获取面时不使用它,而是使用“(point)”,即使稍后会显示消息 “在%d处无面”情况下的pos。

        6
  •  0
  •   ig-perez    5 年前

    @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) 是以整数形式返回点的值的函数。
    • pos 获取由返回的值 (interactive "d")
    • get-char-property 需要一个位置,在本例中由函数给定 (点) .