Skip to content

Commit 7d4981a

Browse files
author
Danny McClanahan
committed
instrument async export
1 parent 2e35f64 commit 7d4981a

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

markdown-mode.el

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5994,9 +5994,6 @@ alive."
59945994
(markdown-live-preview-create-display out-file src-buf)
59955995
(markdown-live-preview-async-cleanup-export src-buf msg)))
59965996

5997-
(defmacro markdown-silence-messages (&rest body)
5998-
`(cl-letf (((symbol-function #'message) (lambda (&rest _)))) ,@body))
5999-
60005997
(defun markdown-live-preview-do-sentinel (src-buf out-file proc)
60015998
(unless (or (process-live-p proc)
60025999
(not (buffer-live-p src-buf)))
@@ -6007,44 +6004,53 @@ alive."
60076004
src-buf out-file cur-msg))))
60086005

60096006
(defun markdown-live-preview-make-async-sentinel (src-buf out-file)
6010-
(lambda (proc _)
6011-
(markdown-live-preview-do-sentinel src-buf out-file proc)))
6007+
(lambda (proc _) (markdown-live-preview-do-sentinel src-buf out-file proc)))
60126008

60136009
(defconst markdown-live-preview-proc-name "*markdown-live-preview*")
60146010
(defconst markdown-live-preview-buf-name "*markdown-live-preview-output*")
60156011

60166012
(defun markdown-live-preview-async-export ()
60176013
(interactive)
6014+
(message "start-export")
60186015
(unless markdown-live-preview-currently-exporting-process
6019-
(markdown-silence-messages
6020-
(let* ((cur-buf (current-buffer))
6021-
(mode major-mode)
6022-
(out-file (markdown-live-preview-get-filename))
6023-
(sentinel (markdown-live-preview-make-async-sentinel
6024-
cur-buf out-file))
6025-
(proc
6026-
(start-process-shell-command
6027-
markdown-live-preview-proc-name markdown-live-preview-buf-name
6028-
;; using redirection means emacs doesn't have to process output,
6029-
;; which interrupts the user less
6030-
(concat
6031-
markdown-command
6032-
(and markdown-command-needs-filename
6033-
(if (buffer-file-name) (buffer-file-name)
6034-
(user-error "Must be visiting a file")))
6035-
" > " (shell-quote-argument out-file)))))
6036-
(setq markdown-live-preview-currently-exporting-process proc)
6037-
(set-process-sentinel proc sentinel)
6038-
(with-temp-buffer
6039-
(let ((tmp-buf (current-buffer)))
6040-
(with-current-buffer cur-buf
6041-
(copy-to-buffer tmp-buf (point-min) (point-max))))
6042-
(funcall mode)
6043-
(run-hooks 'markdown-before-export-hook)
6044-
(process-send-region proc (point-min) (point-max))
6045-
(process-send-eof proc)
6046-
(run-hooks 'markdown-after-export-hook)
6047-
proc)))))
6016+
(let* ((cur-buf (current-buffer))
6017+
(mode major-mode)
6018+
(out-file (markdown-live-preview-get-filename))
6019+
(sentinel (markdown-live-preview-make-async-sentinel
6020+
cur-buf out-file))
6021+
(proc
6022+
(start-process-shell-command
6023+
markdown-live-preview-proc-name markdown-live-preview-buf-name
6024+
;; using redirection means emacs doesn't have to process output,
6025+
;; which interrupts the user less
6026+
(concat
6027+
markdown-command " "
6028+
(and markdown-command-needs-filename
6029+
(if (buffer-file-name)
6030+
(shell-quote-argument (buffer-file-name))
6031+
(user-error "Must be visiting a file")))
6032+
" > " (shell-quote-argument out-file)))))
6033+
(message "start-export2")
6034+
(setq markdown-live-preview-currently-exporting-process proc)
6035+
(set-process-sentinel proc sentinel)
6036+
(message "start-export3")
6037+
(with-temp-buffer
6038+
(message "start-export4")
6039+
(let ((tmp-buf (current-buffer)))
6040+
(with-current-buffer cur-buf
6041+
(copy-to-buffer tmp-buf (point-min) (point-max))))
6042+
(message "start-export5")
6043+
(funcall mode)
6044+
(message "start-export6")
6045+
(run-hooks 'markdown-before-export-hook)
6046+
(message "start-export7")
6047+
(process-send-region proc (point-min) (point-max))
6048+
(message "start-export8")
6049+
(process-send-eof proc)
6050+
(message "start-export9")
6051+
(run-hooks 'markdown-after-export-hook)
6052+
(message "start-export10")
6053+
proc))))
60486054

60496055
(defvar markdown-live-preview-currently-exporting nil)
60506056

tests/markdown-test.el

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3868,37 +3868,27 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
38683868
(cl-loop for win in windows
38693869
unless (eq win (selected-window))
38703870
do (delete-window win))
3871-
(message "start")
38723871
;; note that advices are used in this test to supply `should' conditions
38733872
(markdown-temp-eww
3874-
(message "start2")
38753873
;; test that first window created by
38763874
;; `markdown-live-preview-get-displaying-window' is the same window
38773875
;; that is used to finally render the buffer, on the first try
38783876
(markdown-eww-open-file-advice
3879-
(message "start3")
38803877
(markdown-initial-window-create-advice
3881-
(message "start4")
38823878
(if markdown-live-preview-do-sync
38833879
(markdown-live-preview-sync-export)
38843880
(markdown-live-preview-async-export)
3885-
(message "start5")
38863881
(markdown-test/live-preview-wait))
3887-
(message "start6")
38883882
(should (eq t markdown-test-hit-advice))
3889-
(message "start7")
38903883
(setq markdown-test-hit-advice nil))
38913884
(setq markdown-test-eww-window
38923885
(get-buffer-window (get-buffer "*eww*")))
38933886
(should markdown-live-preview-view-buffer)
38943887
(with-selected-window (get-buffer-window md-buf)
3895-
(message "start8")
38963888
(if markdown-live-preview-do-sync
38973889
(markdown-live-preview-sync-export)
38983890
(markdown-live-preview-async-export)
3899-
(message "start9")
39003891
(markdown-test/live-preview-wait))
3901-
(message "start10")
39023892
;; at this point, `eww-render' should have finished, and eww should
39033893
;; have redisplayed. the advice checks that, since there was a
39043894
;; single window displaying the *eww* buffer, that window was used

0 commit comments

Comments
 (0)