* Help with Fontification
@ 2021-11-03 4:00 Reza Nikoopour
2021-11-03 11:56 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Reza Nikoopour @ 2021-11-03 4:00 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1076 bytes --]
Hello All,
I'm working on refactoring terraform mode and I've stumbled across
a fontification issue I cannot figure out how to solve.
[image: image.png]
A resource can be broken down into the three parts:
The keyword "resource", the resource type (green in the image), and the
resource
name (pink in the image).
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)))
(define-derived-mode terraform-mode prog-mode "Terraform"
;; other code
(setq font-lock-defaults '((terraform-font-lock-keywords))))
However, this is causing the issue above where the search based
highlighting is
overriding the comment highlighting.
Is there a way to only have search based fontification only override
strings but
keep comments unaltered?
Cheers,
Reza
[-- Attachment #1.2: Type: text/html, Size: 1383 bytes --]
[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 7516 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Help with Fontification
2021-11-03 4:00 Help with Fontification Reza Nikoopour
@ 2021-11-03 11:56 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2021-11-03 11:56 UTC (permalink / raw)
To: Reza Nikoopour; +Cc: emacs-devel
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-03 11:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-03 4:00 Help with Fontification Reza Nikoopour
2021-11-03 11:56 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.