Function: c-toggle-comment-style

c-toggle-comment-style is an interactive and byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-toggle-comment-style &optional ARG)

Documentation

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.

This action does nothing when the mode only has one comment style.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-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.

This action does nothing when the mode only has one comment style."
  (interactive "P")
  (setq c-block-comment-flag
	(cond
	 ((and c-line-comment-starter c-block-comment-starter)
	  (c-calculate-state arg c-block-comment-flag))
	 (c-line-comment-starter nil)
	 (t t)))
  (setq comment-start
	(concat (if c-block-comment-flag
		    c-block-comment-starter
		  c-line-comment-starter)
		" "))
  (setq comment-end
	(if c-block-comment-flag
	    (concat " " c-block-comment-ender)
	  ""))
  ;; If necessary, invert the sense of fontification of wrong style comments.
  (when (and c-mark-wrong-style-of-comment
	     font-lock-mode
	     c-block-comment-starter
	     c-block-comment-ender)
    (save-excursion
      (save-restriction
	(widen)
	(goto-char (point-min))
	(c-font-lock-flush (point-min) (point-max)))))
  (c-update-modeline)
  (c-keep-region-active))