From 0074db4224b4269eec464ac00eb751d919aec408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augustin=20Ch=C3=A9neau?= Date: Tue, 26 Sep 2023 14:10:40 +0200 Subject: [PATCH 2/2] c-ts-mode: handle specific comment formatting --- lisp/progmodes/c-ts-common.el | 11 +++++++++++ lisp/progmodes/c-ts-mode.el | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 3b0814970ad..1ea41260ab8 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -56,6 +56,17 @@ ;;; Comment indentation and filling + +(defun c-ts-common-looking-at (char &rest chars) + (lambda (_n _p bol &rest _) + (let ((res nil)) + (setq res (eq (char-after bol) char)) + (while (and chars (not res)) + (setq char (car chars) + chars (cdr chars) + res (eq (char-after bol) char))) + res))) + (defun c-ts-common-looking-at-star (_n _p bol &rest _) "A tree-sitter simple indent matcher. Matches if there is a \"*\" after BOL." diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index cb236447368..76cbad50d06 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -371,8 +371,10 @@ c-ts-mode--indent-styles ((node-is "preproc_arg") no-indent) ;; `c-ts-common-looking-at-star' has to come before ;; `c-ts-common-comment-2nd-line-matcher'. - ((and (parent-is "comment") c-ts-common-looking-at-star) + ((and (parent-is "comment") c-ts-common-looking-at ?*) c-ts-common-comment-start-after-first-star -1) + ((and (parent-is "comment") (c-ts-common-looking-at ?| ?\\ ?`)) + c-ts-common-comment-start-after-first-star -2) (c-ts-common-comment-2nd-line-matcher c-ts-common-comment-2nd-line-anchor 1) -- 2.42.0