From e8e525732dcf6ed807451c3dab450ff9a583cd31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 7 Feb 2025 20:33:41 +0000 Subject: [PATCH] Eglot: fix bug in eglot--lookup-mode When lookup in eglot-server-programs fails, fall back to a half-decent (((foo-mode . "foo")) . nil) return value. This enables interactive M-x eglot for modes not yet registered in e-s-p. * lisp/progmodes/eglot.el (eglot--lookup-mode): Fallback when lookup fails. (cherry picked from commit 7169a5d5636ddede2fe70a31de098031f20f70b1) --- lisp/progmodes/eglot.el | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 2a854af18ac..9e238553216 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1320,22 +1320,28 @@ in `eglot-server-programs' (which see). CONTACT-PROXY is the value of the corresponding `eglot-server-programs' entry." (cl-loop + with lang-from-sym = (lambda (sym &optional language-id) + (cons sym + (or language-id + (or (get sym 'eglot-language-id) + (replace-regexp-in-string + "\\(?:-ts\\)?-mode$" "" + (symbol-name sym)))))) for (modes . contact) in eglot-server-programs for llists = (mapcar #'eglot--ensure-list - (if (or (symbolp modes) (keywordp (cadr modes))) - (list modes) modes)) + (if (or (symbolp modes) (keywordp (cadr modes))) + (list modes) modes)) for normalized = (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-keys) - (cons sym - (or language-id - (or (get sym 'eglot-language-id) - (replace-regexp-in-string - "\\(?:-ts\\)?-mode$" "" - (symbol-name sym)))))) + (funcall lang-from-sym sym language-id)) llists) when (cl-some (lambda (cell) (provided-mode-derived-p mode (car cell))) normalized) - return (cons normalized contact))) + return (cons normalized contact) + ;; If lookup fails at least return some suitable LANGUAGES. + finally (cl-return + (cons (list (funcall lang-from-sym major-mode)) + nil)))) (defun eglot--guess-contact (&optional interactive) "Helper for `eglot'. -- 2.39.5