summaryrefslogtreecommitdiff
path: root/lisp/newcomment.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/newcomment.el')
-rw-r--r--lisp/newcomment.el40
1 files changed, 35 insertions, 5 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 335cbdd3366..ac706b949ba 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -3,7 +3,7 @@
;; Copyright (C) 1999-2019 Free Software Foundation, Inc.
;; Author: code extracted from Emacs-20's simple.el
-;; Maintainer: Stefan Monnier <monnier@iro.umontreal.ca>
+;; Maintainer: Stefan Monnier <monnier@gnu.org>
;; Keywords: comment uncomment
;; Package: emacs
@@ -159,6 +159,14 @@ The function has no args.
Applicable at least in modes for languages like fixed-format Fortran where
comments always start in column zero.")
+(defvar-local comment-combine-change-calls t
+ "If non-nil (the default), use `combine-change-calls' around
+ calls of `comment-region-function' and
+ `uncomment-region-function'. This Substitutes a single call to
+ each of the hooks `before-change-functions' and
+ `after-change-functions' in place of those hooks being called
+ for each individual buffer change.")
+
(defvar comment-region-function 'comment-region-default
"Function to comment a region.
Its args are the same as those of `comment-region', but BEG and END are
@@ -527,7 +535,7 @@ Ensure that `comment-normalize-vars' has been called before you use this."
;; comment-search-backward is only used to find the comment-column (in
;; comment-set-column) and to find the comment-start string (via
;; comment-beginning) in indent-new-comment-line, it should be harmless.
- (if (not (re-search-backward comment-start-skip limit t))
+ (if (not (re-search-backward comment-start-skip limit 'move))
(unless noerror (error "No comment"))
(beginning-of-line)
(let* ((end (match-end 0))
@@ -898,7 +906,7 @@ comment delimiters."
(save-excursion
(funcall uncomment-region-function beg end arg))))
-(defun uncomment-region-default (beg end &optional arg)
+(defun uncomment-region-default-1 (beg end &optional arg)
"Uncomment each line in the BEG .. END region.
The numeric prefix ARG can specify a number of chars to remove from the
comment delimiters.
@@ -993,9 +1001,26 @@ This function is the default value of `uncomment-region-function'."
(re-search-forward sre (line-end-position) t))
(replace-match "" t t nil (if (match-end 2) 2 1)))))
;; Go to the end for the next comment.
- (goto-char (point-max))))))
+ (goto-char (point-max)))
+ ;; Remove any obtrusive spaces left preceding a tab at `spt'.
+ (when (and (eq (char-after spt) ?\t) (eq (char-before spt) ? )
+ (> tab-width 0))
+ (save-excursion
+ (goto-char spt)
+ (let* ((fcol (current-column))
+ (slim (- (point) (mod fcol tab-width))))
+ (delete-char (- (skip-chars-backward " " slim)))))))))
(set-marker end nil))
+(defun uncomment-region-default (beg end &optional arg)
+ "Uncomment each line in the BEG .. END region.
+The numeric prefix ARG can specify a number of chars to remove from the
+comment markers."
+ (if comment-combine-change-calls
+ (combine-change-calls beg end (uncomment-region-default-1 beg end arg))
+ (uncomment-region-default-1 beg end arg)))
+
+
(defun comment-make-bol-ws (len)
"Make a white-space string of width LEN for use at BOL.
When `indent-tabs-mode' is non-nil, tab characters will be used."
@@ -1192,7 +1217,7 @@ changed with `comment-style'."
;; FIXME: maybe we should call uncomment depending on ARG.
(funcall comment-region-function beg end arg)))
-(defun comment-region-default (beg end &optional arg)
+(defun comment-region-default-1 (beg end &optional arg)
(let* ((numarg (prefix-numeric-value arg))
(style (cdr (assoc comment-style comment-styles)))
(lines (nth 2 style))
@@ -1261,6 +1286,11 @@ changed with `comment-style'."
lines
indent))))))
+(defun comment-region-default (beg end &optional arg)
+ (if comment-combine-change-calls
+ (combine-change-calls beg end (comment-region-default-1 beg end arg))
+ (comment-region-default-1 beg end arg)))
+
;;;###autoload
(defun comment-box (beg end &optional arg)
"Comment out the BEG .. END region, putting it inside a box.