branch: elpa/markdown-mode
commit 63321854d5da938fcf4867d39f77c90718dc7199
Author: Allen Li <[email protected]>
Commit: Allen Li <[email protected]>

    Do not trigger auto-insert-mode in markdown-export
    
    markdown-export calls find-file-noselect on output-file before
    generating and writing the HTML output. When output-file does not yet
    exist on disk (e.g., initial export or in markdown-live-preview-mode
    when markdown-live-preview-delete-export deletes the exported file),
    find-file-noselect runs find-file-hook on the empty html-mode buffer
    and triggers auto-insert-mode before markdown-standalone immediately
    erases and overwrites the buffer.
    
    Bind auto-insert to nil in markdown-export.
---
 markdown-mode.el       |  2 ++
 tests/markdown-test.el | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/markdown-mode.el b/markdown-mode.el
index d3b1231a4f..e4b8102e35 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -48,6 +48,7 @@
 (defvar flyspell-generic-check-word-predicate)
 (defvar electric-pair-pairs)
 (defvar sh-ancestor-alist)
+(defvar auto-insert)
 
 (declare-function project-roots "project")
 (declare-function sh-set-shell "sh-script")
@@ -7577,6 +7578,7 @@ current filename, but with the extension removed and 
replaced with .html."
     (let* ((init-buf (current-buffer))
            (init-point (point))
            (init-buf-string (buffer-string))
+           (auto-insert nil)
            (output-buffer (find-file-noselect output-file))
            (output-buffer-name (buffer-name output-buffer)))
       (run-hooks 'markdown-before-export-hook)
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 43dad3b390..6531b3c116 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -5869,6 +5869,22 @@ bar baz"
 
 ;;; Export tests:
 
+(require 'autoinsert)
+
+(ert-deftest test-markdown-export/auto-insert ()
+  "Test that `markdown-export' does not trigger `auto-insert-mode'."
+  (skip-unless (executable-find markdown-command))
+  (markdown-test-temp-file "inline.text"
+    (let* ((auto-insert-triggered nil)
+           (auto-insert t)
+           (auto-insert-query nil)
+           (auto-insert-alist `((html-mode . ,(lambda () (setq 
auto-insert-triggered t)))))
+           (find-file-hook (cons #'auto-insert find-file-hook))
+           (markdown-command #'markdown-command-identity)
+           (ofile (markdown-export)))
+      (delete-file ofile)
+      (should-not auto-insert-triggered))))
+
 (ert-deftest test-markdown-hook/xhtml-standalone ()
   "Test `markdown-xhtml-standalone-regexp' and `markdown-output-standalone-p'."
   (should (string-match markdown-xhtml-standalone-regexp

Reply via email to