>From 6416150bffa8b147758cc4aa131a0681684b56c4 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Tue, 26 May 2024 21:07:50 +0200 Subject: [PATCH] tree-sitter comment-indent-new-line behave more like the standard one. * lisp/progmodes/c-ts-common.el: (c-ts-common-comment-indent-new-line): Single line comment and block comment now behave more like the c-indent-new-comment-line. --- lisp/progmodes/c-ts-common.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index b1520db22e9..f027fc28c04 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -303,20 +303,31 @@ c-ts-common-comment-indent-new-line ;; Or //! (used in rust). ((save-excursion (beginning-of-line) - (looking-at (rx "//" (group (* (any "/!")) (* " "))))) - (let ((whitespaces (match-string 1))) + (re-search-forward + (rx "//" (group (* (any "/!")) (* " "))) + (line-end-position) + t nil)) + (let ((offset (- (match-beginning 0) (line-beginning-position))) + (whitespaces (match-string 1))) (if soft (insert-and-inherit ?\n) (newline 1)) (delete-region (line-beginning-position) (point)) - (insert "//" whitespaces))) + (insert (make-string offset ?\s) "//" whitespaces))) ;; Line starts with /* or /**. ((save-excursion (beginning-of-line) - (looking-at (rx "/*" (group (? "*") (* " "))))) - (let ((whitespace-and-star-len (length (match-string 1)))) + (re-search-forward + (rx "/*" (group (? "*") (* " "))) + (line-end-position) + t nil)) + (let ((offset (- (match-beginning 0) (line-beginning-position))) + (whitespace-and-star-len (length (match-string 1)))) (if soft (insert-and-inherit ?\n) (newline 1)) (delete-region (line-beginning-position) (point)) - (insert " *" (make-string whitespace-and-star-len ?\s)))) + (insert + (make-string offset ?\s) + " *" + (make-string whitespace-and-star-len ?\s)))) ;; Line starts with *. ((save-excursion -- 2.45.1