Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated markdown in message buffer #83

Closed
cruegge opened this issue Feb 1, 2016 · 3 comments
Closed

Generated markdown in message buffer #83

cruegge opened this issue Feb 1, 2016 · 3 comments

Comments

@cruegge
Copy link

cruegge commented Feb 1, 2016

The markdown function uses shell-command-on-region, which in addition to writing to the destination buffer, apparently also prints the output to the echo area and the *Messages* buffer. Maybe call-process-region or something similar should be used instead.

@syohex
Copy link
Collaborator

syohex commented Feb 1, 2016

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)

@cruegge
Copy link
Author

cruegge commented Feb 1, 2016

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.

@jrblevin
Copy link
Owner

jrblevin commented Feb 8, 2016

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.

@jrblevin jrblevin closed this as completed Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants