1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-28 00:01:33 -08:00

Have `M-q' not mark buffers are changed when they haven't

* lisp/textmodes/fill.el (fill-paragraph): Use `buffer-hash'
to avoid marking buffers as changed when they haven't.
This commit is contained in:
Lars Magne Ingebrigtsen 2016-03-28 19:08:33 +02:00
parent 15357f6d1f
commit 742bf8243c

View file

@ -804,6 +804,9 @@ region, instead of just filling the current paragraph."
(interactive (progn
(barf-if-buffer-read-only)
(list (if current-prefix-arg 'full) t)))
(let ((hash (and (not (buffer-modified-p))
(buffer-hash))))
(prog1
(or
;; 1. Fill the region if it is active when called interactively.
(and region transient-mark-mode mark-active
@ -815,13 +818,13 @@ region, instead of just filling the current paragraph."
(and (minibufferp (current-buffer))
(= 1 (point-min))))
(let ((function (or fill-paragraph-function
;; In the minibuffer, don't count the width
;; of the prompt.
;; In the minibuffer, don't count
;; the width of the prompt.
'fill-minibuffer-function))
;; If fill-paragraph-function is set, it probably takes care
;; of comments and stuff. If not, it will have to set
;; fill-paragraph-handle-comment back to t explicitly or
;; return nil.
;; If fill-paragraph-function is set, it probably
;; takes care of comments and stuff. If not, it
;; will have to set fill-paragraph-handle-comment
;; back to t explicitly or return nil.
(fill-paragraph-handle-comment nil)
(fill-paragraph-function t))
(funcall function justify)))
@ -843,11 +846,12 @@ region, instead of just filling the current paragraph."
(concat paragraph-start "\\|[ \t]*\\(?:"
comment-start-skip "\\)")))
(save-excursion
;; To make sure the return value of forward-paragraph is meaningful,
;; we have to start from the beginning of line, otherwise skipping
;; past the last few chars of a paragraph-separator would count as
;; a paragraph (and not skipping any chars at EOB would not count
;; as a paragraph even if it is).
;; To make sure the return value of forward-paragraph is
;; meaningful, we have to start from the beginning of
;; line, otherwise skipping past the last few chars of a
;; paragraph-separator would count as a paragraph (and
;; not skipping any chars at EOB would not count as a
;; paragraph even if it is).
(move-to-left-margin)
(if (not (zerop (fill-forward-paragraph 1)))
;; There's no paragraph at or after point: give up.
@ -862,7 +866,13 @@ region, instead of just filling the current paragraph."
;; fill-region.
(fill-region beg end justify)
(fill-region-as-paragraph beg end justify))))))
fill-pfx)))
fill-pfx))
;; If we didn't change anything in the buffer (and the buffer
;; was previously unmodified), then flip the modification status
;; back to "unchanged".
(when (and hash
(equal hash (buffer-hash)))
(set-buffer-modified-p nil)))))
(declare-function comment-search-forward "newcomment" (limit &optional noerror))
(declare-function comment-string-strip "newcomment" (str beforep afterp))