From 69f9caf8ff1b49543cbfc931becf15c72d3ae757 Mon Sep 17 00:00:00 2001 From: Igor Shymko Date: Sun, 14 Sep 2014 18:06:33 +0300 Subject: [PATCH] sending preview immediately after client websocket connection --- README.md | 8 +++----- markdown-preview-mode.el | 15 +++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7acde83..7638186 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,7 @@ and `websocket.el` to deliver html to browser. ## Starting preview -`M-x markdown-preview-mode` will open preview in a browser and will start `markdown-mode` if it's not yet running for current buffer. - -If you'v closed the preview window, you can start it over with -`M-x markdown-preview-open-browser`. - +`M-x markdown-preview-mode` will open preview in a browser and will start `markdown-mode` if it's not yet running for current buffer. If you'v closed the preview window, you can start it over with `M-x markdown-preview-open-browser`. All websockets will be cleaned up on emacs termination. If you'd like to perform cleanup manually run `M-x markdown-preview-cleanup`. ## Multimarkdown @@ -37,3 +33,5 @@ Select your browser from `Value menu`. If it's not there, follow [EmacsWiki: Bro ## Theme [Solarized-dark](https://github.com/thomasf/solarized-css) + +## El-get recipe included diff --git a/markdown-preview-mode.el b/markdown-preview-mode.el index 1cac2f9..1e4bca2 100644 --- a/markdown-preview-mode.el +++ b/markdown-preview-mode.el @@ -63,10 +63,11 @@ (websocket-send-text ws (websocket-frame-payload frame))) mdpm:remote-clients)) - :on-open (lambda (websocket) (push websocket mdpm:remote-clients)) + :on-open (lambda (websocket) + (push websocket mdpm:remote-clients) + (mdpm:sent-preview-to websocket)) :on-error (lambda (websocket type err) (message (concat "====> Error:" err))) - :on-close (lambda (websocket) (mdpm:drop-closed-clients)) - )) + :on-close (lambda (websocket) (mdpm:drop-closed-clients)))) (add-hook 'kill-emacs-hook 'mdpm:stop-websocket-server) (mdpm:open-browser-preview))) @@ -81,10 +82,12 @@ (setq mdpm:local-client nil)))))) (defun mdpm:send-preview () + (mdpm:sent-preview-to mdpm:local-client)) + +(defun mdpm:sent-preview-to (websocket) (markdown markdown-output-buffer-name) (with-current-buffer (get-buffer markdown-output-buffer-name) - (websocket-send-text mdpm:local-client (buffer-substring-no-properties (point-min) (point-max)))) - ) + (websocket-send-text websocket (buffer-substring-no-properties (point-min) (point-max))))) (defun mdpm:start () (mdpm:start-websocket-server) @@ -98,7 +101,7 @@ (interactive) (mdpm:open-browser-preview)) -(defun markdown-preview-kill-websocket-server () +(defun markdown-preview-cleanup () (interactive) (mdpm:stop-websocket-server))