- (if (null arg) (delete-region (point-min) (point))
- (skip-syntax-backward " ")
- (delete-char (- numarg)))
-
- ;; Remove the end-comment (and leading padding and such).
- (goto-char (point-max)) (comment-enter-backward)
- ;; Check for special `=' used sometimes in comment-box.
- (when (and box-equal (not (eq (char-before (point-max)) ?\n)))
- (let ((pos (point)))
- ;; skip `=' but only if there are at least 7.
- (when (> (skip-chars-backward "=") -7) (goto-char pos))))
- (unless (looking-at "\\(\n\\|\\s-\\)*\\'")
- (when (and (bolp) (not (bobp))) (backward-char))
- (if (null arg) (delete-region (point) (point-max))
- (skip-syntax-forward " ")
- (delete-char numarg)))
-
- ;; Unquote any nested end-comment.
- (comment-quote-nested comment-start comment-end t)
-
- ;; Eliminate continuation markers as well.
- (when sre
- (let* ((cce (comment-string-reverse (or comment-continue
- comment-start)))
- (erei (and box (comment-padleft cce 're)))
- (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
- (goto-char (point-min))
- (while (progn
- (if (and ere (re-search-forward
- ere (line-end-position) t))
- (replace-match "" t t nil (if (match-end 2) 2 1))
- (setq ere nil))
- (forward-line 1)
- (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)))))
- (set-marker end nil))))
+ (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))))
+
+ ;; Remove the end-comment (and leading padding and such).
+ (goto-char (point-max)) (comment-enter-backward)
+ ;; Check for special `=' used sometimes in comment-box.
+ (when (and box-equal (not (eq (char-before (point-max)) ?\n)))
+ (let ((pos (point)))
+ ;; skip `=' but only if there are at least 7.
+ (when (> (skip-chars-backward "=") -7) (goto-char pos))))
+ (unless (looking-at "\\(\n\\|\\s-\\)*\\'")
+ (when (and (bolp) (not (bobp))) (backward-char))
+ (if (null arg) (delete-region (point) (point-max))
+ (skip-syntax-forward " ")
+ (delete-char numarg)
+ (unless (or (eobp) (looking-at comment-end-skip))
+ ;; If there's something left but it doesn't look like
+ ;; a comment-end any more, just remove it.
+ (delete-region (point) (point-max)))))
+
+ ;; Unquote any nested end-comment.
+ (comment-quote-nested comment-start comment-end t)
+
+ ;; Eliminate continuation markers as well.
+ (when sre
+ (let* ((cce (comment-string-reverse (or comment-continue
+ comment-start)))
+ (erei (and box (comment-padleft cce 're)))
+ (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
+ (goto-char (point-min))
+ (while (progn
+ (if (and ere (re-search-forward
+ ere (line-end-position) t))
+ (replace-match "" t t nil (if (match-end 2) 2 1))
+ (setq ere nil))
+ (forward-line 1)
+ (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))))))
+ (set-marker end nil))