unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Felix <felix.dick@web.de>
To: emacs-devel <emacs-devel@gnu.org>
Subject: [PATCH] Make c-ts-mode-toggle-comment-style match it's docstring.
Date: Mon, 27 Feb 2023 16:15:02 +0100	[thread overview]
Message-ID: <87edqb86we.fsf@web.de> (raw)

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


Implement the optional numeric arg mentioned in the docstring.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: c-ts-comment.patch --]
[-- Type: text/x-patch, Size: 1450 bytes --]

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 035df909eb2..9d4021866f0 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -87,19 +87,23 @@ c-ts-mode-indent-offset
   :safe 'integerp
   :group 'c)

-(defun c-ts-mode-toggle-comment-style ()
+(defun c-ts-mode-toggle-comment-style (&optional arg)
   "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))
+  (interactive "P")
+  (let ((prevstate-line (string= comment-start "// ")))
+    (when (or (not arg)
+              (zerop (setq arg (prefix-numeric-value arg)))
+              (xor (> 0 arg) prevstate-line))
+      (pcase-let ((`(,starter . ,ender)
+                   (if prevstate-line
+                       (cons "/* " " */")
+                     (cons "// " ""))))
+        (setq-local comment-start starter
+                    comment-end ender))
+      (c-ts-mode-set-modeline))))

 (defun c-ts-mode-set-modeline ()
   (setq mode-name

             reply	other threads:[~2023-02-27 15:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 15:15 Felix [this message]
2023-02-28 13:39 ` [PATCH] Make c-ts-mode-toggle-comment-style match it's docstring Eli Zaretskii
2023-02-28 16:22   ` Felix
2023-02-28 16:52     ` 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=87edqb86we.fsf@web.de \
    --to=felix.dick@web.de \
    --cc=emacs-devel@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).