summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2022-12-24 00:15:48 -0800
committerYuan Fu <casouri@gmail.com>2022-12-24 00:33:17 -0800
commite4e3634539920d14395b19121715c50b3f022909 (patch)
tree3dca7fdcb50b097b3181a720f9ff3f05cecefd41
parente30621caa2c93018d137a5b75fb0db897b6db9a8 (diff)
downloademacs-e4e36345399.tar.gz
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.
-rw-r--r--lisp/progmodes/c-ts-mode.el21
1 files changed, 20 insertions, 1 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 901b22e3c01..10f7bf58403 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")