From: Eli Zaretskii Date: Mon, 30 Jan 2023 12:22:19 +0000 (+0200) Subject: ; Fix build and startup without tree-sitter X-Git-Tag: emacs-29.0.90~558 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dda4baa58b7e6a5c70f4c40c80463221b3c479c1;p=emacs.git ; Fix build and startup without tree-sitter * lisp/treesit.el (treesit--font-lock-level-setter): Don't loop over all the buffers if tree-sitter is not built-in, or else initialization of defcustom will fail. (Bug#61155) * lisp/progmodes/rust-ts-mode.el (treesit-node-parent): * lisp/progmodes/c-ts-common.el (treesit-node-parent): Declare, to * avoid byte-compilation warnings. --- diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 2d4a0d41c2a..c13b01aae5c 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -50,6 +50,7 @@ (declare-function treesit-node-start "treesit.c") (declare-function treesit-node-end "treesit.c") (declare-function treesit-node-type "treesit.c") +(declare-function treesit-node-parent "treesit.c") ;;; Comment indentation and filling diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index 2812e39c101..e317793d211 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el @@ -37,6 +37,7 @@ (declare-function treesit-node-child-by-field-name "treesit.c") (declare-function treesit-node-start "treesit.c") (declare-function treesit-node-type "treesit.c") +(declare-function treesit-node-parent "treesit.c") (defcustom rust-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `rust-ts-mode'." diff --git a/lisp/treesit.el b/lisp/treesit.el index 92833fb007c..98f446a1456 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -87,6 +87,7 @@ (declare-function treesit-search-subtree "treesit.c") (declare-function treesit-search-forward "treesit.c") (declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-subtree-stat "treesit.c") (declare-function treesit-available-p "treesit.c") @@ -557,20 +558,22 @@ omitted, default END to BEG." (defun treesit--font-lock-level-setter (sym val) "Custom setter for `treesit-font-lock-level'." (set-default sym val) - (named-let loop ((res nil) - (buffers (buffer-list))) - (if (null buffers) - (mapc (lambda (b) - (with-current-buffer b - (setq-local treesit-font-lock-level val) - (treesit-font-lock-recompute-features) - (treesit-font-lock-fontify-region (point-min) (point-max)))) - res) - (let ((buffer (car buffers))) - (with-current-buffer buffer - (if (treesit-parser-list) - (loop (append res (list buffer)) (cdr buffers)) - (loop res (cdr buffers)))))))) + (and (treesit-available-p) + (named-let loop ((res nil) + (buffers (buffer-list))) + (if (null buffers) + (mapc (lambda (b) + (with-current-buffer b + (setq-local treesit-font-lock-level val) + (treesit-font-lock-recompute-features) + (treesit-font-lock-fontify-region (point-min) + (point-max)))) + res) + (let ((buffer (car buffers))) + (with-current-buffer buffer + (if (treesit-parser-list) + (loop (append res (list buffer)) (cdr buffers)) + (loop res (cdr buffers))))))))) (defcustom treesit-font-lock-level 3 "Decoration level to be used by tree-sitter fontifications.