* bug#61550: 30.0.50; c-ts-mode comment-style
@ 2023-02-16 12:08 Felix
2023-02-17 22:51 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 5+ messages in thread
From: Felix @ 2023-02-16 12:08 UTC (permalink / raw)
To: 61550
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#61550: 30.0.50; c-ts-mode comment-style
2023-02-16 12:08 bug#61550: 30.0.50; c-ts-mode comment-style Felix
@ 2023-02-17 22:51 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 23:46 ` Felix
2023-02-18 6:59 ` Eli Zaretskii
0 siblings, 2 replies; 5+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-17 22:51 UTC (permalink / raw)
To: Felix; +Cc: 61550
[-- Attachment #1: Type: text/plain, Size: 361 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-comment-style-toggle-for-c-ts-mode.patch --]
[-- Type: text/x-patch, Size: 2276 bytes --]
From e5b7bf56a25089a4ae27056f31d71d2b78dc1adf Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#61550: 30.0.50; c-ts-mode comment-style
2023-02-17 22:51 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-17 23:46 ` Felix
2023-02-18 6:59 ` Eli Zaretskii
1 sibling, 0 replies; 5+ messages in thread
From: Felix @ 2023-02-17 23:46 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: 61550
Hi Theodor,
it works!
Thanks a lot!
Theodor Thornhill <theo@thornhill.no> writes:
> 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
>
> [2. text/x-patch; 0001-Add-comment-style-toggle-for-c-ts-mode.patch]...
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#61550: 30.0.50; c-ts-mode comment-style
2023-02-17 22:51 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 23:46 ` Felix
@ 2023-02-18 6:59 ` Eli Zaretskii
2023-02-18 7:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-02-18 6:59 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: 61550, felix.dick
> Cc: 61550@debbugs.gnu.org
> Date: Fri, 17 Feb 2023 23:51:10 +0100
> From: Theodor Thornhill via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> > 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?
No, not too big.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#61550: 30.0.50; c-ts-mode comment-style
2023-02-18 6:59 ` Eli Zaretskii
@ 2023-02-18 7:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 5+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-18 7:24 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 61550, felix.dick
On 18 February 2023 07:59:35 CET, Eli Zaretskii <eliz@gnu.org> wrote:
>> Cc: 61550@debbugs.gnu.org
>> Date: Fri, 17 Feb 2023 23:51:10 +0100
>> From: Theodor Thornhill via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>
>> > 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?
>
>No, not too big.
>
>Thanks.
Great! Installing later today.
Theo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-18 7:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16 12:08 bug#61550: 30.0.50; c-ts-mode comment-style Felix
2023-02-17 22:51 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 23:46 ` Felix
2023-02-18 6:59 ` Eli Zaretskii
2023-02-18 7:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
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).