]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement prefix arg for 'c-ts-mode-toggle-comment-style'
authorFelix <felix.dick@web.de>
Mon, 27 Feb 2023 15:15:02 +0000 (16:15 +0100)
committerEli Zaretskii <eliz@gnu.org>
Tue, 28 Feb 2023 13:31:49 +0000 (15:31 +0200)
* lisp/progmodes/c-ts-mode.el (c-ts-mode-toggle-comment-style):
Actually implement the optional numeric arg mentioned in the
docstring.

Copyright-paperwork-exempt: yes

lisp/progmodes/c-ts-mode.el

index 4b66824c44fa8916e26cb35407c3ced2b04c498a..53f7839e4af6d03b514d1194c2d1c3df71a2bc41 100644 (file)
   :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