diff options
author | Yuan Fu <casouri@gmail.com> | 2023-03-05 15:01:54 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-03-05 15:01:54 -0800 |
commit | 7292b24c80143d697870a670963f136db375580b (patch) | |
tree | 75b99ee711fe97143bf92139b6effb055a94ae3d /lisp/progmodes/c-ts-mode.el | |
parent | 75cdc1afbe5a649eed02cd186a38d40b3d0a4439 (diff) | |
download | emacs-7292b24c80143d697870a670963f136db375580b.tar.gz emacs-7292b24c80143d697870a670963f136db375580b.tar.bz2 emacs-7292b24c80143d697870a670963f136db375580b.zip |
Fix c-ts-mode indentation
Not the subject of it, but mentioned in bug#61893.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Skip
the sibling if it doesn't start on it's own line.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
Diffstat (limited to 'lisp/progmodes/c-ts-mode.el')
-rw-r--r-- | lisp/progmodes/c-ts-mode.el | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index f40bbc57eb5..ee4a3bb2de0 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -284,17 +284,25 @@ PARENT and BOL are like other anchor functions." (treesit-node-first-child-for-pos parent bol) t) (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)))) + (save-excursion + (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))) + ;; If the start of the previous sibling isn't at the + ;; beginning of a line, something's probably not quite + ;; right, go a step further. + (_ (goto-char (treesit-node-start prev-sibling)) + (if (looking-back (rx bol (* whitespace)) + (line-beginning-position)) + (setq continue nil) + (setq prev-sibling + (treesit-node-prev-sibling prev-sibling))))))) ;; 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))) |