Skip to content

Commit

Permalink
Merge pull request #35 from juergenhoetzel/fix-emacs-26-network-serve…
Browse files Browse the repository at this point in the history
…r-process

Add workaround for Emacs 26 async network-server-process issues
  • Loading branch information
ancane authored Sep 29, 2018
2 parents 4ec1518 + 363692d commit 180350d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion markdown-preview-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,21 @@ rendered copy to PREVIEW-FILE, ready to be open in browser."
(replace-match (format "%s" preview-uuid) t))
(buffer-string)))

;; Emacs 26 async network workaround
(defun markdown-preview--fix-network-process-wait (plist)
"Ensure PLIST contains :nowait nil."
(if (and (>= emacs-major-version 26)
(equal (plist-get plist :name) "ws-server")
(plist-get plist :server)
(plist-get plist :nowait))
(plist-put plist :nowait nil)
plist))

(defun markdown-preview--start-http-server (port)
"Start http server at PORT to serve preview file via http."
(unless markdown-preview--http-server
(lexical-let ((docroot default-directory))
(advice-add 'make-network-process :filter-args #'markdown-preview--fix-network-process-wait)
(setq markdown-preview--http-server
(ws-start
(lambda (request)
Expand All @@ -186,7 +197,8 @@ rendered copy to PREVIEW-FILE, ready to be open in browser."
(ws-send-file process filename)
(ws-send-404 process)
))))))
markdown-preview-http-port nil :host markdown-preview-http-host)))))
markdown-preview-http-port nil :host markdown-preview-http-host))
(advice-remove 'make-network-process #'my-filter))))

(defun markdown-preview--parse-uuid (headers)
"Find uuid query param in HEADERS."
Expand Down

0 comments on commit 180350d

Please sign in to comment.