Function: comment-region

comment-region is an interactive and byte-compiled function defined in newcomment.el.gz.

Signature

(comment-region BEG END &optional ARG)

Documentation

Comment or uncomment each line in the region.

With just C-u (universal-argument) prefix arg, uncomment each line in region BEG .. END. Numeric prefix ARG means use ARG comment characters. If ARG is negative, delete that many comment characters instead.

The strings used as comment starts are built from comment-start and comment-padding; the strings used as comment ends are built from comment-end and comment-padding.

By default, the comment-start markers are inserted at the current indentation of the region, and comments are terminated on each line (even for syntaxes in which newline does not end the comment and blank lines do not get comments). This can be changed with comment-style.

View in manual

Probably introduced at or before Emacs version 19.20.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/newcomment.el.gz
;;;###autoload
(defun comment-region (beg end &optional arg)
  "Comment or uncomment each line in the region.
With just \\[universal-argument] prefix arg, uncomment each line in region BEG .. END.
Numeric prefix ARG means use ARG comment characters.
If ARG is negative, delete that many comment characters instead.

The strings used as comment starts are built from `comment-start'
and `comment-padding'; the strings used as comment ends are built
from `comment-end' and `comment-padding'.

By default, the `comment-start' markers are inserted at the
current indentation of the region, and comments are terminated on
each line (even for syntaxes in which newline does not end the
comment and blank lines do not get comments).  This can be
changed with `comment-style'."
  (interactive "*r\nP")
  (comment-normalize-vars)
  (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
  (save-excursion
    ;; FIXME: maybe we should call uncomment depending on ARG.
    (funcall comment-region-function beg end arg)))