[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 c78e19d99c 4/8: Allow offset in tree-sitter indent rules to be
From: |
Yuan Fu |
Subject: |
emacs-29 c78e19d99c 4/8: Allow offset in tree-sitter indent rules to be functions |
Date: |
Sun, 15 Jan 2023 04:17:44 -0500 (EST) |
branch: emacs-29
commit c78e19d99c01660284c6c4d58a2e98e1ba93fb6d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Allow offset in tree-sitter indent rules to be functions
This is needed for fixing C indentation. See next comment.
* doc/lispref/modes.texi (Parser-based Indentation): Update manual.
* lisp/treesit.el (treesit-simple-indent): Try evaluating OFFSET as a
function if it's not integer nor variable.
---
doc/lispref/modes.texi | 14 ++++++++------
lisp/treesit.el | 13 +++++++++----
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index ff372edb3f..fe5eb8a1b8 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -4926,8 +4926,7 @@ the current line to @var{matcher}; if it returns
non-@code{nil}, this
rule is applicable. Then Emacs passes the node to @var{anchor}, which
returns a buffer position. Emacs takes the column number of that
position, adds @var{offset} to it, and the result is the indentation
-column for the current line. @var{offset} can be an integer or a
-variable whose value is an integer.
+column for the current line.
The @var{matcher} and @var{anchor} are functions, and Emacs provides
convenient defaults for them.
@@ -4943,10 +4942,13 @@ inside a multi-line string, no node can start at that
position, so
@var{node} is @code{nil}. In that case, @var{parent} would be the
smallest node that spans that position.
-Emacs finds @var{bol}, @var{node} and @var{parent} and
-passes them to each @var{matcher} and @var{anchor}. @var{matcher}
-should return non-@code{nil} if the rule is applicable, and
-@var{anchor} should return a buffer position.
+@var{matcher} should return non-@code{nil} if the rule is applicable,
+and @var{anchor} should return a buffer position.
+
+@var{offset} can be an integer, a variable whose value is an integer,
+or a function that returns an integer. If it is a function, it is
+passed @var{node}, @var{parent}, and @var{bol}, like matchers and
+anchors.
@end defvar
@defvar treesit-simple-indent-presets
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 5b30635446..ffc78b9303 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1511,10 +1511,15 @@ OFFSET."
return
(let ((anchor-pos
(treesit--simple-indent-eval
- (list anchor node parent bol))))
- (cons anchor-pos (if (symbolp offset)
- (symbol-value offset)
- offset)))
+ (list anchor node parent bol)))
+ (offset-val
+ (cond ((numberp offset) offset)
+ ((and (symbolp offset)
+ (boundp offset))
+ (symbol-value offset))
+ (t (treesit--simple-indent-eval
+ (list offset node parent bol))))))
+ (cons anchor-pos offset-val))
finally return
(progn (when treesit--indent-verbose
(message "No matched rule"))
- emacs-29 updated (b365a7cc32 -> 3fa10f6e54), Yuan Fu, 2023/01/15
- emacs-29 25a5575f16 7/8: Fix c-ts-mode block comment indentation (bug#60270), Yuan Fu, 2023/01/15
- emacs-29 3fa10f6e54 8/8: ; Add more c-ts-mode indent and filling tests, Yuan Fu, 2023/01/15
- emacs-29 252b2c01af 6/8: Fix c-ts-mode label indent, Yuan Fu, 2023/01/15
- emacs-29 f02998939c 1/8: ; Fix c-ts-mode filling, Yuan Fu, 2023/01/15
- emacs-29 d13a329acf 3/8: ; Minor change in c-ts-mode--indent-styles, Yuan Fu, 2023/01/15
- emacs-29 c78e19d99c 4/8: Allow offset in tree-sitter indent rules to be functions,
Yuan Fu <=
- emacs-29 189d976dba 5/8: Fix statement indent for c-ts-mode (bug#59686) (bug#60280), Yuan Fu, 2023/01/15
- emacs-29 d428d51066 2/8: Support filling line comments in c-ts-mode, Yuan Fu, 2023/01/15