Giter Site home page Giter Site logo

Comments (3)

syohex avatar syohex commented on May 18, 2024

I suppose markdown-mode can avoid this issue by calling call-process-region directly or using start-process(or start-file-process) interfaces.

Use call-process-region directly

diff --git a/markdown-mode.el b/markdown-mode.el
index bad960d..59fcdfa 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -5270,8 +5270,15 @@ Return the name of the output buffer used."
                          output-buffer-name)))
        ;; Pass region to `markdown-command' via stdin
        (t
-        (shell-command-on-region begin-region end-region markdown-command
-                                 output-buffer-name))))
+        (let ((buf (get-buffer-create output-buffer-name)))
+          (with-current-buffer buf
+            (setq buffer-read-only nil)
+            (erase-buffer))
+          (let ((ret (call-process-region begin-region end-region
+                                          shell-file-name nil buf nil
+                                          shell-command-switch markdown-command)))
+            (unless (zerop ret)
+              (error "Failed: '%s'" markdown-command)))))))
     output-buffer-name))

 (defun markdown-standalone (&optional output-buffer-name)

Using start-process

This is asynchronous execution.

diff --git a/markdown-mode.el b/markdown-mode.el
index bad960d..8573698 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -5270,8 +5270,16 @@ Return the name of the output buffer used."
                          output-buffer-name)))
        ;; Pass region to `markdown-command' via stdin
        (t
-        (shell-command-on-region begin-region end-region markdown-command
-                                 output-buffer-name))))
+        (let ((buf (get-buffer-create output-buffer-name)))
+          (with-current-buffer buf
+            (setq buffer-read-only nil)
+            (erase-buffer))
+          (let ((input (buffer-substring-no-properties begin-region end-region))
+                (proc (start-process-shell-command "markdown" buf markdown-command)))
+            (set-process-sentinel proc #'ignore)
+            (set-process-query-on-exit-flag proc nil)
+            (process-send-string proc input)
+            (process-send-eof proc))))))
     output-buffer-name))

 (defun markdown-standalone (&optional output-buffer-name)

from markdown-mode.

cruegge avatar cruegge commented on May 18, 2024

I think the synchronous version is probably better. Minor modes like markdown-preview-mode call the function and expect the result in the returned buffer for further processing, so asynchronous execution can lead to race conditions.

from markdown-mode.

jrblevin avatar jrblevin commented on May 18, 2024

Thanks for reporting this. I didn't realize this was happening. I merged #86. Thanks to @syohex for the patch. Please reopen if this does not fix the issue.

from markdown-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.