-;;; newcomment.el --- (un)comment regions of buffers
+;;; newcomment.el --- (un)comment regions of buffers -*- lexical-binding: t -*-
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
;; Author: code extracted from Emacs-20's simple.el
;; Maintainer: Stefan Monnier <monnier@iro.umontreal.ca>
;;;###autoload
(defvar comment-start nil
- "*String to insert to start a new comment, or nil if no comment syntax.")
+ "String to insert to start a new comment, or nil if no comment syntax.")
;;;###autoload(put 'comment-start 'safe-local-variable 'string-or-null-p)
;;;###autoload
(defvar comment-start-skip nil
- "*Regexp to match the start of a comment plus everything up to its body.
+ "Regexp to match the start of a comment plus everything up to its body.
If there are any \\(...\\) pairs, the comment delimiter text is held to begin
at the place matched by the close of the first pair.")
;;;###autoload(put 'comment-start-skip 'safe-local-variable 'string-or-null-p)
;;;###autoload
(defvar comment-end-skip nil
- "Regexp to match the end of a comment plus everything up to its body.")
+ "Regexp to match the end of a comment plus everything back to its body.")
;;;###autoload(put 'comment-end-skip 'safe-local-variable 'string-or-null-p)
;;;###autoload
(defvar comment-end (purecopy "")
- "*String to insert to end a new comment.
+ "String to insert to end a new comment.
Should be an empty string if comments are terminated by end-of-line.")
;;;###autoload(put 'comment-end 'safe-local-variable 'string-or-null-p)
This should generally stay 0, except for a few modes like Lisp where
it is 1 so that regions are commented with two or three semi-colons.")
+;;;###autoload
(defconst comment-styles
'((plain nil nil nil nil
"Start in column 0 (do not indent), as in Emacs-20")
/* bli */
if `comment-end' is empty, this has no effect, unless EXTRA is also set,
in which case the comment gets wrapped in a box.
-
+
EXTRA specifies that an extra line should be used before and after the
region to comment (to put the `comment-end' and `comment-start').
e.g. in C it comments regions as
(let ((cs (read-string "No comment syntax is defined. Use: ")))
(if (zerop (length cs))
(error "No comment syntax defined")
- (set (make-local-variable 'comment-start) cs))))
+ (set (make-local-variable 'comment-start) cs)
+ (set (make-local-variable 'comment-start-skip) cs))))
;; comment-use-syntax
(when (eq comment-use-syntax 'undecided)
(set (make-local-variable 'comment-use-syntax)
(save-excursion (end-of-line) (current-column)))))
(other nil)
(min (save-excursion (skip-chars-backward " \t")
- (1+ (current-column)))))
+ (if (bolp) 0 (1+ (current-column))))))
;; Fix up the range.
(if (< max min) (setq max min))
;; Don't move past the fill column.
With prefix ARG, kill comments on that many lines starting with this one."
(interactive "P")
(comment-normalize-vars)
- (dotimes (_ (prefix-numeric-value arg))
+ (dotimes (_i (prefix-numeric-value arg))
(save-excursion
(beginning-of-line)
(let ((cs (comment-search-forward (line-end-position) t)))
(when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
(goto-char (match-end 0)))
(if (null arg) (delete-region (point-min) (point))
- (skip-syntax-backward " ")
- (delete-char (- numarg))
- (unless (or (bobp)
- (save-excursion (goto-char (point-min))
- (looking-at comment-start-skip)))
- ;; If there's something left but it doesn't look like
- ;; a comment-start any more, just remove it.
- (delete-region (point-min) (point))))
+ (let ((opoint (point-marker)))
+ (skip-syntax-backward " ")
+ (delete-char (- numarg))
+ (unless (and (not (bobp))
+ (save-excursion (goto-char (point-min))
+ (looking-at comment-start-skip)))
+ ;; If there's something left but it doesn't look like
+ ;; a comment-start any more, just remove it.
+ (delete-region (point-min) opoint))))
;; Remove the end-comment (and leading padding and such).
(goto-char (point-max)) (comment-enter-backward)
(setq ,bindent (- ,bindent n)))))))))))
(defun comment-add (arg)
- "Compute the number of extra comment starter characters
-\(extra semicolons in Lisp mode, extra stars in C mode, etc.)
+ "Compute the number of extra comment starter characters.
+\(Extra semicolons in Lisp mode, extra stars in C mode, etc.)
If ARG is non-nil, just follow ARG.
If the comment starter is multi-char, just follow ARG.
Otherwise obey `comment-add'."
'box-multi 'box)))
(comment-region beg end (+ comment-add arg))))
+(defun comment-only-p (beg end)
+ "Return non-nil if the text between BEG and END is all comments."
+ (save-excursion
+ (goto-char beg)
+ (comment-forward (point-max))
+ (<= end (point))))
;;;###autoload
(defun comment-or-uncomment-region (beg end &optional arg)
is passed on to the respective function."
(interactive "*r\nP")
(comment-normalize-vars)
- (funcall (if (save-excursion ;; check for already commented region
- (goto-char beg)
- (comment-forward (point-max))
- (<= end (point)))
+ (funcall (if (comment-only-p beg end)
'uncomment-region 'comment-region)
beg end arg))
:group 'comment)
(defun comment-valid-prefix-p (prefix compos)
- "Check that the adaptive-fill-prefix is consistent with the context.
+ "Check that the adaptive fill prefix is consistent with the context.
PREFIX is the prefix (presumably guessed by `adaptive-fill-mode').
COMPOS is the position of the beginning of the comment we're in, or nil
if we're not inside a comment."
(provide 'newcomment)
-;; arch-tag: 01e3320a-00c8-44ea-a696-8f8e7354c858
;;; newcomment.el ends here