aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/treesit.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/treesit.el')
-rw-r--r--lisp/treesit.el50
1 files changed, 29 insertions, 21 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 7d6113e3249..14c05b0dd16 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -753,10 +753,10 @@ that encompasses the region between START and END."
753 (numberp (cdr range-offset))) 753 (numberp (cdr range-offset)))
754 (signal 'treesit-error (list "Value of :offset option should be a pair of numbers" range-offset))) 754 (signal 'treesit-error (list "Value of :offset option should be a pair of numbers" range-offset)))
755 (setq offset range-offset))) 755 (setq offset range-offset)))
756 (:range-fn (let ((range-fn (pop query-specs))) 756 (:range-fn (let ((fn (pop query-specs)))
757 (unless (functionp range-fn) 757 (unless (functionp fn)
758 (signal 'treesit-error (list "Value of :range-fn option should be a function" range-fn))) 758 (signal 'treesit-error (list "Value of :range-fn option should be a function" fn)))
759 (setq range-fn range-fn))) 759 (setq range-fn fn)))
760 (query (if (functionp query) 760 (query (if (functionp query)
761 (push (list query nil nil) result) 761 (push (list query nil nil) result)
762 (when (null embed) 762 (when (null embed)
@@ -1423,22 +1423,31 @@ LANGUAGE is the language of QUERY.")
1423 (setf (nth 1 new-setting) t) 1423 (setf (nth 1 new-setting) t)
1424 new-setting)) 1424 new-setting))
1425 1425
1426(defun treesit--font-lock-level-setter (sym val) 1426(defun treesit--font-lock-level-setter (sym val &optional buffer-local)
1427 "Custom setter for `treesit-font-lock-level'. 1427 "Custom setter for `treesit-font-lock-level'.
1428Set the default value of SYM to VAL, recompute fontification 1428Set the default value of SYM to VAL, recompute fontification
1429features and refontify for every buffer where tree-sitter-based 1429features and refontify for every buffer where tree-sitter-based
1430fontification is enabled." 1430fontification is enabled.
1431 (set-default sym val) 1431
1432 (when (treesit-available-p) 1432If optional BUFFER-LOCAL is non-nil, only affect the current buffer.
1433 (dolist (buffer (buffer-list)) 1433Set SYM buffer locally and refontify."
1434 (with-current-buffer buffer 1434 ;; FIXME: This doesn't re-run major mode hooks, meaning any
1435 ;; FIXME: This doesn't re-run major mode hooks, meaning any 1435 ;; customization done in major mode hooks (e.g., with
1436 ;; customization done in major mode hooks (e.g., with 1436 ;; `treesit-font-lock-recompute-features') may be overridden.
1437 ;; `treesit-font-lock-recompute-features') is lost. 1437 (cond (buffer-local
1438 (when treesit-font-lock-settings 1438 (set-local sym val)
1439 (treesit-font-lock-recompute-features) 1439 (when (and (treesit-available-p)
1440 (treesit-font-lock-fontify-region 1440 treesit-font-lock-settings)
1441 (point-min) (point-max))))))) 1441 (treesit-font-lock-recompute-features)
1442 (font-lock-flush)))
1443 (t
1444 (set-default sym val)
1445 (when (treesit-available-p)
1446 (dolist (buffer (buffer-list))
1447 (with-current-buffer buffer
1448 (when treesit-font-lock-settings
1449 (treesit-font-lock-recompute-features)
1450 (font-lock-flush))))))))
1442 1451
1443(defcustom treesit-font-lock-level 3 1452(defcustom treesit-font-lock-level 3
1444 "Decoration level to be used by tree-sitter fontifications. 1453 "Decoration level to be used by tree-sitter fontifications.
@@ -2050,9 +2059,8 @@ If LOUDLY is non-nil, display some debugging information."
2050 (pcase-let ((`(,max-depth ,max-width) 2059 (pcase-let ((`(,max-depth ,max-width)
2051 (treesit-subtree-stat 2060 (treesit-subtree-stat
2052 (treesit-buffer-root-node language)))) 2061 (treesit-buffer-root-node language))))
2053 (if (or (> max-depth 100) (> max-width 4000)) 2062 (setq treesit--font-lock-fast-mode
2054 (setq treesit--font-lock-fast-mode t) 2063 (or (> max-depth 100) (> max-width 4000)))))
2055 (setq treesit--font-lock-fast-mode nil))))
2056 2064
2057 ;; Only activate if ENABLE flag is t. 2065 ;; Only activate if ENABLE flag is t.
2058 (when-let* 2066 (when-let*
@@ -5849,7 +5857,7 @@ language."
5849 "Pattern matching" 5857 "Pattern matching"
5850 (treesit-query-capture 5858 (treesit-query-capture
5851 :no-eval (treesit-query-capture node '((identifier) @id "return" @ret)) 5859 :no-eval (treesit-query-capture node '((identifier) @id "return" @ret))
5852 :eg-result-string "((id . #<treesit-node (identifier) in 195-196>) (ret . #<treesit-node "return" in 338-344>))") 5860 :eg-result-string "((id . #<treesit-node (identifier) in 195-196>) (ret . #<treesit-node \"return\" in 338-344>))")
5853 (treesit-query-compile 5861 (treesit-query-compile
5854 :no-eval (treesit-query-compile 'c '((identifier) @id "return" @ret)) 5862 :no-eval (treesit-query-compile 'c '((identifier) @id "return" @ret))
5855 :eg-result-string "#<treesit-compiled-query>") 5863 :eg-result-string "#<treesit-compiled-query>")