-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlivedown.el
75 lines (58 loc) · 2.06 KB
/
livedown.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;; livedown.el --- Realtime Markdown previews for Emacs.
;; Copyright (C) 2014-2016 Hrvoje Simic
;; Author: Hrvoje Simic <[email protected]>
;; Version: 1.0.0
;; Keywords: markdown, preview, live
;; URL: https://github.com/shime/emacs-livedown
;;; Commentary:
;; Realtime Markdown previews for Emacs.
;;; Code:
(defgroup livedown nil
"Realtime Markdown previews"
:group 'livedown
:prefix "livedown-")
(defcustom livedown-port 1337
"Port on which livedown server will run."
:type 'integer
:group 'livedown)
(defcustom livedown-open t
"Open browser automatically."
:type 'boolean
:group 'livedown)
(defcustom livedown-browser nil
"Open alternative browser."
:type 'string
:group 'livedown)
(defcustom livedown-autostart nil
"Auto-open previews when opening markdown files."
:type 'boolean
:group 'livedown)
;;;###autoload
(defun livedown-preview ()
"Preview the current file in livedown."
(interactive)
(call-process-shell-command
(format "livedown stop --port %s &"
livedown-port))
(start-process-shell-command
(format "emacs-livedown")
(format "emacs-livedown-buffer")
(format "livedown start %s --port %s %s %s "
buffer-file-name
livedown-port
(if livedown-browser (concat "--browser " livedown-browser) "")
(if livedown-open "--open" "")))
(print (format "%s rendered @ %s" buffer-file-name livedown-port) (get-buffer "emacs-livedown-buffer")))
;;;###autoload
(defun livedown-kill (&optional async)
"Stops the livedown process."
(interactive)
(let ((stop-livedown (if async 'async-shell-command 'call-process-shell-command)))
(funcall stop-livedown
(format "livedown stop --port %s &"
livedown-port))))
(if livedown-autostart
(eval-after-load 'markdown-mode '(livedown-preview)))
(add-hook 'kill-emacs-query-functions (lambda () (livedown-kill t)))
(provide 'livedown)
;;; livedown.el ends here