[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 9e105d483fa: Fix c-ts-mode indentation for statement after prep
From: |
Yuan Fu |
Subject: |
emacs-29 9e105d483fa: Fix c-ts-mode indentation for statement after preproc (bug#61893) |
Date: |
Thu, 2 Mar 2023 23:00:18 -0500 (EST) |
branch: emacs-29
commit 9e105d483fa54c5f07a42b4c0fab40507f1fd9ec
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix c-ts-mode indentation for statement after preproc (bug#61893)
Originally our c-ts-mode--anchor-prev-sibling only specially handled
labeled_statements, now we add special case for preproc in the similar
fasion: instead of using the preproc directive as anchor, use the last
statement in that preproc as the anchor. Thus effectively ignore the
preproc.
There should be an accompanying test, but there are some problem in
the elif preproc directive indent so it would pass, we'll add the test
when that is fixed.
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--anchor-prev-sibling): Add special case for preproc
directives.
---
lisp/progmodes/c-ts-mode.el | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 3afd7a4a913..eb07eb74676 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -282,12 +282,19 @@ PARENT and BOL are like other anchor functions."
(or (treesit-node-prev-sibling node t)
(treesit-node-prev-sibling
(treesit-node-first-child-for-pos parent bol) t)
- (treesit-node-child parent -1 t))))
- (while (and prev-sibling
- (equal "labeled_statement"
- (treesit-node-type prev-sibling)))
- ;; The 0th child is the label, the 1th the colon.
- (setq prev-sibling (treesit-node-child prev-sibling 2)))
+ (treesit-node-child parent -1 t)))
+ (continue t))
+ (while (and prev-sibling continue)
+ (pcase (treesit-node-type prev-sibling)
+ ;; Get the statement in the label.
+ ("labeled_statement"
+ (setq prev-sibling (treesit-node-child prev-sibling 2)))
+ ;; Get the last statement in the preproc. Tested by
+ ;; "Prev-Sibling When Prev-Sibling is Preproc" test.
+ ((or "preproc_if" "preproc_ifdef" "preproc_elif" "preproc_else")
+ (setq prev-sibling (treesit-node-child prev-sibling -2)))
+ ;; Don't do anything special.
+ (_ (setq continue nil))))
;; This could be nil if a) there is no prev-sibling or b)
;; prev-sibling doesn't have a child.
(treesit-node-start prev-sibling)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-29 9e105d483fa: Fix c-ts-mode indentation for statement after preproc (bug#61893),
Yuan Fu <=