From 3229d6f0e32b495c8587cea9ba645110dd4277fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 1 Jun 2026 19:40:23 +0100 Subject: [PATCH] Eglot: Simplify markdown rendering support (bug#81150) Now that markdown-ts-view-mode is demoted to "experimental" in emacs-31, simplify bits of eglot.el and rewrite docs to be more neutral. In practice 'gfm-view-mode' is still used if found, just like before, but intrepid users can still try the "experimental" modes. * lisp/progmodes/eglot.el (eglot-documentation-renderer): Rewrite doc string. (eglot--accepted-formats): Rewrite. (eglot--builtin-mdown-p): Remove. * doc/misc/eglot.texi (Customization Variables): Rewrite entry. * etc/EGLOT-NEWS: Tweak. --- doc/misc/eglot.texi | 15 ++++++++------- etc/EGLOT-NEWS | 9 ++++++--- lisp/progmodes/eglot.el | 28 ++++++++++------------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/doc/misc/eglot.texi b/doc/misc/eglot.texi index 97a934fa953..1c9acdc6f9b 100644 --- a/doc/misc/eglot.texi +++ b/doc/misc/eglot.texi @@ -999,13 +999,14 @@ will consider it to be part of the workspace. The default is @cindex markdown renderer @item eglot-documentation-renderer This variable controls how Eglot renders at-point documentation imported -from the server (@pxref{Eglot Features}). By default, the variable's -value is set during startup to the @code{gfm-view-mode} markdown -renderer if available. This utility visually enhances the documentation -content through fontification and other formatting. If you set it to -@code{t}, plain text will be requested from the server and no rendering -is attempted. If the variable's value is @code{nil}, Eglot will attempt -to find a suitable renderer every time. +from the server (@pxref{Eglot Features}). The default value is +@code{nil}, meaning Eglot selects a suitable Markdown renderer on each +use---for example, @code{gfm-view-mode} from @code{markdown-mode} on +NonGNU ELPA, which enhances documentation through fontification and +other formatting. You can also set it to always use a specific major mode symbol, such +as the aforementioned @code{gfm-view-mode}, or the experimental +@code{markdown-ts-view-mode}. If you set it to @code{t}, plain text is +requested from the server and no rendering is attempted. @item eglot-mode-map This variable is the keymap for binding Eglot-related command. It is in diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index 7510f13521e..5b487fd1621 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS @@ -32,11 +32,14 @@ New key bindings: 'k' shuts down, 'r' reconnects, 'e' visits the events buffer, 'w' shows workspace configuration, and 'RET' invokes 'eglot-describe-connection'. -** 'eglot-documentation-renderer' replaces 'eglot-prefer-plaintext'. +** New variable 'eglot-documentation-renderer' (bug#80127) The variable 'eglot-documentation-renderer' replaces the now-obsolete -'eglot-prefer-plaintext'. By default, the variable selects a markdown -renderer to use throughout the session. +'eglot-prefer-plaintext' and offers more control over what major mode is +used to render markdown snippets. By default, the variable is nil and +'gfm-view-mode' from NonGNU ELPA's markdown-mode package is used if +found. You may also set it to the experimental 'markdown-ts-view-mode' +in Emacs versions with tree-sitter markdown support. * Changes in Eglot 1.23 (2/4/2026) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index a8b107b1a89..8d5d7cafc3c 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -537,15 +537,12 @@ or file operation kinds not in the alist." "If non-nil, activate Eglot in cross-referenced non-project files." :type 'boolean) -(defcustom eglot-documentation-renderer (cond ((fboundp 'gfm-view-mode) - 'gfm-view-mode) - (t - nil)) - "Control rendering of LSP documentation fragments. -If set to the major mode symbol `gfm-view-mode', request -markdown-snippets and use `gfm-view-mode' to render it. -If t, always request and render plain text snippets. If set to nil, -decide dynamically." +(defcustom eglot-documentation-renderer nil + "Controls rendering of LSP documentation fragments. +If set to a major mode symbol like `gfm-view-mode', or the experimental +`markdown-ts-view-mode', request markdown snippets and use that mode to +render them. If t, request and render plain text instead. If nil, +request markdown snippets and select a renderer dynamically." :type '(choice (const :tag "Plain text" t) (const :tag "Auto-detect" nil) (function :tag "Renderer")) @@ -738,16 +735,11 @@ This can be useful when using docker to run a language server.") (declare-function treesit-grammar-location "treesit.c") -(defun eglot--builtin-mdown-p () - (and (fboundp 'markdown-ts-view-mode) - (fboundp 'treesit-grammar-location) - (treesit-grammar-location 'markdown))) - (defun eglot--accepted-formats () - (if (and (not (eq t eglot-documentation-renderer)) - (or (fboundp 'gfm-view-mode) (eglot--builtin-mdown-p))) - ["markdown" "plaintext"] - ["plaintext"])) + (if (or (eq t eglot-documentation-renderer) + (not (or eglot-documentation-renderer (fboundp 'gfm-view-mode)))) + ["plaintext"] + ["markdown" "plaintext"])) (defconst eglot--uri-path-allowed-chars (let ((vec (copy-sequence url-path-allowed-chars)))