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

Add an alternative way to display cider-cheatsheet-select #3686

Merged
merged 2 commits into from
May 29, 2024

Conversation

katomuso
Copy link
Contributor

Instead of having the multi-step selection process, which is the default cider-cheatsheet-select behavior, we represent each candidate as a full path to a var when cider-cheatsheet-select is called with a prefix argument. This can be handy with fuzzy completion style and vertical candidates display, as discussed in #3678.

Here's how the default multi-step selection process looks when you need to select every single section before choosing a var:
cider-cheatsheet-select-default

In contrast, when cider-cheatsheet-select is called with a prefix argument, each candidate is a full path to a var:
cider-cheatsheet-select-flat

(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
(var (completing-read "Select var: " vars)))
(cider-doc-lookup var))))
(defun cider-cheatsheet-select (&optional flat)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this can be a defcustom instead and you can use the prefix arg to invert whatever the value of the defcustom is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I've seen such a pattern a few times, but haven't thought about it this time. I planned to think about customizable variables later, so I will keep this in mind.

@bbatsov
Copy link
Member

bbatsov commented May 29, 2024

Nice improvement - i definitely like it.

@katomuso
Copy link
Contributor Author

I wonder why the lint check failed because eldev lint shows no warnings...

@katomuso
Copy link
Contributor Author

I wonder why the lint check failed because eldev lint shows no warnings...

Oh, I found it. It has to do with byte compilation and the string-split function. I don't need to fix this kind of warnings, right?

@bbatsov
Copy link
Member

bbatsov commented May 29, 2024

You just need to require subr-x and the error will go away.

@katomuso
Copy link
Contributor Author

You just need to require subr-x and the error will go away.

Hmm, it seems that the error is still present, as string-split is located in subr.el, while other string functions indeed are located in subr-x.el.

@bbatsov
Copy link
Member

bbatsov commented May 29, 2024

Ah, my bad. Then it's very weird, as subr.el is auto-required always.

@bbatsov
Copy link
Member

bbatsov commented May 29, 2024

Hmm, I see that the function is actually named split-string, so it seems the warning has discovered an actual error. :-)

@@ -32,6 +32,7 @@
(require 'cl-lib)
(require 'map)
(require 'seq)
(require 'subr-x)
Copy link
Member

Choose a reason for hiding this comment

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

In light of my last comment you can remove 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.

As I actually use string-join from subr-x, I think it will be okay to be explicit about it by requiring it.

(let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy))
(paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy))
(path (completing-read "Select path: " paths))
(var (car (last (string-split path " > ")))))
Copy link
Member

Choose a reason for hiding this comment

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

It's actually split-string. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html

No idea how this ever worked for you, if the name of the function is wrong.

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, this is an alias. I guess that may be the reason it can't find it during byte compilation.

Copy link
Member

Choose a reason for hiding this comment

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

It also seems this alias was only added in Emacs 29.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, changing the name fixed it. It still seems weird, but I'll be more cautious with aliases from now on :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It also seems this alias was only added in Emacs 29.

I see, so that's the reason. Thanks for helping me figure it out.

@katomuso
Copy link
Contributor Author

So now that all the checks are passing, can I add a new entry to the changelog so we can merge the change? I'll add customizable variables in the future as I am still not sure about some of the details.

@bbatsov
Copy link
Member

bbatsov commented May 29, 2024 via email

@bbatsov bbatsov merged commit 5964bd3 into clojure-emacs:master May 29, 2024
39 checks passed
@bbatsov
Copy link
Member

bbatsov commented May 29, 2024

Thanks!

@katomuso katomuso deleted the cheatsheet-select-flat branch May 29, 2024 12:11
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.

2 participants