GNU bug report logs -
#79363
31.0.50; Font locking issue in go-ts-mode when tree-sitter grammar is automatically installed
Previous Next
Full log
Message #11 received at 79363 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> One idea is to turn defvar into defun that memoizes its return value.
Do you mean something like this?
(defvar go-ts-mode--font-lock-settings nil
"Tree-sitter font-lock settings for `go-ts-mode'.")
(defun go-ts-mode--font-lock-settings ()
"Return tree-sitter font-lock settings for `go-ts-mode'.
Tree-sitter font-lock rules are evaluated the first time this function
is called. Subsequent calls return the first evaluated value."
(or go-ts-mode--font-lock-settings
(setq go-ts-mode--font-lock-settings
(treesit-font-lock-rules
...))))
(define-derived-mode go-ts-mode prog-mode "Go"
...
(when (treesit-ensure-installed 'go)
...
(setq-local treesit-font-lock-settings (go-ts-mode--font-lock-settings))
...))
I tried and I can confirm it works fine. I can work on a patch for all
the affected ts modes if you want.
BTW is this a common pattern? If it is, does the Elisp core library
provide something similar? At the end of the day it is a sort of "lazy
defvar", isn't it?
Roi
This bug report was last modified 4 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.