regex - How to match everything except a particular pattern after/before a specific string constant -
ats(inline, const, unused) /* variadic macro */ ots(inline, const, unused)
i'm trying match inline
, const
, unused
keywords only in ats
macro. tried ats([^,]*)
matches inline
keyword.
edit: need change color of ats
parameters. works on first parameter.
(font-lock-add-keywords nil '(("ats(\\([^,]*\\)" 1 font-lock-builtin-face)))
you can use anchored font-lock rule. it's search within search. code below searches ast(
. once it's found, find end of argument list , performs search words within it.
(defun foo () (interactive) (setq font-lock-multiline t) (font-lock-add-keywords nil '(("\\_<ats(" ("\\_<\\sw+\\_>" ;; pre-match form -- limit sub-search end of 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 match words inside parentheses, if spread out across multiple lines.
the pre-match form has 2 purposes: can position point suitable locations , controls extend of sub-search (where nil
means end of line). post-match form can, example, used return point position other keyword rules.
this can, of course, extended highlight specific set of words, leave exercise.
Comments
Post a Comment