在Emacs的光标下获取字体
我一直在开发自己的自定义颜色主题,如果能得到影响光标下方文本的字体列表,这将非常有用。
像Textmate的show current scope命令。
这样可以节省我做Mx自定义面孔的麻烦,并查看可用的选项,猜测哪一个会影响当前的单词。
有任何想法吗?
你可以用这个代码来定义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))))
之后,
Mx what-face
将打印在当前点find的面部。
(感谢ddz指出what-face
是不是内置的。)
具有前缀参数的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]
Mx描述
特雷是什么脸在正确的轨道上。 它让我在邮件列表上发送了一封电子邮件,内容如下:
(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))))
在“what-face”代码中存在一个错误:函数以“pos”作为参数,但是在获取面部时不使用它 – 而是使用“(point)”,即使消息稍后声明 pos在“无%d”情况下。