sending preview immediately after client websocket connection

This commit is contained in:
Igor Shymko 2014-09-14 18:06:33 +03:00
parent 2c3dc8bbd6
commit 69f9caf8ff
2 changed files with 12 additions and 11 deletions

View File

@ -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

View File

@ -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))