From 08716b9a0aeea0f59e926dc7665a963d698c4e0d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 6 Jan 2025 10:47:13 +0000 Subject: [PATCH] Eglot: new eglot--format to fix quote substitution woes (bug#73472) * lisp/progmodes/eglot.el (eglot--guess-contact): Use eglot--format. (eglot--format): New helper. (eglot--error, eglot--message, eglot--warn) (eglot--apply-text-edits, eglot-rename): Use eglot--format. (cherry picked from commit c3ec174a6c2d1118e82aecceb203634f7b567e20) --- lisp/progmodes/eglot.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 48ad8e024dd..7313f2876d2 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1323,16 +1323,19 @@ be guessed." (and base-prompt (cond (current-prefix-arg base-prompt) ((null guess) - (format "[eglot] Couldn't guess LSP server for `%s'\n%s" - main-mode base-prompt)) + (eglot--format + "[eglot] Couldn't guess LSP server for `%s'\n%s" + main-mode base-prompt)) ((and program (not (file-name-absolute-p program)) (not (compat-call executable-find program t))) (if full-program-invocation - (concat (format "[eglot] I guess you want to run `%s'" - full-program-invocation) - (format ", but I can't find `%s' in PATH!" - program) + (concat (eglot--format + "[eglot] I guess you want to run `%s'" + full-program-invocation) + (eglot--format + ", but I can't find `%s' in PATH!" + program) "\n" base-prompt) (eglot--error (concat "`%s' not found in PATH, but can't form" @@ -1701,19 +1704,23 @@ in project `%s'." ;;; Helpers (move these to API?) ;;; +(defun eglot--format (format &rest args) + "Like `format`, but substitutes quotes." + (apply #'format (substitute-quotes format) args)) + (defun eglot--error (format &rest args) "Error out with FORMAT with ARGS." - (error "[eglot] %s" (apply #'format format args))) + (error "[eglot] %s" (apply #'eglot--format format args))) (defun eglot--message (format &rest args) "Message out with FORMAT with ARGS." - (message "[eglot] %s" (apply #'format format args))) + (message "[eglot] %s" (apply #'eglot--format format args))) (defun eglot--warn (format &rest args) "Warning message with FORMAT and ARGS." (apply #'eglot--message (concat "(warning) " format) args) (let ((warning-minimum-level :error)) - (display-warning 'eglot (apply #'format format args) :warning))) + (display-warning 'eglot (apply #'eglot--format format args) :warning))) (defalias 'eglot--bol (if (fboundp 'pos-bol) #'pos-bol @@ -3634,7 +3641,7 @@ If SILENT, don't echo progress in mode-line." (howmany (length edits)) (reporter (unless silent (make-progress-reporter - (format "[eglot] applying %s edits to `%s'..." + (eglot--format "[eglot] applying %s edits to `%s'..." howmany (current-buffer)) 0 howmany))) (done 0)) @@ -3756,8 +3763,9 @@ edit proposed by the server." "Rename the current symbol to NEWNAME." (interactive (list (read-from-minibuffer - (format "Rename `%s' to: " (or (thing-at-point 'symbol t) - "unknown symbol")) + (eglot--format "Rename `%s' to: " + (or (thing-at-point 'symbol t) + "unknown symbol")) nil nil nil nil (symbol-name (symbol-at-point))))) (eglot-server-capable-or-lose :renameProvider) -- 2.39.5