* bug#58873: 29.0.50; Fix indent-line-function in tree-sitter
@ 2022-10-29 19:11 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-29 20:06 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-10-29 19:11 UTC (permalink / raw)
To: 58873; +Cc: casouri
[-- Attachment #1: Type: text/plain, Size: 702 bytes --]
Hi Yuan!
There were some regressions with the new indent-line-function - see
attached patch. We need the point, not the indentation, and the
save-excursion is actually needed.
consider:
```
foo({
thing: 1,
tho|ng: 2, // <--- point is |
})
```
if you indent now you want to end up like this:
```
foo({
thing: 1,
tho|ng: 2, // <--- point is |
})
```
or if
```
foo({
thing: 1,
|thong: 2, // <--- point is |
})
```
You want to end up like this:
```
foo({
thing: 1,
|thong: 2, // <--- point is |
})
```
This patch addresses this :-)
In addition there was a bug where the parent-bol didn't indent
correctly, this should also be fixed now.
Thanks again, Yuan!
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix indent-line-function in tree-sitter --]
[-- Type: text/x-patch, Size: 2151 bytes --]
From b8af08cbe03b66437901af2164e3b31c7df46f04 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 29 Oct 2022 21:03:23 +0200
Subject: [PATCH] Fix indent-line-function
* lisp/treesit.el (treesit-simple-indent-presets): We need the actual
position, not the indentation offset from column 0. Revert earlier change.
(treesit-indent): Revert earlier change to preserve behavior with
similar functions for other modes. Specifically. We want to preserve
position in text if we are "in front of" the indentation goal.
Otherwise just jump to the correct indentation.
---
lisp/treesit.el | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index dd0aca5049..4032af5f14 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -783,7 +783,8 @@ treesit-simple-indent-presets
(lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
- (current-indentation)))))
+ (back-to-indentation)
+ (point)))))
(prev-sibling . ,(byte-compile
(lambda (node &rest _)
(treesit-node-start
@@ -973,13 +974,19 @@ treesit--indent-1
(defun treesit-indent ()
"Indent according to the result of `treesit-indent-function'."
(treesit-update-ranges)
- (pcase-let* ((`(,anchor . ,offset) (treesit--indent-1)))
+ (pcase-let* ((orig-pos (point))
+ (bol (save-excursion
+ (back-to-indentation)
+ (point)))
+ (`(,anchor . ,offset) (treesit--indent-1)))
(when (and anchor offset)
(let ((col (+ (save-excursion
(goto-char anchor)
(current-column))
offset)))
- (indent-line-to col)))))
+ (if (< bol orig-pos)
+ (save-excursion (indent-line-to col))
+ (indent-line-to col))))))
(defvar treesit--indent-region-batch-size 400
"How many lines of indent value do we precompute.
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#58873: 29.0.50; Fix indent-line-function in tree-sitter
2022-10-29 19:11 bug#58873: 29.0.50; Fix indent-line-function in tree-sitter Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-10-29 20:06 ` Yuan Fu
2022-11-12 20:33 ` Stefan Kangas
0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2022-10-29 20:06 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: 58873
> On Oct 29, 2022, at 12:11 PM, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors <bug-gnu-emacs@gnu.org> wrote:
>
>
> Hi Yuan!
>
> There were some regressions with the new indent-line-function - see
> attached patch. We need the point, not the indentation, and the
> save-excursion is actually needed.
>
> consider:
>
> ```
> foo({
> thing: 1,
> tho|ng: 2, // <--- point is |
> })
> ```
>
> if you indent now you want to end up like this:
>
> ```
> foo({
> thing: 1,
> tho|ng: 2, // <--- point is |
> })
> ```
>
> or if
>
> ```
> foo({
> thing: 1,
> |thong: 2, // <--- point is |
> })
> ```
> You want to end up like this:
>
> ```
> foo({
> thing: 1,
> |thong: 2, // <--- point is |
> })
> ```
>
> This patch addresses this :-)
>
> In addition there was a bug where the parent-bol didn't indent
> correctly, this should also be fixed now.
>
> Thanks again, Yuan!
I applied your change (manually), thanks!
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#58873: 29.0.50; Fix indent-line-function in tree-sitter
2022-10-29 20:06 ` Yuan Fu
@ 2022-11-12 20:33 ` Stefan Kangas
2022-11-14 9:16 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2022-11-12 20:33 UTC (permalink / raw)
To: Yuan Fu; +Cc: 58873-done, Theodor Thornhill
Yuan Fu <casouri@gmail.com> writes:
> I applied your change (manually), thanks!
It seems this was installed but never closed so I'm doing that now.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#58873: 29.0.50; Fix indent-line-function in tree-sitter
2022-11-12 20:33 ` Stefan Kangas
@ 2022-11-14 9:16 ` Yuan Fu
0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2022-11-14 9:16 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 58873-done, Theodor Thornhill
> On Nov 12, 2022, at 12:33 PM, Stefan Kangas <stefankangas@gmail.com> wrote:
>
> Yuan Fu <casouri@gmail.com> writes:
>
>> I applied your change (manually), thanks!
>
> It seems this was installed but never closed so I'm doing that now.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-14 9:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-29 19:11 bug#58873: 29.0.50; Fix indent-line-function in tree-sitter Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-29 20:06 ` Yuan Fu
2022-11-12 20:33 ` Stefan Kangas
2022-11-14 9:16 ` Yuan Fu
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.