diff options
author | Yuan Fu <casouri@gmail.com> | 2023-02-24 19:31:34 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-02-24 19:51:43 -0800 |
commit | d25f24fe57b0bf4d9847ba491ec23c08d44e9d46 (patch) | |
tree | f89da28a02d6aa47a70db90877edd3b9284f43ad | |
parent | c92360c7a3bf8f33d4fe4e7cc351c33ab4a7d5ca (diff) | |
download | emacs-d25f24fe57b0bf4d9847ba491ec23c08d44e9d46.tar.gz emacs-d25f24fe57b0bf4d9847ba491ec23c08d44e9d46.tar.bz2 emacs-d25f24fe57b0bf4d9847ba491ec23c08d44e9d46.zip |
Fix c-ts-common-statement-offset and c-ts-common--node-is
* lisp/progmodes/c-ts-common.el:
(c-ts-common--node-is): Guard against case where the node has no field
name.
(c-ts-common-statement-offset): Do indent a level if the "if" in the
"else if" is on an independent line.
-rw-r--r-- | lisp/progmodes/c-ts-common.el | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 72df65a2287..de0ec0d2876 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -305,6 +305,7 @@ If NODE is nil, return nil." (and parent (string-match-p (car regexp) (treesit-node-type parent)) + (treesit-node-field-name node) (string-match-p (cdr regexp) (treesit-node-field-name node))) @@ -363,7 +364,13 @@ characters on the current line." (cl-incf level)) ;; Flatten "else if" statements. (when (and (c-ts-common--node-is node 'else) - (c-ts-common--node-is node 'if)) + (c-ts-common--node-is node 'if) + ;; But if the "if" is on it's own line, still + ;; indent a level. + (not (save-excursion + (goto-char (treesit-node-start node)) + (looking-back (rx bol (* whitespace)) + (line-beginning-position))))) (cl-decf level))) ;; Go up the tree. (setq node (treesit-node-parent node))) |