summaryrefslogtreecommitdiff
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorFelix <felix.dick@web.de>2023-02-27 16:15:02 +0100
committerEli Zaretskii <eliz@gnu.org>2023-02-28 15:31:49 +0200
commitc2b5c6acc586cc6a2e66e23a6208045d456ae41a (patch)
tree6ded1d1ef9a1d8bacec51080e6d18fba440d203e /lisp/progmodes
parenteb2ab52fb0180daa792d4b7ff290f348fef12115 (diff)
downloademacs-c2b5c6acc586cc6a2e66e23a6208045d456ae41a.tar.gz
emacs-c2b5c6acc586cc6a2e66e23a6208045d456ae41a.tar.bz2
emacs-c2b5c6acc586cc6a2e66e23a6208045d456ae41a.zip
Implement prefix arg for 'c-ts-mode-toggle-comment-style'
* 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
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/c-ts-mode.el22
1 files changed, 13 insertions, 9 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 4b66824c44f..53f7839e4af 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -88,19 +88,23 @@
: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