bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#69647: [PATCH 1/2] Delete trailing whitespace when formatting LSP do


From: Jim Porter
Subject: bug#69647: [PATCH 1/2] Delete trailing whitespace when formatting LSP documentation
Date: Fri, 8 Mar 2024 13:36:45 -0800

On 3/8/2024 1:02 PM, João Távora wrote:
And that's probably the ideal solution too.  But as far as I remember,
markdown-view-mode (or whatever it's called) is not used for viewing the
documentation.  it is used somewhere in the pipeline to render the text in a
buffer which is then yanked using `buffer-substring` (with properties).

Yep. 'eglot--format-markup' uses 'gfm-view-mode' in a temp buffer and returns it as a string after calling 'buffer-string'. That should be fine though. For example, last year I fixed a similar issue with Eglot's usage of Markdown mode where backslash escapes still showed up in the Eldoc buffer:

  https://github.com/joaotavora/eglot/issues/188
  https://github.com/jrblevin/markdown-mode/pull/756
  https://github.com/jrblevin/markdown-mode/issues/766

I expect that something similar could be done for the trailing spaces case.

So I don't know how that'd work.  Maybe Philip's patch can be tweaked to leave
those specific bits of trailing whitespace alone?

I think we should leave the trailing whitespace alone in Eglot entirely; the underline that Philip mentioned in the original report is from 'markdown-line-break-face', which Markdown mode uses[1] to fontify only the trailing whitespace that means "insert a line break".

And do we really want to preserve the LSP server's notion of a line
break anyway?  It has no concept of how wide the  Emacs window is.
I'd say paragraphs yes, line breaks no.
I think we do in this case, yes. (Although I guess this depends on how Markdown mode handles things.) These are "hard" line breaks corresponding to the "<br>" tag when you convert Markdown->HTML, so they should always get turned into a newline.

Normally if I have some text like "foo bar\nbaz" in Markdown, that should get rendered as "foo bar baz": the newline is just there to make the source text readable, but it's treated like a space. 'markdown-view-mode' (and 'gfm-view-mode') don't do this though, so a soft newline stays a newline in the "view" output. This also means that the Markdown line break sequence (" \n") isn't necessary in 'markdown-view-mode' to get a line break. Just the "\n" is sufficient. (In this sense, we could remove the " " and there'd be no issues with the *current* version of markdown-mode.)

If I were going to make a complete fix for this, I'd do most of it in markdown-mode and would do the following things:

1. Translate "\n" to " " in 'markdown-view-mode'
2. Translate "  \n" to "\n" in 'markdown-view-mode'
3. Turn on 'visual-line-mode' in the ElDoc buffer to get soft line wrapping

However, as a partial fix, you could probably just set 'markdown-line-break-face' to be invisible when 'markdown-hide-markup[-in-view-modes]' is non-nil somewhere in Markdown mode. I think that would be easy, although I tried to do this and the obvious method didn't work, so who knows?

[1] Or *should* use, anyway. I haven't tested all possible cases.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]