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.
This commit is contained in:
João Távora 2026-06-01 19:40:23 +01:00
parent 8855e88d74
commit 3229d6f0e3
3 changed files with 24 additions and 28 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)))