diff options
author | Yuan Fu <casouri@gmail.com> | 2023-01-15 00:15:25 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-01-15 01:11:37 -0800 |
commit | c78e19d99c01660284c6c4d58a2e98e1ba93fb6d (patch) | |
tree | 260b3e87d2afed08a9582fb585bbcf1ac9a8b9ba /lisp | |
parent | d13a329acff37b37091e137e3b04669ab7aab9ae (diff) | |
download | emacs-c78e19d99c01660284c6c4d58a2e98e1ba93fb6d.tar.gz emacs-c78e19d99c01660284c6c4d58a2e98e1ba93fb6d.tar.bz2 emacs-c78e19d99c01660284c6c4d58a2e98e1ba93fb6d.zip |
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.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/treesit.el | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 5b306354465..ffc78b93032 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")) |