Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek advice on the formatting of eldoc buffer #61

Closed
seraphlive opened this issue Mar 7, 2023 · 4 comments
Closed

Seek advice on the formatting of eldoc buffer #61

seraphlive opened this issue Mar 7, 2023 · 4 comments

Comments

@seraphlive
Copy link

seraphlive commented Mar 7, 2023

This is not a bug of eldoc-box, but rather a minor but annoying formatting issue caused by markdown-mode used by elgot. I've raised jrblevin/markdown-mode#754 to markdown-mode, but while waiting I'd like to ask some advice from you to find a temporary workaround since you are more familiar with eldoc and eglot.

To give you a background about what I was trying to do:

I set eldoc-documentation-strategy to eldoc-documentation-compose to show multiple source of eldoc. For example below buffer has 4 source (elisp-eldoc-var-docstring elisp-eldoc-funcall flymake-eldoc-function embark-eldoc-first-target):
image

By default there is no blank line to separate each source in eldoc buffer, so I override function eldoc--format-doc-buffer to add one (just add one more \n in the line of when rest do...). This looks nice:
image

Until I open a buffer with eglot sources (eglot-signature-eldoc-function eglot-hover-eldoc-function python-eldoc-function flymake-eldoc-function emabark-eldoc-first-target):
image

As you may see, there is one extra blank line from eglot-hover-eldoc-function, which is inconsistent with other sources. This is because of the issue that I've raised to markdown-mode. eglot-hover-eldoc-function use the view mode from markdown-mode to format the code in the lsp documentation with markdown format. And when markdown-mode hides the markup when enabling the view mode, it leaves an extra blank line if the "```" close mark is at the end of the buffer.

I was trying for several days to figure out a work-around to remove the extra blank line for eglot-hover-eldoc-function, but still not find out the correct. Hence I'd like to ask for some advice on how to modify this. Ideally it should be a more general solution to modify the eldoc-buffer or eglot-hover-eldoc-function but a eldoc-box specific method would also be great enough.

Sorry for bothering you with such a wall of text only for a minor format issue. I hope you may have some insight that can save me from this rabbit hole :)

@casouri
Copy link
Owner

casouri commented Mar 7, 2023

I can't test this, but try

(defun eldoc-box--remove-duplicate-newline ()
  "Compress more-than-3 consecutive newlines."
  (while (re-search-forward (rx (>= 3 "\n")) nil t)
    (replace-match "\n\n")))

(add-hook 'eldoc-box-buffer-hook #'eldoc-box--remove-duplicate-newline)

You can even make eldoc--format-doc-buffer to use a special character rather than a new line as the separator, and replace that special char with a nice separator in eldoc-box-buffer-hook, like shown in #60

@seraphlive
Copy link
Author

Thanks for the hints. Although the code can't work because it's not just a "\n" but hidden markup, I saw you've already caught that in your latest update. Also I feel your latter advice is actually better for me, because after trying a language with more redundant documentation like rust, I realize there will be countless newlines anyway. So simply use some dashes instead will work for me.

I also updated to the latest version of eldoc-box. The refined buffer looks nice but I notice something strange:

eldoc-box-help-at-point looks correct:
image

but eldoc-box-hover-mode doesn't:
image

Two things: 1. The function name is missing. This only happens to elisp's eldoc and eglot has no problem. 2. My own separator is missing :)

I basically use original eldoc and manually call eldoc-box-help-at-point so it's OK for me but I feel you may want to take a look into this. If it's just my mis-configuration instead of a bug, please feel free to close this issue. Thanks.

@casouri
Copy link
Owner

casouri commented Mar 8, 2023

Yeah, in eldoc-box-hover-mode, eldoc gives us a list of docs and we combine them into a single string ourselves, so your modification wouldn't take effect. I added a variable eldoc-box-doc-separator that you can customize.

Unfortunately this new variable wouldn't affect eldoc-box-help-at-point, so you need to keep your hack on eldoc.

As for the disappearing function name, it should be fixed now!

@seraphlive
Copy link
Author

image
Works perfect now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants