diff --git a/lisp/ox.el b/lisp/ox.el index 5142700c1..81be2b39c 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -2655,9 +2655,6 @@ The function assumes BUFFER's major mode is `org-mode'." ov-set)))) (lambda () (let ((inhibit-modification-hooks t)) - ;; Never write the buffer copy to disk, despite - ;; `buffer-file-name' not being nil. - (set 'write-contents-functions (list #'always)) ;; Set major mode. Ignore `org-mode-hook' and other hooks as ;; they have been run already in BUFFER. (unless (eq major-mode 'org-mode) @@ -2679,7 +2676,10 @@ The function assumes BUFFER's major mode is `org-mode'." (goto-char pos) ;; Overlays with invisible property. (pcase-dolist (`(,start ,end ,invis) ols) - (overlay-put (make-overlay start end) 'invisible invis))))))) + (overlay-put (make-overlay start end) 'invisible invis)) + ;; Never write the buffer copy to disk, despite + ;; `buffer-file-name' not being nil. + (setq write-contents-functions (list #'always))))))) (defun org-export--delete-comment-trees () "Delete commented trees and commented inlinetasks in the buffer. diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 573dbc6a5..90a9eb3aa 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -61,6 +61,23 @@ variable, and communication channel under `info'." ;;; Internal Tests +(ert-deftest test-org-export/org-export-copy-buffer () + "Test `org-export-copy-buffer' specifications." + ;; The buffer copy must not cause overwriting the original file + ;; buffer under any circumstances. + (org-test-with-temp-text-in-file + "* Heading" + (let ((file (buffer-file-name))) + (with-current-buffer (org-export-copy-buffer) + (insert "This must not go into actual file.") + (save-buffer) + (should + (equal + "* Heading" + (with-temp-buffer + (insert-file-contents file) + (buffer-string)))))))) + (ert-deftest test-org-export/bind-keyword () "Test reading #+BIND: keywords." ;; Test with `org-export-allow-bind-keywords' set to t.