* 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.
@@ -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
@@ -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