[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with Fontification
From: |
Stefan Monnier |
Subject: |
Re: Help with Fontification |
Date: |
Wed, 03 Nov 2021 07:56:31 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> The resource name and type are string literals so I
> used the override flag for the regex when setting font-lock-defaults:
> (defvar terraform-font-lock-keywords
> ;; other code
> (,terraform--block-builtins-with-type-and-name--type-highlight-regexp
> 2 'terraform--resource-type t)
> (,terraform--block-builtins-with-type-and-name--name-highlight-regexp
> 3 'terraform--resource-name t)))
[...]
> Is there a way to only have search based fontification only override
> strings but keep comments unaltered?
Yes: the "face" part of the specs above are actually arbitrary ELisp
expressions, so you can do things like:
(defvar terraform-font-lock-keywords
;; other code
(,terraform--block-builtins-with-type-and-name--type-highlight-regexp
2 (unless (nth 4 (syntax-ppss)) 'terraform--resource-type) t)
(,terraform--block-builtins-with-type-and-name--name-highlight-regexp
3 (unless (nth 4 (syntax-ppss)) 'terraform--resource-name) t)))
Another option is to replace the regexps by functions (which internally
can use the same regexps, of course) and have those functions check (nth
4 (syntax-ppss)) to see if the match is inside a comment (and skip to
the next match if so),
Stefan