如何在不影响 Emacs 中其他字体锁定自定义的情况下更改长行的外观?
我有一些很久以前借来的代码,当行太长时设置长行面:(
(add-hook 'font-lock-mode-hook
(function
(lambda ()
(setq font-lock-keywords
(append font-lock-keywords
'( ("^.\\{133,\\}$" (0 'my-long-line-face t))
)
)
)
)
))
顺便说一句,我现在知道了 font-lock-add-keywords;就像我说的,这是一种旧的.)
问题是这改变了整条生产线的面貌。因此,如果我指示 long-line-face 为粗体,则我会丢失该线的所有上下文自定义,并且它会显示在默认外观中,但为粗体。
我怎样才能让它保持上下文颜色但使所有内容都变得粗体?
I have some code that I borrowed from a long while ago that sets a long-line face when the line is too long:
(add-hook 'font-lock-mode-hook
(function
(lambda ()
(setq font-lock-keywords
(append font-lock-keywords
'( ("^.\\{133,\\}$" (0 'my-long-line-face t))
)
)
)
)
))
(I know about font-lock-add-keywords now, BTW; like I said, this is kind of old.)
The problem is that this changes the face of the entire line. So if I indicate that long-line-face is bold, I lose all the contextual customization of the line, and it appears in the default face, but bold.
How would I get it to keep the contextual colouring but make everything bold?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用字体锁定规范中的
t
覆盖字体化。尝试将(0 'my-long-line-face t)
更改为(0 'my-long-line-face prepend)
或(0 ' my-long-line-face 附加)
。You are overriding the fontification with the
t
in your font-lock spec. Try changing the(0 'my-long-line-face t)
to either(0 'my-long-line-face prepend)
or(0 'my-long-line-face append)
.尝试对您的代码进行此修改:
关键是您希望正则表达式有一个子表达式,该子表达式位于不太长的 133 个字符之后,然后应用
my-long-line-face
到下面的子表达式 - 如 1 所示(而不是您的 0)。请参阅基于搜索的字体化的信息页面了解更多详情。Try this modification to your code:
The key being that you want the regexp to have a sub expression that follows the 133 characters that aren't too long, and then apply
my-long-line-face
to that following sub expression - as indicated by the 1 (instead of the 0 that you had). See the info page for Search-based Fontification for more details.