]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve treesit-major-mode-setup indentation setup (bug#71086)
authorYuan Fu <casouri@gmail.com>
Wed, 22 May 2024 06:15:00 +0000 (23:15 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 May 2024 08:29:59 +0000 (10:29 +0200)
* lisp/treesit.el (treesit-major-mode-setup): Setup indentation when
treesit-indent-function is set.
* doc/lispref/modes.texi (Parser-based Indentation): Fix manual.

(cherry picked from commit e153093f0a14fda47daa12b151b291e61d20b7e3)

doc/lispref/modes.texi
lisp/treesit.el

index ffede9e86f5b8af5c1eb18da05b4df9edd6e6781..361a5e37d02a508ace070658bdc11c0aa02a3701 100644 (file)
@@ -5186,9 +5186,12 @@ below: then the major mode needs only write some indentation rules,
 and the engine takes care of the rest.
 
 To enable the parser-based indentation engine, either set
-@code{treesit-simple-indent-rules} and call
-@code{treesit-major-mode-setup}, or equivalently, set the value of
-@code{indent-line-function} to @code{treesit-indent}.
+@code{treesit-simple-indent-rules} or set
+@code{treesit-indent-function}, then call
+@code{treesit-major-mode-setup}.  (All that
+@code{treesit-major-mode-setup} does is setting the value of
+@code{indent-line-function} to @code{treesit-indent} and
+@code{indent-region-function} to @code{treesit-indent-region}.)
 
 @defvar treesit-indent-function
 This variable stores the actual function called by
index 86ed1bbae33d8884f6d0b3c27645f01d45771fb8..0475227c726822ed1a15fb9e6305ace4bf69234a 100644 (file)
@@ -3008,7 +3008,12 @@ before calling this function."
   (when treesit-simple-indent-rules
     (setq-local treesit-simple-indent-rules
                 (treesit--indent-rules-optimize
-                 treesit-simple-indent-rules))
+                 treesit-simple-indent-rules)))
+  ;; Enable indent if simple indent rules are set, or the major mode
+  ;; sets a custom indent function.
+  (when (or treesit-simple-indent-rules
+            (and (not (eq treesit-indent-function #'treesit-simple-indent))
+                 treesit-indent-function))
     (setq-local indent-line-function #'treesit-indent)
     (setq-local indent-region-function #'treesit-indent-region))
   ;; Navigation.