ATS(inline, const, unused) /* Variadic Macro */
OTS(inline, const, unused)
I'm trying to match inline
, const
, unused
keywords only in ATS
macro. i tried ATS([^,]*)
but it only matches inline
keyword.
Edit: I need to change the color of all ATS
parameters. this only works on the first parameter.
(font-lock-add-keywords nil
'(("ATS(\\([^,]*\\)" 1 font-lock-builtin-face)))
You can use an anchored font-lock rule. It's like a search within a search. The code below searches for AST(
. Once it's found, it find the end of the argument list and performs a search for all words within it.
(defun foo ()
(interactive)
(setq font-lock-multiline t)
(font-lock-add-keywords
nil
'(("\\_<ATS("
("\\_<\\sw+\\_>"
;; Pre-match form -- limit the sub-search to the end of the argument list.
(save-excursion
(goto-char (match-end 0))
(backward-char)
(ignore-errors
(forward-sexp))
(point))
;; Post-match form
(goto-char (match-end 0))
(0 font-lock-builtin-face))))))
This will match all words inside the parentheses, even if they are spread out across multiple lines.
The pre-match form has two purposes: It can position the point to a suitable locations and it controls the extend of the sub-search (where nil
means the end of the line). The post-match form can, for example, be used to return the point to a good position for other keyword rules.
This can, of course, be extended to only highlight a specific set of words, but I leave that as an exercise.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments