emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Average-user-facing interface for tree-sitter


From: Stefan Monnier
Subject: Re: Average-user-facing interface for tree-sitter
Date: Mon, 24 Oct 2022 19:55:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> There will not be treesit-mode and global-treesit-mode, only the central
> variable treesit-settings. Enabling tree-sitter only requires adding (mode
> t) to treesit-setttings, and M-x revert-buffer, or reopen the file, or rerun
> the major mode.

Yeah, I guess it's good enough for now.  We can still keep all the
treesit-<foo> variables and then a `treesit-enable` function which the
major mode has to call, right?  Oh and probably something like
`treesit-enable-p` function (or maybe `treesit-enable` can return
whether it enabled the treesit support).

So the major mode code could look like in the patch below?


        Stefan


diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 52160fbb5ee..4cea9f4ec1a 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3617,14 +3617,8 @@ js-mode
               (list js--font-lock-keywords nil nil nil nil
                     '(font-lock-syntactic-face-function
                       . js-font-lock-syntactic-face-function)))
-  (setq-local syntax-propertize-function #'js-syntax-propertize)
-  (add-hook 'syntax-propertize-extend-region-functions
-            #'syntax-propertize-multiline 'append 'local)
-  (add-hook 'syntax-propertize-extend-region-functions
-            #'js--syntax-propertize-extend-region 'append 'local)
   (setq-local prettify-symbols-alist js--prettify-symbols-alist)
 
-  (setq-local parse-sexp-ignore-comments t)
   (setq-local which-func-imenu-joiner-function #'js--which-func-joiner)
 
   ;; Comments
@@ -3634,25 +3628,11 @@ js-mode
   (setq-local fill-paragraph-function #'js-fill-paragraph)
   (setq-local normal-auto-fill-function #'js-do-auto-fill)
 
-  ;; Parse cache
-  (add-hook 'before-change-functions #'js--flush-caches t t)
-
-  ;; Frameworks
-  (js--update-quick-match-re)
-
-  ;; Syntax extensions
-  (unless (js-jsx--detect-and-enable)
-    (add-hook 'after-change-functions #'js-jsx--detect-after-change nil t))
-  (js-use-syntactic-mode-name)
-
   ;; Imenu
   (setq imenu-case-fold-search nil)
   (setq imenu-create-index-function #'js--imenu-create-index)
 
   ;; for filling, pretend we're cc-mode
-  (c-foreign-init-lit-pos-cache)
-  (add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t)
-  (setq-local comment-line-break-function #'c-indent-new-comment-line)
   (setq-local comment-multi-line t)
   (setq-local electric-indent-chars
              (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds 
"[]*".
@@ -3698,7 +3678,29 @@ js-mode
                       "function_declaration"
                       "lexical_declaration")))
   (setq-local treesit-font-lock-settings js--treesit-font-lock-settings)
-  (setq-local treesit-font-lock-feature-list '((minimal) (moderate) (full))))
+  (setq-local treesit-font-lock-feature-list '((minimal) (moderate) (full)))
+
+  (unless (treesit-enable)
+    ;; Parse cache
+    (setq-local syntax-propertize-function #'js-syntax-propertize)
+    (add-hook 'syntax-propertize-extend-region-functions
+              #'syntax-propertize-multiline 'append 'local)
+    (add-hook 'syntax-propertize-extend-region-functions
+              #'js--syntax-propertize-extend-region 'append 'local)
+    (setq-local parse-sexp-ignore-comments t)
+    (add-hook 'before-change-functions #'js--flush-caches t t)
+
+    ;; Frameworks
+    (js--update-quick-match-re)
+
+    ;; Syntax extensions
+    (unless (js-jsx--detect-and-enable)
+      (add-hook 'after-change-functions #'js-jsx--detect-after-change nil t))
+    (js-use-syntactic-mode-name)
+
+    (c-foreign-init-lit-pos-cache)
+    (add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil 
t)
+    (setq-local comment-line-break-function #'c-indent-new-comment-line)))
 
 (defvar js-json--treesit-font-lock-settings
   (treesit-font-lock-rules




reply via email to

[Prev in Thread] Current Thread [Next in Thread]