Skip to content

Commit 3de74bb

Browse files
committed
fixup! org-export-copy-buffer: Prevent saving to disk
* lisp/ox.el (org-export--generate-copy-script): Set `write-contents-functions' after running `major-mode'. * testing/lisp/test-ox.el (test-org-export/org-export-copy-buffer): Add test.
1 parent 1a62cd9 commit 3de74bb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lisp/ox.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,9 +2655,6 @@ The function assumes BUFFER's major mode is `org-mode'."
26552655
ov-set))))
26562656
(lambda ()
26572657
(let ((inhibit-modification-hooks t))
2658-
;; Never write the buffer copy to disk, despite
2659-
;; `buffer-file-name' not being nil.
2660-
(set 'write-contents-functions (list #'always))
26612658
;; Set major mode. Ignore `org-mode-hook' and other hooks as
26622659
;; they have been run already in BUFFER.
26632660
(unless (eq major-mode 'org-mode)
@@ -2679,7 +2676,10 @@ The function assumes BUFFER's major mode is `org-mode'."
26792676
(goto-char pos)
26802677
;; Overlays with invisible property.
26812678
(pcase-dolist (`(,start ,end ,invis) ols)
2682-
(overlay-put (make-overlay start end) 'invisible invis)))))))
2679+
(overlay-put (make-overlay start end) 'invisible invis))
2680+
;; Never write the buffer copy to disk, despite
2681+
;; `buffer-file-name' not being nil.
2682+
(setq write-contents-functions (list #'always)))))))
26832683

26842684
(defun org-export--delete-comment-trees ()
26852685
"Delete commented trees and commented inlinetasks in the buffer.

testing/lisp/test-ox.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ variable, and communication channel under `info'."
6161

6262
;;; Internal Tests
6363

64+
(ert-deftest test-org-export/org-export-copy-buffer ()
65+
"Test `org-export-copy-buffer' specifications."
66+
;; The buffer copy must not cause overwriting the original file
67+
;; buffer under any circumstances.
68+
(org-test-with-temp-text-in-file
69+
"* Heading"
70+
(let ((file (buffer-file-name)))
71+
(with-current-buffer (org-export-copy-buffer)
72+
(insert "This must not go into actual file.")
73+
(save-buffer)
74+
(should
75+
(equal
76+
"* Heading"
77+
(with-temp-buffer
78+
(insert-file-contents file)
79+
(buffer-string))))))))
80+
6481
(ert-deftest test-org-export/bind-keyword ()
6582
"Test reading #+BIND: keywords."
6683
;; Test with `org-export-allow-bind-keywords' set to t.

0 commit comments

Comments
 (0)