From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61550: 30.0.50; c-ts-mode comment-style Date: Fri, 17 Feb 2023 23:51:10 +0100 Message-ID: <87k00f6h41.fsf@thornhill.no> References: <87wn4hak35.fsf@web.de> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12185"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61550@debbugs.gnu.org To: Felix Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 17 23:52:14 2023 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 1pT9aP-0002zT-TQ for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Feb 2023 23:52:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pT9aG-0006iz-7Q; Fri, 17 Feb 2023 17:52:04 -0500 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 1pT9aE-0006io-QE for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 17:52:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pT9aE-0007j6-HQ for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 17:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pT9aE-000512-3s for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 17:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Feb 2023 22:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61550 X-GNU-PR-Package: emacs Original-Received: via spool by 61550-submit@debbugs.gnu.org id=B61550.167667427619223 (code B ref 61550); Fri, 17 Feb 2023 22:52:02 +0000 Original-Received: (at 61550) by debbugs.gnu.org; 17 Feb 2023 22:51:16 +0000 Original-Received: from localhost ([127.0.0.1]:41817 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pT9ZU-0004zy-E7 for submit@debbugs.gnu.org; Fri, 17 Feb 2023 17:51:16 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]:57228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pT9ZS-0004zp-2Y for 61550@debbugs.gnu.org; Fri, 17 Feb 2023 17:51:15 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1676674271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/zROglqovJC6+2fjCSFk6an1KGHCb+jVqbJFqkYyEKs=; b=P5rVwd7OFjaHdZELP1QnwLlgCAq0JKi9AeyQ/PYGFhPg57vi/xQApJabXxuqM8rVjO9dr5 hr7SjOij6hmVfsbbKtLyIMc95FuZIhuwwwkx4sj35r7WfYgldiNZbARCXLKH7R4CJHT0lw Lb43ml6eEx0YkLuQY9Fb3tts1S5k57WSqo812/ZgqheFTj4e98ukEtK9BpQFi/HI3KceKT kx/zzHWclQTyf7r6vMYHKSJFR/UA5FCHBYAM5JhpXbe4GHIDRVk8xRrSi8lhV8uYU5e77u b9Y9nH3hmBo3kyKodaCN/yqFjP9WpPBq70JOqQe91zZR36Xr3g4fL7lGcVDodw== In-Reply-To: <87wn4hak35.fsf@web.de> (Felix's message of "Thu, 16 Feb 2023 13:08:46 +0100") X-Migadu-Flow: FLOW_OUT 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:255909 Archived-At: --=-=-= Content-Type: text/plain Hi Felix! > c-ts-mode needs it's own version of the command 'c-toggle-comment-style'. > Invoking the original 'c-toggle-comment-style' in c-ts-mode breaks the > comment functions. Can you test this for me? It seems to behave similarly to c-toggle-comment-style, right? Are you satisfied with this? And what do you think, Eli, too big for emacs-29? Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-comment-style-toggle-for-c-ts-mode.patch >From e5b7bf56a25089a4ae27056f31d71d2b78dc1adf Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Fri, 17 Feb 2023 23:46:24 +0100 Subject: [PATCH] Add comment style toggle for c-ts-mode * lisp/progmodes/c-ts-mode.el (c-ts-mode-toggle-comment-style): New command. (c-ts-base-mode-map): Add binding. (c-ts-mode-set-modeline): New function. (c-ts-mode): Set modeline. (c++-ts-mode): Set modeline. --- lisp/progmodes/c-ts-mode.el | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index a60c464093..05875e9267 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -87,6 +87,25 @@ c-ts-mode-indent-offset :safe 'integerp :group 'c) +(defun c-ts-mode-toggle-comment-style () + "Toggle the comment style between block and line comments. +Optional numeric ARG, if supplied, switches to block comment +style when positive, to line comment style when negative, and +just toggles it when zero or left out." + (interactive) + (pcase-let ((`(,starter . ,ender) + (if (string= comment-start "// ") + (cons "/* " " */") + (cons "// " "")))) + (setq-local comment-start starter + comment-end ender)) + (c-ts-mode-set-modeline)) + +(defun c-ts-mode-set-modeline () + (setq mode-name + (concat (if (eq major-mode 'c-ts-mode) "C" "C++") comment-start)) + (force-mode-line-update)) + (defun c-ts-mode--indent-style-setter (sym val) "Custom setter for `c-ts-mode-set-style'. @@ -740,7 +759,8 @@ c-ts-base-mode-map :parent prog-mode-map "C-c C-q" #'c-ts-mode-indent-defun "C-c ." #'c-ts-mode-set-style - "C-c C-c" #'comment-region) + "C-c C-c" #'comment-region + "C-c C-k" #'c-ts-mode-toggle-comment-style) ;;;###autoload (define-derived-mode c-ts-base-mode prog-mode "C" @@ -824,6 +844,7 @@ c-ts-mode in your configuration." :group 'c + :after-hook (c-ts-mode-set-modeline) (when (treesit-ready-p 'c) (treesit-parser-create 'c) @@ -856,6 +877,7 @@ c++-ts-mode in your configuration." :group 'c++ + :after-hook (c-ts-mode-set-modeline) (when (treesit-ready-p 'cpp) (treesit-parser-create 'cpp) -- 2.34.1 --=-=-=--