Subject: bug#61072: How to change the length of the separation lines in eldoc, used by eglot?

From: João Távora <[email-masked]>
Date: Thu, 23 Mar 2023 21:53:18 +0000

Wei-Ting Lin <[email-masked]> writes:

> As seen in the screenshot, the line is too long for the child frame and gets wrapped. How can I change the length of the
> line?

> This issue was posted in https://github.com/joaotavora/eglot/discussions/1157 originally. 

Hello,

I'm sorry for the long delay in replying to this.  I've investigated
this issue today.  This issue in on my radar with lots of other related
Eglot/ElDoc issues (see for example bug#62029)

I think this one specifically is coming from the markdown.el library
(https://jblevins.org/projects/markdown-mode/).  I'm copying in the
maintainer, Jason Blevins.

Jason, you're probably out of the loop.  Eglot is using gfm-view-mode to
"render" Markdown snippets in temporary buffers, so it can then shoot
that results as a propertized string to ElDoc, which shows it in
different outlets (buffers, echo area, child frames, etc.

The very long separator we're seeing in the screenshot is markdown.el's
way of rendering Markdown horizontal rulers.  There, it uses this code:

    (defun markdown-fontify-hrs (last)
      "Add text properties to horizontal rules from point to LAST."
      ...
                      `(display ,(make-string
                                  (1- (window-body-width)) hr-char)))))
      ...
          t)))

As we can see, `window-body-width' is used, which is problematic because
it creates text with a display spec which might not match the size of
the window used for showing this text.  Instead, markdown.el could use
something like propertizing that text witha special face, which doesn't
suffer from this shortcoming.  To see how it behaves, evaluate this code

  (with-current-buffer (pop-to-buffer "*test*")
    (insert "foo\n")
    (insert (propertize "\n" 'face '(:inherit separator-line :extend t)))
    (insert "bar\n")
    (insert (propertize "\n" 'face '(:inherit separator-line :extend t)))
    (insert "baz"))

While we're on the topic, there are other things that could make
markdown.el much more useful for ElDoc/Eglot's purposes, like being able
to "fill" paragraphs regions to specific lengths (maybe infinite
lengths, so that visual-line-mode can do its thing)

João