From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.bugs 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 Message-ID: <2561105.XAFRqVoOGU@3-191.divsi.unimi.it> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3616587.dWV9SEqChM" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23904"; mail-complaints-to="usenet@ciao.gmane.io" To: 71225@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 27 16:10:42 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sBb3i-0005zQ-DU for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 May 2024 16:10:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBb2x-0002aA-6E; Mon, 27 May 2024 10:09:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBb2v-0002Zf-LW for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 10:09:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBb2v-0005Kc-BS for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 10:09:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sBb33-0008RA-Uk for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 10:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 May 2024 14:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71225 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.171681897932396 (code B ref -1); Mon, 27 May 2024 14:10:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 May 2024 14:09:39 +0000 Original-Received: from localhost ([127.0.0.1]:45001 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBb2g-0008QR-QF for submit@debbugs.gnu.org; Mon, 27 May 2024 10:09:39 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:48608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBb2e-0008QH-Li for submit@debbugs.gnu.org; Mon, 27 May 2024 10:09:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBb2V-0002UI-Jf for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 10:09:27 -0400 Original-Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBb2T-0005Iu-FC for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 10:09:26 -0400 Original-Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6ad8243dba8so4748596d6.3 for ; Mon, 27 May 2024 07:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716818962; x=1717423762; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=kYgs+EaQM/vcyIzwRQKWMazOXLdzSlk+qO/JHtsggq4=; b=erZdjOiAsXsV5Eo7tBxzvj5WqwwzWGlMhHVZHdx7uVdDS+/nA9m4sAvRzE5HjfRFpW t5ZzoZO0EX4AEv6eyKWVMumnUXBTqvWdEdPB7hsmbKeiJWMnsyMoCjTaUD7yFVdqy91u MsOhoHfSA7cZOhjJnWanDv1Yd+HenA/jKHTvsGxP+MLzyBCInwKbOTtp1gwEiJUvafzS s6qxRraRZtJ7N5Pk1E8ukSAFvn6aI7AnA8n6/osmZoqjWihqtnfp4ZrXMjY8zR+2UOAI 6gbixRNACFIU4hagqpQ609QiSGH9l3K/4LkU0lOeLCn/SK81R/rM17gXepQnPo31WtDN RVvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716818962; x=1717423762; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kYgs+EaQM/vcyIzwRQKWMazOXLdzSlk+qO/JHtsggq4=; b=fTNJMhjQ2O3YuFFfvbHQ4UkWywK6UulcBN6kNaUxD7U3u6tTmtfa0aGv4w6Fr2DTPF g9N1Lj0y3RQ5LQwF1kM9RIKz7awBwSXNhJkGFLEHvpZt1ch3KPdz3DtdaTRLWP9tDcyk 2DK58jIK4ndTuklp6srhKDceTISs/H3xbhSjD0WQYATTHobV2Nn193qW2kLeabbIIpIk s1/8lJsSqCKx8e0+sUo+2NWLiSRvcK7qE3o958X6z0c1jxq+l2L6N2XTVAGX35DuZCWp vFg5O4apfHJ0mPSRmHR0IQKGOTkEDzspG6abI0A84gx85FydtVRIKabz0ykKgDMJW5fo wEAQ== X-Gm-Message-State: AOJu0YyCUhRhQSY1UcaxBuZx7ODVqCSn+yt4nBL2eE+oTn0HMeKP0XG7 khQf381yymEeZrgskZjq72gBUSevCAT2M3COgNsp4AoHS+xbqc9ME31zBA== X-Google-Smtp-Source: AGHT+IH4d1R3mlyMc6JLLX+sU75wZLW2ectk61xAp4PhHvyRG49Dt4vNblIk5vVxr0Kjt1GEJq2rdQ== X-Received: by 2002:a05:6214:5f04:b0:6ac:78b2:749c with SMTP id 6a1803df08f44-6ad8d7a5c2fmr3248156d6.15.1716818961814; Mon, 27 May 2024 07:09:21 -0700 (PDT) Original-Received: from 3-191.divsi.unimi.it (3-191.divsi.unimi.it. [159.149.3.191]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ad791691e4sm15505736d6.138.2024.05.27.07.09.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:09:21 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=v.pupillo@gmail.com; helo=mail-qv1-xf30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286039 Archived-At: This is a multi-part message in MIME format. --nextPart3616587.dWV9SEqChM Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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. --nextPart3616587.dWV9SEqChM Content-Disposition: attachment; filename="0001-tree-sitter-comment-indent-new-line-behave-more-like.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="x-UTF_8J"; name="0001-tree-sitter-comment-indent-new-line-behave-more-like.patch" >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 --nextPart3616587.dWV9SEqChM--