diff options
| author | Yuan Fu | 2022-10-29 14:49:31 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-10-29 14:49:31 -0700 |
| commit | f6e3de3f63616d7bd52c1390f9dea70fa33e49c2 (patch) | |
| tree | d1c14acf823ed4ce3308f2f8740790297dd0bece | |
| parent | da87895df2d6b21468b187f5a4e2ca8710e35ee7 (diff) | |
| download | emacs-f6e3de3f63616d7bd52c1390f9dea70fa33e49c2.tar.gz emacs-f6e3de3f63616d7bd52c1390f9dea70fa33e49c2.zip | |
Not return noindent in treesit-indent
* lisp/treesit.el (treesit-indent): Don't return noindent.
(treesit-defun-type-regexp): Return (nil . nil) rather than nil.
| -rw-r--r-- | lisp/treesit.el | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 027f5ecb77d..624e809b46d 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -974,19 +974,21 @@ Return (ANCHOR . OFFSET). This function is used by | |||
| 974 | (defun treesit-indent () | 974 | (defun treesit-indent () |
| 975 | "Indent according to the result of `treesit-indent-function'." | 975 | "Indent according to the result of `treesit-indent-function'." |
| 976 | (treesit-update-ranges) | 976 | (treesit-update-ranges) |
| 977 | ;; We don't return 'noindent even if no rules match, because | ||
| 978 | ;; `indent-for-tab-command' tries to indent itself when we return | ||
| 979 | ;; 'noindent, which leads to wrong indentation at times. | ||
| 977 | (pcase-let* ((`(,anchor . ,offset) (treesit--indent-1))) | 980 | (pcase-let* ((`(,anchor . ,offset) (treesit--indent-1))) |
| 978 | (if (and anchor offset) | 981 | (when (and anchor offset) |
| 979 | (let ((col (+ (save-excursion | 982 | (let ((col (+ (save-excursion |
| 980 | (goto-char anchor) | 983 | (goto-char anchor) |
| 981 | (current-column)) | 984 | (current-column)) |
| 982 | offset)) | 985 | offset)) |
| 983 | (delta (- (point-max) (point)))) | 986 | (delta (- (point-max) (point)))) |
| 984 | (indent-line-to col) | 987 | (indent-line-to col) |
| 985 | ;; Now point is at the end of indentation. If we started | 988 | ;; Now point is at the end of indentation. If we started |
| 986 | ;; from within the line, go back to where we started. | 989 | ;; from within the line, go back to where we started. |
| 987 | (when (> (- (point-max) delta) (point)) | 990 | (when (> (- (point-max) delta) (point)) |
| 988 | (goto-char (- (point-max) delta)))) | 991 | (goto-char (- (point-max) delta))))))) |
| 989 | 'noindent))) | ||
| 990 | 992 | ||
| 991 | (defvar treesit--indent-region-batch-size 400 | 993 | (defvar treesit--indent-region-batch-size 400 |
| 992 | "How many lines of indent value do we precompute. | 994 | "How many lines of indent value do we precompute. |
| @@ -1066,8 +1068,9 @@ Return (ANCHOR . OFFSET) where ANCHOR is a node, OFFSET is the | |||
| 1066 | indentation offset, meaning indent to align with ANCHOR and add | 1068 | indentation offset, meaning indent to align with ANCHOR and add |
| 1067 | OFFSET." | 1069 | OFFSET." |
| 1068 | (if (null parent) | 1070 | (if (null parent) |
| 1069 | (when treesit--indent-verbose | 1071 | (progn (when treesit--indent-verbose |
| 1070 | (message "PARENT is nil, not indenting")) | 1072 | (message "PARENT is nil, not indenting")) |
| 1073 | (cons nil nil)) | ||
| 1071 | (let* ((language (treesit-node-language parent)) | 1074 | (let* ((language (treesit-node-language parent)) |
| 1072 | (rules (alist-get language | 1075 | (rules (alist-get language |
| 1073 | treesit-simple-indent-rules))) | 1076 | treesit-simple-indent-rules))) |