From: João Távora Date: Mon, 16 Jan 2023 11:48:09 +0000 (+0000) Subject: Fix M-x eglot prompt when connection already exists (bug#60557) X-Git-Tag: emacs-29.0.90~710 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=67df34c143d;p=emacs.git Fix M-x eglot prompt when connection already exists (bug#60557) Before this change, if a current connection existed at the time of M-x eglot, user would be first asked to enter into M-x eglot's interactive spec details about new command line arguments, and only afterwards be prompted about what to do with the current connection (which could be to reconnect to it using the same arguments, or tear it down and make a new one). This is very confusing, as users may not be fully aware of the distinction between "reconnect" vs "disconnect-and-connect". They might not know if any new command line arguments provided are taking effect or not. This change simplifies this and removes the option to "reconnect instead" from M-x eglot (users can do that at any time via M-x eglot-reconnect). It also ensures that users are informed about a current connection before asking to enter new command line arguments and not the other way round. * lisp/progmodes/eglot.el (eglot): Rework. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 0082a171303..445d6ee9b5e 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1113,16 +1113,16 @@ LANGUAGE-ID is the language ID string to send to the server for MANAGED-MAJOR-MODE, which matters to a minority of servers. INTERACTIVE is t if called interactively." - (interactive (append (eglot--guess-contact t) '(t))) - (setq managed-major-mode (eglot--ensure-list managed-major-mode)) - (let* ((current-server (eglot-current-server)) - (live-p (and current-server (jsonrpc-running-p current-server)))) - (if (and live-p - interactive - (y-or-n-p "[eglot] Live process found, reconnect instead? ")) - (eglot-reconnect current-server interactive) - (when live-p (ignore-errors (eglot-shutdown current-server))) - (eglot--connect managed-major-mode project class contact language-id)))) + (interactive + (let ((current-server (eglot-current-server))) + (unless (or (null current-server) + (y-or-n-p "\ +[eglot] Shut down current connection before attempting new one?")) + (user-error "[eglot] Connection attempt aborted by user.")) + (prog1 (append (eglot--guess-contact t) '(t)) + (when current-server (ignore-errors (eglot-shutdown current-server)))))) + (eglot--connect (eglot--ensure-list managed-major-mode) + project class contact language-id)) (defun eglot-reconnect (server &optional interactive) "Reconnect to SERVER.