- (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
- (save-excursion
- (goto-char beg)
- (setq end (copy-marker end))
- (let* ((numarg (prefix-numeric-value arg))
- (ccs comment-continue)
- (srei (comment-padright ccs 're))
- (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
- spt)
- (while (and (< (point) end)
- (setq spt (comment-search-forward end t)))
- (let ((ipt (point))
- ;; Find the end of the comment.
- (ept (progn
- (goto-char spt)
- (unless (comment-forward)
- (error "Can't find the comment end"))
- (point)))
- (box nil)
- (box-equal nil)) ;Whether we might be using `=' for boxes.
- (save-restriction
- (narrow-to-region spt ept)
-
- ;; Remove the comment-start.
- (goto-char ipt)
- (skip-syntax-backward " ")
- ;; A box-comment starts with a looong comment-start marker.
- (when (and (or (and (= (- (point) (point-min)) 1)
- (setq box-equal t)
- (looking-at "=\\{7\\}")
- (not (eq (char-before (point-max)) ?\n))
- (skip-chars-forward "="))
- (> (- (point) (point-min) (length comment-start)) 7))
- (> (count-lines (point-min) (point-max)) 2))
- (setq box t))
- (when (looking-at (regexp-quote comment-padding))
- (goto-char (match-end 0)))
- (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
+ (when (> beg end) (setq beg (prog1 end (setq end beg))))
+ ;; Bind `comment-use-global-state' to nil. While uncommenting a region
+ ;; (which works a line at a time), a comment can appear to be
+ ;; included in a mult-line string, but it is actually not.
+ (let ((comment-use-global-state nil))
+ (save-excursion
+ (funcall uncomment-region-function beg end arg))))
+
+(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."
+ (goto-char beg)
+ (setq end (copy-marker end))
+ (let* ((numarg (prefix-numeric-value arg))
+ (ccs comment-continue)
+ (srei (comment-padright ccs 're))
+ (csre (comment-padright comment-start 're))
+ (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
+ spt)
+ (while (and (< (point) end)
+ (setq spt (comment-search-forward end t)))
+ (let ((ipt (point))
+ ;; Find the end of the comment.
+ (ept (progn
+ (goto-char spt)
+ (unless (or (comment-forward)
+ ;; Allow non-terminated comments.
+ (eobp))
+ (error "Can't find the comment end"))
+ (point)))
+ (box nil)
+ (box-equal nil)) ;Whether we might be using `=' for boxes.
+ (save-restriction
+ (narrow-to-region spt ept)
+
+ ;; Remove the comment-start.
+ (goto-char ipt)
+ (skip-syntax-backward " ")
+ ;; A box-comment starts with a looong comment-start marker.
+ (when (and (or (and (= (- (point) (point-min)) 1)
+ (setq box-equal t)
+ (looking-at "=\\{7\\}")
+ (not (eq (char-before (point-max)) ?\n))
+ (skip-chars-forward "="))
+ (> (- (point) (point-min) (length comment-start)) 7))
+ (> (count-lines (point-min) (point-max)) 2))
+ (setq box t))
+ ;; Skip the padding. Padding can come from comment-padding and/or
+ ;; from comment-start, so we first check comment-start.
+ (if (or (save-excursion (goto-char (point-min)) (looking-at csre))
+ (looking-at (regexp-quote comment-padding)))