summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-06-14 21:47:00 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-03 18:44:34 +0200
commit0dd29855090ae54946ff4cabb23dfc83d002fc23 (patch)
tree7055e42d5c8a92182336629e91401fb45135e3b3
parent0ff4076cb4b0f9b7e911afb8780cdc158826133c (diff)
downloadorg-mode-0dd29855090ae54946ff4cabb23dfc83d002fc23.tar.gz
`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.
-rw-r--r--lisp/org-compat.el4
-rw-r--r--lisp/org.el35
2 files changed, 25 insertions, 14 deletions
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 714ad78..a72627a 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -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
diff --git a/lisp/org.el b/lisp/org.el
index 68076e9..0bda8df 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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."