summaryrefslogtreecommitdiff
path: root/doc/lispref/modes.texi
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2022-11-19 17:59:14 -0800
committerYuan Fu <casouri@gmail.com>2022-11-19 18:36:08 -0800
commitac9bc819bc438f21bd38a995812d756727ed8e2a (patch)
tree94bc9c6242de9a72b7768512388714f08bc3d783 /doc/lispref/modes.texi
parent7d7e9ef46a1b310fb3f481cdf8023082f5ec1618 (diff)
downloademacs-ac9bc819bc438f21bd38a995812d756727ed8e2a.tar.gz
Fix tree-sitter comment indentation for C-like languages
The goal is to indent like this: /* comment comment --> This line aligns with the beginning of the first line */ --> This line aligns with the opening comment token * lisp/treesit.el (treesit-comment-start) (treesit-comment-end): New variables. (treesit-simple-indent-presets): New preset comment-end, comment-start, comment-start-skip * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles) (c-ts-mode) * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules) (java-ts-mode) * lisp/progmodes/js.el (js--treesit-indent-rules) (js-ts-mode) * lisp/progmodes/ts-mode.el (ts-mode--indent-rules) (ts-mode): Add identical indent rules to each mode, and set identical treesit-comment-start/end's. * doc/lispref/modes.texi (Parser-based Indentation) * doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
Diffstat (limited to 'doc/lispref/modes.texi')
-rw-r--r--doc/lispref/modes.texi22
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 8b20bc0b758..5e5eb458974 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -4964,6 +4964,12 @@ first child where parent is @code{argument_list}, use
(match nil "argument_list" nil nil 0 0)
@end example
+@item comment-end
+This matcher is a function of 3 arguments: @var{node}, @var{parent},
+and @var{bol}, and returns non-@code{nil} if point is before a comment
+ending token. Comment ending tokens are defined by regular expression
+@code{treesit-comment-end}.
+
@item first-sibling
This anchor is a function that is called with 3 arguments: @var{node},
@var{parent}, and @var{bol}, and returns the start of the first child
@@ -4996,8 +5002,22 @@ charater on the previous line.
This anchor is a function is called with 3 arguments: @var{node},
@var{parent}, and @var{bol}, and returns the beginning of the buffer.
This is useful as the beginning of the buffer is always at column 0.
-@end ftable
+@item comment-start
+This anchor is a function is called with 3 arguments: @var{node},
+@var{parent}, and @var{bol}, and returns the position right after the
+opening comment token. Opening comment tokens are defined by regular
+expression @code{treesit-comment-start}. This function assumes
+@var{parent} is the comment node.
+
+@item coment-start-skip
+This anchor is a function is called with 3 arguments: @var{node},
+@var{parent}, and @var{bol}, and returns the position after the
+opening comment token, after skipping forward any whitespace
+characters. Opening comment tokens are defined by regular expression
+@code{treesit-comment-start}. This function assumes @var{parent} is
+the comment node.
+@end ftable
@end defvar
@heading Indentation utilities