Emacs Adding Preprocessor to Major Mode
-
15-03-2021 - |
Question
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.
Solution
try this: "^\\s-*\\.\\(set\\|macro\\|endmacro\\)\\>"
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow