[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 e4e3634539 4/5: Improve c-ts-mode block comment indent (bug#602
From: |
Yuan Fu |
Subject: |
emacs-29 e4e3634539 4/5: Improve c-ts-mode block comment indent (bug#60270) |
Date: |
Sat, 24 Dec 2022 03:33:28 -0500 (EST) |
branch: emacs-29
commit e4e3634539920d14395b19121715c50b3f022909
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Improve c-ts-mode block comment indent (bug#60270)
Now it handles stuff like
/**
* @some_func:
* @arg1:
*/
* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Use new
matcher and anchor.
(c-ts-mode--looking-at-star): New matcher.
(c-ts-mode--comment-start-after-first-star): New anchor.
---
lisp/progmodes/c-ts-mode.el | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 901b22e3c0..10f7bf5840 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -102,7 +102,8 @@ MODE is either `c' or `cpp'."
((node-is "else") parent-bol 0)
((node-is "case") parent-bol 0)
((node-is "preproc_arg") no-indent)
- ((and (parent-is "comment") comment-end) comment-start -1)
+ ((and (parent-is "comment") c-ts-mode--looking-at-star)
+ c-ts-mode--comment-start-after-first-star -1)
((parent-is "comment") prev-adaptive-prefix 0)
((node-is "labeled_statement") parent-bol 0)
((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset)
@@ -168,6 +169,24 @@ MODE is either `c' or `cpp'."
('linux (alist-get 'linux (c-ts-mode--indent-styles mode)))))))
`((,mode ,@style))))
+(defun c-ts-mode--looking-at-star (&rest _)
+ "A tree-sitter simple indent matcher.
+Matches if there is a \"*\" after point (ignoring whitespace in
+between)."
+ (looking-at (rx (* (syntax whitespace)) "*")))
+
+(defun c-ts-mode--comment-start-after-first-star (_n parent &rest _)
+ "A tree-sitter simple indent anchor.
+Finds the \"/*\" and returns the point after the \"*\".
+Assumes PARENT is a comment node."
+ (save-excursion
+ (goto-char (treesit-node-start parent))
+ (if (looking-at (rx "/*"))
+ (match-end 0)
+ (point))))
+
+;;; Font-lock
+
(defvar c-ts-mode--preproc-keywords
'("#define" "#if" "#ifdef" "#ifndef"
"#else" "#elif" "#endif" "#include")