unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Vincenzo Pupillo <v.pupillo@gmail.com>
To: 71225@debbugs.gnu.org
Subject: bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
Date: Mon, 27 May 2024 16:09:18 +0200	[thread overview]
Message-ID: <2561105.XAFRqVoOGU@3-191.divsi.unimi.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 624 bytes --]

Hi, 
the c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments. 
M-j also behaves differently in different places.

// M-j wrong behavior.
int test(int a)
{
  /** (1)
  */
  int a;

  /* (1)
  */
  int b;
  // test (1)

  int c; // blah blah
         // (3)
}

/* (2)
 */

/** (2)
*/

// (2)

If you place the cursor at the positions indicated by (1) and (2), press M-j the result is different and is different from what happens with c/c++-mode. 

As a bonus, the attached patch also allows single-line comments placed at the end of a line to be indented as in c-mode (as in "(3)")

Thank you.
V.


[-- Attachment #2: 0001-tree-sitter-comment-indent-new-line-behave-more-like.patch --]
[-- Type: text/x-patch, Size: 2191 bytes --]

From 6416150bffa8b147758cc4aa131a0681684b56c4 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
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


             reply	other threads:[~2024-05-27 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 14:09 Vincenzo Pupillo [this message]
2024-05-28 18:15 ` bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments Andrea Corallo
2024-05-28 18:30   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02  8:11     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02  8:30       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2561105.XAFRqVoOGU@3-191.divsi.unimi.it \
    --to=v.pupillo@gmail.com \
    --cc=71225@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).