如何在不影响 Emacs 中其他字体锁定自定义的情况下更改长行的外观?

发布于 2024-12-18 15:04:44 字数 592 浏览 3 评论 0原文

我有一些很久以前借来的代码,当行太长时设置长行面:(

 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤檠 2024-12-25 15:04:44

您正在使用字体锁定规范中的 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).

淡墨 2024-12-25 15:04:44

尝试对您的代码进行此修改:

(add-hook 'font-lock-mode-hook
       (function
    (lambda ()
      (setq font-lock-keywords
        (append font-lock-keywords
            '( ("^.\\{133\\}\\(.*\\)$" (1 'my-long-line-face t))
              )
            )
        )
      )
    ))

关键是您希望正则表达式有一个子表达式,该子表达式位于不太长的 133 个字符之后,然后应用 my-long-line-face 到下面的子表达式 - 如 1 所示(而不是您的 0)。请参阅基于搜索的字体化的信息页面了解更多详情。

Try this modification to your code:

(add-hook 'font-lock-mode-hook
       (function
    (lambda ()
      (setq font-lock-keywords
        (append font-lock-keywords
            '( ("^.\\{133\\}\\(.*\\)$" (1 'my-long-line-face t))
              )
            )
        )
      )
    ))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文