[英]Get font face under cursor in Emacs
I've been developing my own custom color theme, and it'd be really useful if I could get a list of font-faces affecting the text under the cursor.我一直在开发我自己的自定义颜色主题,如果我能得到影响光标下文本的字体列表,那将非常有用。
Something like Textmate's show current scope command.类似于 Textmate 的 show current scope 命令。
That would save me the trouble of doing Mx customize-face and looking through available options, guessing at which one affects the current word I'm on.这将省去我进行 Mx 自定义面部和查看可用选项的麻烦,猜测哪个会影响我当前使用的单词。
Any ideas?有任何想法吗?
what-cursor-position
with a prefix argument shows the face under point, among other information.带有前缀参数的what-cursor-position
显示点下的面,以及其他信息。
Keyboard shortcut is Cu Cx =键盘快捷键是Cu Cx =
Example output (the face property is shown in the last paragraph):示例输出(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 描述面
You can define what-face
with this code:您可以使用以下代码定义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))))
After that,之后,
M-x what-face
will print the face found at the current point.将打印在当前点找到的人脸。
(Thanks to thedz for pointing out that what-face
wasn't built in.) (感谢dz指出没有内置what-face
。)
Trey's what face is on the right track. Trey 的脸在正确的轨道上。 It led me to an email on a mailing list that had this:它让我看到了邮件列表中的一封电子邮件,其中包含以下内容:
(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 没有脸”的情况下。
I tried @tray function but it didn't work, @thedz definition does work:我试过@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))))
After some research I found why:经过一番研究,我发现了原因:
(point)
is a function that returns the value of point as an integer. (point)
是一个函数,它以整数形式返回 point 的值。pos
gets the value returned by (interactive "d")
which will be the position of point, as an integer. pos
获取(interactive "d")
返回的值,它将是点的位置,作为整数。get-char-property
expects a position, in this case given by the function (point)
. get-char-property
需要一个位置,在本例中由函数(point)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.