5151 :group 'markdown
5252 :link '(url-link :tag " Homepage" " https://github.com/seagle0128/grip-mode" ))
5353
54- (defcustom grip-binary-path " grip"
55- " Path to the grip binary."
56- :type 'file
57- :group 'grip )
58-
59- (defcustom grip-mdopen-path " mdopen"
60- " Path to the mdopen binary."
61- :type 'file
62- :group 'grip )
63-
64- (defcustom grip-use-mdopen nil
65- " Use mdopen instead of grip if non-nil."
66- :type 'boolean
67- :group 'grip )
68-
69- (defcustom grip-use-gogrip nil
70- " Use go-grip instead of grip if non-nil."
71- :type 'boolean
72- :group 'grip )
73-
74- (defcustom grip-gogrip-path " go-grip"
75- " Path to the go-grip binary."
76- :type 'file
54+ (defcustom grip-command 'auto
55+ " The command of grip."
56+ :type '(choice
57+ (const :tag " Automatic" auto)
58+ (const :tag " Grip" grip)
59+ (const :tag " Go-grip" go-grip)
60+ (const :tag " Mdopen" mdopen))
7761 :group 'grip )
7862
79- (defcustom grip-gogrip-theme " auto"
63+ (defcustom grip-gogrip-theme ' auto
8064 " Theme choice for go-grip."
8165 :type '(choice
82- (const :tag " Automatic" " auto" )
83- (const :tag " Dark" " dark" )
84- (const :tag " Light" " light" ))
66+ (const :tag " Automatic" auto)
67+ (const :tag " Dark" dark)
68+ (const :tag " Light" light))
8569 :group 'grip )
8670
8771(defcustom grip-preview-use-webkit t
8872 " Use embedded webkit to preview.
8973
9074This requires Emacs GUI version >= 26 and built with the `--with-xwidgets`
91- option."
75+ option. mdopen doesn't support webkit preview. "
9276 :type 'boolean
9377 :group 'grip )
9478
@@ -103,17 +87,26 @@ Use default browser if nil. It respects `grip-preview-use-webkit'."
10387 :type '(repeat (string :tag " Argument" )))
10488
10589(defcustom grip-github-api-url " "
106- " A base URL to another GitHub API."
90+ " A base URL to another GitHub API.
91+ Only available for `grip' ."
10792 :type 'string
10893 :group 'grip )
10994
11095(defcustom grip-github-user " "
111- " A GitHub username for API authentication."
96+ " A GitHub username for API authentication.
97+ Only available for `grip' ."
11298 :type 'string
11399 :group 'grip )
114100
115101(defcustom grip-github-password " "
116- " A GitHub password or auth token for API auth."
102+ " A GitHub password or auth token for API auth.
103+ Only available for `grip' ."
104+ :type 'string
105+ :group 'grip )
106+
107+ (defcustom grip-preview-host " localhost"
108+ " Preview hostname.
109+ Only available for `grip' ."
117110 :type 'string
118111 :group 'grip )
119112
@@ -124,11 +117,6 @@ When nil, only update the preview on file save."
124117 :type 'boolean
125118 :group 'grip )
126119
127- (defcustom grip-preview-host " localhost"
128- " Preview hostname."
129- :type 'string
130- :group 'grip )
131-
132120(defcustom grip-sleep-time 2
133121 " Sleep seconds to ensure the server starts successfully."
134122 :type 'integer
@@ -182,67 +170,79 @@ Use default browser unless `xwidget' is available."
182170 (file-name-nondirectory grip--preview-file))
183171 (format " http://%s :%d " grip-preview-host grip--port)))
184172
173+ (defvar grip--command nil )
185174(defun grip-start-process ()
186- " Render and preview with grip or mdopen ."
175+ " Render and preview."
187176 (unless (processp grip--process)
188- (cond (grip-use-mdopen
189- (progn
190- (unless (and grip-mdopen-path (executable-find grip-mdopen-path))
191- (grip-mode -1 ) ; Force to disable
192- (user-error " The `mdopen' is not available in PATH environment" ))
193- (when grip--preview-file
194- (setq grip--process
195- (start-process " mdopen" " *mdopen*"
196- grip-mdopen-path
197- grip--preview-file))
198- (message " Preview `%s' on %s " buffer-file-name (grip--preview-url)))))
199- (grip-use-gogrip
200- (progn
201- (unless (and grip-gogrip-path (executable-find grip-gogrip-path))
202- (grip-mode -1 ) ; Force to disable
203- (user-error " The `go-grip' is not available in PATH environment" ))
204- ; ; Generate random port
205- (while (< grip--port 6419 )
206- (setq grip--port (random 65535 )))
207- ; ; Start a new grip process
208- (when grip--preview-file
209- (setq grip--process
210- (start-process (format " grip-%d " grip--port)
211- (format " *grip-%d * " grip--port)
212- grip-gogrip-path
213- (format " --port=%d " grip--port)
214- (format " --theme=%s " grip-gogrip-theme)
215- " --browser=false"
216- grip--preview-file))
217- (message " Preview `%s' on %s " buffer-file-name (grip--preview-url))
218- (sleep-for grip-sleep-time)
219- (grip--browse-url (grip--preview-url)))))
220- (t
221- (progn
222- (unless (and grip-binary-path (executable-find grip-binary-path))
223- (grip-mode -1 ) ; Force to disable
224- (user-error " The `grip' is not available in PATH environment" ))
225- ; ; Generate random port
226- (while (< grip--port 6419 )
227- (setq grip--port (random 65535 )))
228- ; ; Start a new grip process
229- (when grip--preview-file
230- (setq grip--process
231- (start-process (format " grip-%d " grip--port)
232- (format " *grip-%d * " grip--port)
233- grip-binary-path
234- (format " --api-url=%s " grip-github-api-url)
235- (format " --user=%s " grip-github-user)
236- (format " --pass=%s " grip-github-password)
237- (format " --title=%s - Grip " (buffer-name ))
238- grip--preview-file
239- (number-to-string grip--port)))
240- (message " Preview `%s' on %s " buffer-file-name (grip--preview-url))
241- (sleep-for grip-sleep-time)
242- (grip--browse-url (grip--preview-url))))))))
177+ (setq grip--command grip-command)
178+ (when (eq grip--command 'auto )
179+ (setq grip--command
180+ (cond
181+ ((executable-find " go-grip" ) 'go-grip )
182+ ((executable-find " mdopen" ) 'mdopen )
183+ ((executable-find " grip" ) 'grip )
184+ (t (user-error " No grip comamnd is available in PATH environment" )))))
185+
186+ (pcase grip--command
187+ ('mdopen
188+ (progn
189+ (unless (executable-find " mdopen" )
190+ (grip-mode -1 ) ; Force to disable
191+ (user-error " The `mdopen' is not available in PATH environment" ))
192+ (when grip--preview-file
193+ (setq grip--process
194+ (start-process " grip" " *grip*" " mdopen" grip--preview-file))
195+ (message " Preview `%s' on %s " buffer-file-name (grip--preview-url)))))
196+ ('go-grip
197+ (progn
198+ (unless (executable-find " go-grip" )
199+ (grip-mode -1 ) ; Force to disable
200+ (user-error " The `go-grip' is not available in PATH environment" ))
201+ ; ; Generate random port
202+ (while (< grip--port 6419 )
203+ (setq grip--port (random 65535 )))
204+ ; ; Start a new grip process
205+ (when grip--preview-file
206+ (setq grip--process
207+ (start-process (format " grip-%d " grip--port)
208+ (format " *grip-%d * " grip--port)
209+ " go-grip"
210+ (format " --port=%d " grip--port)
211+ (format " --theme=%s " grip-gogrip-theme)
212+ " --browser=false"
213+ grip--preview-file))
214+ (message " Preview `%s' on %s " buffer-file-name (grip--preview-url))
215+ (grip--browse-url (format " %s /%s "
216+ (grip--preview-url)
217+ (file-name-nondirectory grip--preview-file))))))
218+ ('grip
219+ (progn
220+ (unless (executable-find " grip" )
221+ (grip-mode -1 ) ; Force to disable
222+ (user-error " The `grip' is not available in PATH environment" ))
223+ ; ; Generate random port
224+ (while (< grip--port 6419 )
225+ (setq grip--port (random 65535 )))
226+ ; ; Start a new grip process
227+ (when grip--preview-file
228+ (setq grip--process
229+ (start-process (format " grip-%d " grip--port)
230+ (format " *grip-%d * " grip--port)
231+ " grip"
232+ (format " --api-url=%s " grip-github-api-url)
233+ (format " --user=%s " grip-github-user)
234+ (format " --pass=%s " grip-github-password)
235+ (format " --title=%s - Grip " (buffer-name ))
236+ grip--preview-file
237+ (number-to-string grip--port)))
238+ (message " Preview `%s' on %s " buffer-file-name (grip--preview-url))
239+ (sleep-for grip-sleep-time)
240+ (grip--browse-url (grip--preview-url)))))
241+ (_
242+ (user-error " No grip comamnd is available in PATH environment" )))))
243243
244244(defun grip--kill-process ()
245- " Kill grip or mdopen or go-grip process."
245+ " Kill the preview process."
246246 (when grip--process
247247 ; ; Delete xwidget buffer
248248 (when (and grip-preview-use-webkit
0 commit comments