gpt4 book ai didi

行首每组空格的正则表达式

转载 作者:行者123 更新时间:2023-12-03 18:50:32 24 4
gpt4 key购买 nike

我正在尝试修复 highlight indentation 的正则表达式emacs 的模块。它目前的工作方式是每隔 %s 个空格突出显示一次:

"\\( \\) \\{%s\\}"

下面是一些 Verilog 代码行为的示例结果:

enter image description here

当前的正则表达式适用于每行开头的缩进。但是,存在一个不受欢迎的伪影,即不在行首的空格序列也被正则表达式匹配。 我想修改正则表达式以匹配上述行为,但仅限于行首。这就是我想要的 (我不得不手动绘制它):

enter image description here

这是我尝试过的。从结果中可以看出行为不对。
"^\\(\\( \\) \\{%s\\}\\) \\{1,\\}"

结果:

enter image description here

也试过
"^\\(\\( \\) \\{%s\\}\\)\\{1,\\}"

结果:

enter image description here

这是相关代码,但我很抱歉这不是一个工作示例。请使用上面的链接作为一个工作示例。
(set (make-local-variable 'highlight-indentation-current-regex)
(format "\\( \\) \\{%s\\}" (- highlight-indentation-offset 1)))
(font-lock-add-keywords nil `((,highlight-indentation-current-regex
(1 'highlight-indentation-face))))

最佳答案

假设您当前的字体锁定规则如下所示:

(,highlight-indentation-current-regex (1 'highlight-indentation-face))

你可以使用
(,highlight-indentation-current-regex (1 (if (save-excursion (skip-chars-backward " \t") (bolp)) 'highlight-indentation-face)))

关于行首每组空格的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com