@@ -124,8 +124,8 @@ If not provided, download and start eca automatically."
124124 'response ))
125125 'notification ))
126126
127- (defun eca--download-server ()
128- " Download eca server."
127+ (defun eca--download-server (on-downloaded )
128+ " Download eca server calling ON-DOWNLOADED when success ."
129129 (let* ((url eca-server-download-url)
130130 (store-path eca-server-install-path)
131131 (download-path (concat store-path " .zip" )))
@@ -135,21 +135,20 @@ If not provided, download and start eca automatically."
135135 (progn
136136 (when (f-exists? download-path) (f-delete download-path))
137137 (when (f-exists? store-path) (f-delete store-path))
138- (eca-info " Starting to download eca to %s..." download-path)
138+ (eca-info " Downloading eca server to %s..." download-path)
139139 (mkdir (f-parent download-path) t )
140- (url-copy-file url download-path)
140+ (let ((inhibit-message t ))
141+ (url-copy-file url download-path))
141142 (unless eca-unzip-script
142143 (error " Unable to find `unzip' or `powershell' on the path, please customize `eca-unzip-script' " ))
143144 (shell-command (format (funcall eca-unzip-script) download-path (f-parent store-path)))
144- (eca-info " Downloaded eca successfully" ))
145+ (eca-info " Downloaded eca successfully" )
146+ (funcall on-downloaded))
145147 (error " Could not download eca server " err))))))
146148
147149(defun eca--server-command ()
148- " Build the eca server command downloading server if not provided ."
150+ " Return the command to start server ."
149151 (or eca-custom-command
150- (unless (f-exists? eca-server-install-path)
151- (eca--download-server)
152- nil )
153152 (list eca-server-install-path " server" )))
154153
155154(defun eca--parse-header (s )
@@ -264,25 +263,31 @@ If not provided, download and start eca automatically."
264263 (eca--handle-message msg))
265264 (nreverse messages)))))
266265
267- (defun eca--start-process ()
268- " Start the eca process."
266+ (defun eca--start-process (on-start )
267+ " Start the eca process calling ON-START after ."
269268 (unless (process-live-p (eca--session-process eca--session))
270- (eca-info " Starting process..." )
271- (setf (eca--session-process eca--session)
272- (make-process
273- :coding 'no-conversion
274- :connection-type 'pipe
275- :name " eca"
276- :command (eca--server-command)
277- :buffer eca--process-buffer-name
278- :stderr (get-buffer-create eca--process-stderr-buffer-name)
279- :filter #'eca--process-filter
280- :sentinel (lambda (process exit-str )
281- (unless (process-live-p process)
282- (setq eca--session nil )
283- (eca-info " process has exited (%s)" (s-trim exit-str))))
284- :file-handler t
285- :noquery t ))))
269+ (let ((start-process-fn (lambda ()
270+ (eca-info " Starting process..." )
271+ (setf (eca--session-process eca--session)
272+ (make-process
273+ :coding 'no-conversion
274+ :connection-type 'pipe
275+ :name " eca"
276+ :command (eca--server-command)
277+ :buffer eca--process-buffer-name
278+ :stderr (get-buffer-create eca--process-stderr-buffer-name)
279+ :filter #'eca--process-filter
280+ :sentinel (lambda (process exit-str )
281+ (unless (process-live-p process)
282+ (setq eca--session nil )
283+ (eca-info " process has exited (%s)" (s-trim exit-str))))
284+ :file-handler t
285+ :noquery t ))
286+ (funcall on-start))))
287+ (if (f-exists? eca-server-install-path)
288+ (funcall start-process-fn)
289+ (eca--download-server (lambda ()
290+ (funcall start-process-fn)))))))
286291
287292(defun eca--initialize ()
288293 " Sent the initialize request."
@@ -324,8 +329,8 @@ If not provided, download and start eca automatically."
324329 (interactive )
325330 (unless eca--session
326331 (setq eca--session (eca-create-session)))
327- (eca--start-process)
328- (eca--initialize))
332+ (eca--start-process ( lambda ( )
333+ (eca--initialize)) ))
329334
330335;;;### autoload
331336(defun eca-stop ()
0 commit comments