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.
This commit is contained in:
Ihor Radchenko 2022-10-07 17:46:15 +08:00
parent 1a62cd94cf
commit 3de74bbeff
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 21 additions and 4 deletions

View File

@ -2655,9 +2655,6 @@ The function assumes BUFFER's major mode is `org-mode'."
ov-set)))) ov-set))))
(lambda () (lambda ()
(let ((inhibit-modification-hooks t)) (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 ;; Set major mode. Ignore `org-mode-hook' and other hooks as
;; they have been run already in BUFFER. ;; they have been run already in BUFFER.
(unless (eq major-mode 'org-mode) (unless (eq major-mode 'org-mode)
@ -2679,7 +2676,10 @@ The function assumes BUFFER's major mode is `org-mode'."
(goto-char pos) (goto-char pos)
;; Overlays with invisible property. ;; Overlays with invisible property.
(pcase-dolist (`(,start ,end ,invis) ols) (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 () (defun org-export--delete-comment-trees ()
"Delete commented trees and commented inlinetasks in the buffer. "Delete commented trees and commented inlinetasks in the buffer.

View File

@ -61,6 +61,23 @@ variable, and communication channel under `info'."
;;; Internal Tests ;;; 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 () (ert-deftest test-org-export/bind-keyword ()
"Test reading #+BIND: keywords." "Test reading #+BIND: keywords."
;; Test with `org-export-allow-bind-keywords' set to t. ;; Test with `org-export-allow-bind-keywords' set to t.