`org-fill-paragraph' leaves buffer unmodified when doing nothing

* lisp/org.el (org-fill-paragraph): Leave buffer unmodified when
  nothing was filled.
* lisp/org-compat.el: Add forward compatibility with `buffer-hash'
  function.
This commit is contained in:
Nicolas Goaziou 2018-06-14 21:47:00 +02:00
parent 0ff4076cb4
commit 0dd2985509
2 changed files with 25 additions and 14 deletions

View File

@ -81,6 +81,10 @@
(defalias 'org-line-number-display-width 'line-number-display-width)
(defun org-line-number-display-width (&rest _) 0))
(if (fboundp 'buffer-hash)
(defalias 'org-buffer-hash 'buffer-hash)
(defun org-buffer-hash () (md5 (current-buffer))))
;;; Emacs < 25.1 compatibility

View File

@ -22154,20 +22154,27 @@ filling the current element."
(interactive (progn
(barf-if-buffer-read-only)
(list (when current-prefix-arg 'full) t)))
(cond
((and region transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(let ((origin (point-marker))
(start (region-beginning)))
(unwind-protect
(progn
(goto-char (region-end))
(while (> (point) start)
(org-backward-paragraph)
(org-fill-element justify)))
(goto-char origin)
(set-marker origin nil))))
(t (org-fill-element justify))))
(let ((hash (and (not (buffer-modified-p))
(org-buffer-hash))))
(cond
((and region transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(let ((origin (point-marker))
(start (region-beginning)))
(unwind-protect
(progn
(goto-char (region-end))
(while (> (point) start)
(org-backward-paragraph)
(org-fill-element justify)))
(goto-char origin)
(set-marker origin nil))))
(t (org-fill-element justify)))
;; 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 (org-buffer-hash)))
(set-buffer-modified-p nil))))
(defun org-auto-fill-function ()
"Auto-fill function."