unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
@ 2024-05-27 14:09 Vincenzo Pupillo
  2024-05-28 18:15 ` Andrea Corallo
  0 siblings, 1 reply; 5+ messages in thread
From: Vincenzo Pupillo @ 2024-05-27 14:09 UTC (permalink / raw)
  To: 71225

[-- 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
  2024-05-27 14:09 bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments Vincenzo Pupillo
@ 2024-05-28 18:15 ` Andrea Corallo
  2024-05-28 18:30   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 5+ messages in thread
From: Andrea Corallo @ 2024-05-28 18:15 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: 71225, Theodor Thornhill

Vincenzo Pupillo <v.pupillo@gmail.com> writes:

> 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.

Adding Theodor in.

Thanks

  Andrea





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
  2024-05-28 18:15 ` 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
  0 siblings, 1 reply; 5+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-28 18:30 UTC (permalink / raw)
  To: Andrea Corallo, Vincenzo Pupillo; +Cc: 71225

On May 28, 2024 8:15:20 PM GMT+02:00, Andrea Corallo <acorallo@gnu.org> wrote:
>Vincenzo Pupillo <v.pupillo@gmail.com> writes:
>
>> 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.
>
>Adding Theodor in.
>
>Thanks
>
>  Andrea

Thanks for the ping, I'll take a look :)

Theo






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-06-02  8:11 UTC (permalink / raw)
  To: Andrea Corallo; +Cc: 71225, Vincenzo Pupillo

Theodor Thornhill <theo@thornhill.no> writes:

> On May 28, 2024 8:15:20 PM GMT+02:00, Andrea Corallo <acorallo@gnu.org> wrote:
>>Vincenzo Pupillo <v.pupillo@gmail.com> writes:
>>
>>> 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)


Thanks, pushed to master.

Theo





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2024-06-02  8:30 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: v.pupillo, 71225-done, acorallo

> Cc: 71225@debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@gmail.com>
> Date: Sun, 02 Jun 2024 10:11:27 +0200
> From:  Theodor Thornhill via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> 
> Thanks, pushed to master.

Thanks, I'm therefore closing this bug.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-02  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 14:09 bug#71225: 30.0.50; [PATCH] c-ts-common-comment-indent-new-line does not behave like c/c++-mode in comments Vincenzo Pupillo
2024-05-28 18:15 ` 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

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).