[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter a915d836fc: Keep cursor position in treesit-indent
From: |
Yuan Fu |
Subject: |
feature/tree-sitter a915d836fc: Keep cursor position in treesit-indent |
Date: |
Sat, 29 Oct 2022 15:03:17 -0400 (EDT) |
branch: feature/tree-sitter
commit a915d836fce238cd57233f67e8d2451a26d2fb6b
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Keep cursor position in treesit-indent
* lisp/treesit.el (treesit-indent): Create a marker and jump back to
that marker after indentation.
---
lisp/treesit.el | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index dd0aca5049..90e5d09693 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -974,12 +974,18 @@ Return (ANCHOR . OFFSET). This function is used by
"Indent according to the result of `treesit-indent-function'."
(treesit-update-ranges)
(pcase-let* ((`(,anchor . ,offset) (treesit--indent-1)))
- (when (and anchor offset)
- (let ((col (+ (save-excursion
- (goto-char anchor)
- (current-column))
- offset)))
- (indent-line-to col)))))
+ (if (and anchor offset)
+ (let ((col (+ (save-excursion
+ (goto-char anchor)
+ (current-column))
+ offset))
+ (delta (- (point-max) (point))))
+ (indent-line-to col)
+ ;; Now point is at the end of indentation. If we started
+ ;; from within the line, go back to where we started.
+ (when (> (- (point-max) delta) (point))
+ (goto-char (- (point-max) delta))))
+ 'noindent)))
(defvar treesit--indent-region-batch-size 400
"How many lines of indent value do we precompute.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/tree-sitter a915d836fc: Keep cursor position in treesit-indent,
Yuan Fu <=