瀏覽代碼

src: Do not undo edit buffers back to empty state

* lisp/org-src.el (org-src--edit-element): Clear undo information once
the initial contents have been inserted.
* testing/lisp/test-org-src.el (test-org-src/undo): New test.
Nicolas Goaziou 4 年之前
父節點
當前提交
b0bbe512b4
共有 2 個文件被更改,包括 15 次插入0 次删除
  1. 4 0
      lisp/org-src.el
  2. 11 0
      testing/lisp/test-org-src.el

+ 4 - 0
lisp/org-src.el

@@ -558,6 +558,10 @@ Leave point in edit buffer."
 	(setq org-src-source-file-name source-file-name)
 	;; Start minor mode.
 	(org-src-mode)
+	;; Clear undo information so we cannot undo back to the
+	;; initial empty buffer.
+	(buffer-disable-undo (current-buffer))
+	(buffer-enable-undo)
 	;; Move mark and point in edit buffer to the corresponding
 	;; location.
 	(if remote

+ 11 - 0
testing/lisp/test-org-src.el

@@ -58,6 +58,17 @@
     (goto-char (point-max))
     (should-error (org-edit-special))))
 
+(ert-deftest test-org-src/undo ()
+  "Undo-ing an edit buffer should not go back to empty state."
+  (org-test-with-temp-text "
+#+begin_src emacs-lisp<point>
+  (message hello)
+#+end_src
+"
+    (org-edit-special)
+    (should-error (undo))
+    (org-edit-src-exit)))
+
 (ert-deftest test-org-src/empty-block ()
   "Editing empty block."
   (org-test-with-temp-text