summaryrefslogtreecommitdiff
path: root/doc/lispref/modes.texi
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-02-26 18:05:13 -0800
committerYuan Fu <casouri@gmail.com>2023-02-26 21:38:22 -0800
commit0f15286c5396e3415e0f40c21b6f6d7554f46a5e (patch)
tree99bf3e05b6bf7762ffb0a681a95d9030e75de4de /doc/lispref/modes.texi
parent267fc6d00c4db6f20da3c2d63e48a71ab70505d3 (diff)
downloademacs-0f15286c5396e3415e0f40c21b6f6d7554f46a5e.tar.gz
emacs-0f15286c5396e3415e0f40c21b6f6d7554f46a5e.tar.bz2
emacs-0f15286c5396e3415e0f40c21b6f6d7554f46a5e.zip
New tree-sitter indent anchor standalone-parent used by c-ts-mode
When writing c-ts-mode Theo used parent-bol which works well except one case: 1 for (int i=0; 2 i < 5; 3 i++) { 4 func(i); 5 } In this case, when indenting "func(i)", parent-bol returns the start of "i++" on line 3, instead of the "correct" anchor, the start of "for" on line 1. parent-bol would have worked if the "for (...) {" part is in one line. To support this case I tried numerous things and added a bunch of stuff, culminating in c-ts-common-statement-offset. It's complicated, requires extra setup, and slow. Not anymore! I think the new anchor standalone-parent really captures the logic behind how people expect indentation to work. It's simple and fast, and requires no setup. * doc/lispref/modes.texi (Parser-based Indentation): Update manual. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--standalone-grandparent): New anchor. (c-ts-mode--indent-styles): Replace c-ts-common-statement-offset with standalone-parent. (c-ts-base-mode): Add comment. * lisp/treesit.el: (treesit-simple-indent-presets): New anchor standalone-parent.
Diffstat (limited to 'doc/lispref/modes.texi')
-rw-r--r--doc/lispref/modes.texi10
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 4c40f414ca0..11892aaa40e 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -5093,7 +5093,15 @@ This anchor is a function that is called with 3 arguments: @var{node},
@item parent-bol
This anchor is a function that is called with 3 arguments: @var{node},
@var{parent}, and @var{bol}, and returns the first non-space character
-on the line of @var{parent}.
+on the line which @var{parent}'s start is on.
+
+@item parent-bol
+This anchor is a function that is called with 3 arguments: @var{node},
+@var{parent}, and @var{bol}. It finds the first ancestor node
+(parent, grandparent, etc) of @var{node} that starts on its own line,
+and return the start of that node. ``Starting on its own line'' means
+there is only whitespace character before the node on the line which
+the node's start is on.
@item prev-sibling
This anchor is a function that is called with 3 arguments: @var{node},