Преглед изворни кода

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.
Ihor Radchenko пре 2 година
родитељ
комит
3de74bbeff
2 измењених фајлова са 21 додато и 4 уклоњено
  1. 4 4
      lisp/ox.el
  2. 17 0
      testing/lisp/test-ox.el

+ 4 - 4
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.

+ 17 - 0
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.