Function: eca-process-start

eca-process-start is a natively compiled function defined in eca-process.el.

Signature

(eca-process-start SESSION ON-START HANDLE-MSG)

Documentation

Start the eca process for SESSION calling ON-START after.

Call HANDLE-MSG for new msgs processed.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-process.el
;; Public

(defun eca-process-start (session on-start handle-msg)
  "Start the eca process for SESSION calling ON-START after.
Call HANDLE-MSG for new msgs processed."
  (unless (process-live-p (eca--session-process session))
    ;; Clean up any .old binary from previous updates
    (eca-process--cleanup-old-server)
    (-let* (((result &as &plist :decision decision :command command) (eca-process--server-command))
            (start-process-fn (lambda ()
                                (let ((command (append command eca-extra-args)))
                                  (when eca-process-wrapper-function
                                    (setq command
                                          (funcall eca-process-wrapper-function
                                                   command
                                                   (eca--session-workspace-folders session))))
                                  (eca-info "Starting process '%s'" (string-join command " "))
                                  (setf (eca--session-process session)
                                        (make-process
                                         :coding 'no-conversion
                                         :connection-type 'pipe
                                         :name "eca"
                                         :command command
                                         :buffer (eca-process--buffer-name session)
                                         :stderr (get-buffer-create (eca-process--stderr-buffer-name session))
                                         :filter (eca-process--make-filter handle-msg)
                                         :sentinel (lambda (process exit-str)
                                                     (unless (process-live-p process)
                                                       (when-let* ((name (eca-process--stderr-buffer-name session))
                                                                   (buf (get-buffer name)))
                                                         (with-current-buffer buf
                                                           (rename-buffer (concat (buffer-name) ":closed") t)
                                                           (setq-local mode-line-format '("*Closed session*"))))
                                                       (eca-delete-session session)
                                                       (eca-info "process has exited (%s)" (s-trim exit-str))))
                                         :file-handler t
                                         :noquery t)))
                                (funcall on-start))))
      (pcase decision
        ('custom (funcall start-process-fn))

        ('system (funcall start-process-fn))

        ('error-download (user-error (eca-error (plist-get result :message))))

        ('already-installed (funcall start-process-fn))

        ('download (eca-process--download-server
                    (lambda () (funcall start-process-fn))
                    (plist-get result :latest-version)
                    ;; When updating an already installed server, a
                    ;; failed download (e.g. GitHub outage) falls back
                    ;; to starting the installed binary.
                    (when (f-exists? eca-server-install-path)
                      (lambda (err)
                        (eca-warn "Failed to download eca server (%s), starting installed version instead" err)
                        (funcall start-process-fn)))))))))