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

ClojureDocs formatting tweaks #3701

Merged

Conversation

katomuso
Copy link
Contributor

@katomuso katomuso commented Jun 3, 2024

I plan to rework how ClojureDocs buffer is displayed (improve some formatting, make it more modular and customizable) and want to start with some small improvements.

This particular change:

  • Removes annoying whitespace that appears before every line (after the first one) of the docstring.
  • Changes how buttons are displayed so that * and newline are no longer part of the button.

This is how it looked before:
cider-cheatsheet-formatting-tweaks-old

This is how it looks now:
cider-cheatsheet-formatting-tweaks-new

@katomuso katomuso force-pushed the clojuredocs-formatting-tweaks branch from b9e6911 to ae5cd39 Compare June 3, 2024 17:08
(when-let ((doc (nrepl-dict-get dict "doc")))
(insert "\n")
(let ((lines (mapcar (lambda (line)
(replace-regexp-in-string "^\s+" "" line))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use string-trim-left?

One thing to consider here, though, is how much to strip exactly, as I'm guessing that some docstrings might have intentional indentation on some lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, string-trim-left will suffice in that case.

I'm not sure why we get these spaces in the docstring in the first place. Maybe it has something to do with ClojureDocs data.

But we can be sure that every line after the first one contains two additional spaces at the beginning, so maybe just removing exactly two spaces will be good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, they are here because this is a literal string from the source code. As there are generally two spaces at the beginning of lines in docstrings, I guess it will be okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'm also not sure where those spaces are coming from, but I guess your solution is unlikely to break something in the formatting.

@katomuso katomuso force-pushed the clojuredocs-formatting-tweaks branch from ae5cd39 to 2bebbba Compare June 3, 2024 20:00
(insert (nrepl-dict-get dict "doc"))
(insert "\n"))
(when-let ((doc (nrepl-dict-get dict "doc")))
(insert "\n" (replace-regexp-in-string "\n " "\n" doc) "\n")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a note here regarding the need to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a note.

@katomuso katomuso force-pushed the clojuredocs-formatting-tweaks branch from 2bebbba to f2553a6 Compare June 4, 2024 12:23
@bbatsov bbatsov merged commit 1fcc6d2 into clojure-emacs:master Jun 4, 2024
39 checks passed
@katomuso katomuso deleted the clojuredocs-formatting-tweaks branch June 5, 2024 14:28
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

Successfully merging this pull request may close these issues.

None yet

2 participants