Emacs 将预处理器添加到主模式
我正在尝试修改 fortran 主要模式以与同事编写的预处理器一起使用。预处理器指令均以“.”为前缀。
例如:
.set
.macro
类似于C的#define的函数
到目前为止,我有:
(font-lock-add-keywords 'fortran-mode
'(("\\<\\(set\\|macro\\|endmacro\\)\\>" . font-lock-preprocessor-face)))
不幸的是,这并没有突出显示“。”这是可取的。此外,该模式仅应在出现在行开头时匹配。 我已经尝试过:
(font-lock-add-keywords 'fortran-mode
'(("\\<\\(^\.set\\|^\.macro\\|^\.endmacro\\)\\>" . font-lock-preprocessor-face)))
但这没有用。
任何有关如何进行正则表达式匹配的帮助将不胜感激。
I am trying to modify the fortran major mode to work with a preprocessor a colleague wrote. The preprocessor directives are all prefixed by a "."
for example:
.set
.macro
function similar to C's #define
This far, I have:
(font-lock-add-keywords 'fortran-mode
'(("\\<\\(set\\|macro\\|endmacro\\)\\>" . font-lock-preprocessor-face)))
Unfortunately, This does not highlight the "." which is desirable. Also, the pattern should only match if it appears at the start of the line.
I've tried:
(font-lock-add-keywords 'fortran-mode
'(("\\<\\(^\.set\\|^\.macro\\|^\.endmacro\\)\\>" . font-lock-preprocessor-face)))
but that didn't work.
Any help on how to make this regex match would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
“^\\s-*\\.\\(set\\|macro\\|endmacro\\)\\>”
try this:
"^\\s-*\\.\\(set\\|macro\\|endmacro\\)\\>"
您应该使用
\\.
而不是^\.
。双斜杠转义了反斜杠的特殊含义,创建了字符串\.
,而后者中的^
没有特殊含义。You should use
\\.
rather that^\.
. The double slashed escapes the special meaning of backslashes, creating the string\.
, whereas the^
in the latter has no special meaning.