GNU bug report logs -
#65570
[Tree Sitter] [Feature Request] Allow Adding User-Defined Queries
Previous Next
To reply to this bug, email your comments to 65570 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#65570
; Package
emacs
.
(Sun, 27 Aug 2023 18:38:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jacob Faibussowitsch <jacob.fai <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 27 Aug 2023 18:38:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello,
Is it possible for users to define their own custom font-lock queries? If so, how?
Per the documentation, font-locking is controlled by the contents of `treesit-font-lock-settings`. Perusing `lisp/progmodes/c-ts-mode.el` one finds `c-ts-mode--font-lock-settings`, which is used to populate `treesit-font-lock-settings`, but there seems to be no way to override or append to these settings.
For example, suppose that I — just for laughs — wanted to highlight the namespace name in the same face as integer-literals for:
```
// namespace.cpp
int x = 2;
namespace foo
{
}
```
I might do:
```
;; init.el
;; ensure the modes are overridden
(add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode))
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
(add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))
;; to make it ~pop~
(set-face-attribute 'font-lock-number-face nil :foreground "red")
(use-package c-ts-mode
:config
(setq my-custom-font-lock-rules
(treesit-font-lock-rules
:language 'cpp
:override t
:feature 'type
`((namespace_definition
name: (namespace_identifier) @font-lock-number-face))))
(setq-local treesit-font-lock-settings my-custom-font-lock-rules)
(treesit-major-mode-setup))
```
But that does not seem to work.
[PastedGraphic-1.png (image/png, inline)]
[Message part 3 (text/plain, inline)]
You can see that 2 is obviously red, but foo is not (in fact, `M-x describe-face` reports it as “default” face). I want both foo and 2 to have the same font face.
You can reproduce this with (assuming you paste the above 2 snippets into some directory:
```
$ emacs --init-directory=`pwd` ./namespace.cpp
```
Best regards,
Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)
This bug report was last modified 1 year and 122 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.