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 customizable variables for cheatsheet #3690

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

katomuso
Copy link
Contributor

Add multiple customizable variables to control different aspects of cider-cheatsheet and cider-cheatsheet-select behavior.

@katomuso
Copy link
Contributor Author

@bbatsov Can I be added to the cider-cheatsheet.el package authors?


(defcustom cider-cheatsheet-auto-select-buffer t
"Whether to auto-select the cheatsheet popup buffer."
:type 'boolean)
Copy link
Member

Choose a reason for hiding this comment

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

You should also add :package-version properties to all defcustoms (saying 1.15.0 as the version).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

(const :tag "ClojureDocs" cider-clojuredocs-lookup)
function))

(defcustom cider-cheatsheet-select-path nil
Copy link
Member

Choose a reason for hiding this comment

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

Probably it'd better for this to be an option taking some symbol (the name of the type of behavior to use) instead of a boolean - it would make the code more flexible if we decide to add different options down the road.

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 think that it's a good idea to create a variable like cider-cheatsheet-select-type or cider-cheatsheet-select-display, which accepts symbols like multi (default) and path. However, one small consequence of this approach is that we won't be able to use cider-cheatsheet-select with a prefix argument anymore as it doesn’t make sense to negate the value of this variable as it did with cider-cheatsheet-select-path, which accepted a boolean. Will this be okay?

Copy link
Contributor Author

@katomuso katomuso Jun 2, 2024

Choose a reason for hiding this comment

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

Actually, we can do something similar. We just need to check the exact prefix argument value and use the value of cider-cheatsheet-select-type accordingly, as it is done in cider-jack-in-universal, right?

Copy link
Member

Choose a reason for hiding this comment

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

That's one option, another would be to just drop the prefix argument and rely only on the defcustom.

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 think it will be better to drop the prefix argument as most users will probably always use one way or the other.

"Whether to auto-select the cheatsheet popup buffer."
:type 'boolean)

(defcustom cider-cheatsheet-doc-function #'cider-doc-lookup
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use a more generic name like cider-cheatsheet-(default)-action-function? And obviously in the buffer view we can also have more actions bound to different keybindings (the default could be the one triggered by RET)

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'm not exactly sure what you mean. Maybe you can point me to some place where such logic is already implemented, so I can understand it better? I think some examples of values for such a variable will also be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand correctly, you're suggesting renaming it to a more generic name because it's not guaranteed that by selecting a var, the user wants to show documentation. Did I understand that correctly?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, exactly. You can check the namespace navigator or apropos where you can trigger different actions in the buffer displaying the results (e.g. you can show the docs or go to the definition for some var), and there's some default action triggered by RET. I'm not sure if that makes much sense here, but it's another case where we are dealing with var names, so we might aim for some consistency.

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 agree, and it actually looks more generic, which is a good thing.

such as '/' and '&'."
:type 'string)

(defcustom cider-cheatsheet-indentation-function
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite certain that many people will want to modify this. Do you have any particular use-case in mind?

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 thought that, since it is related to UI, some users might want to modify how it looks. However, I agree that most users won't do this, and it is actually not that safe to modify that variable, as it can break cider-cheatsheet-select. So, I think it would be a good idea to move it to a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I assumed you meant cider-cheatsheet-select-path-separator. If it is cider-cheatsheet-indentation-function, then some people prefer 2 spaces, others 4 spaces, tabs, or other indication of indentation. This use-case is what I had in mind when adding this as a customizable variable.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like premature optimization to me. I usually wait for the users to request some config options if I have doubts that there would be demand for them.

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 think that's a good approach, so for now, they will be removed.

@bbatsov
Copy link
Member

bbatsov commented Jun 2, 2024

@bbatsov Can I be added to the cider-cheatsheet.el package authors?

Sure.

@katomuso
Copy link
Contributor Author

katomuso commented Jun 2, 2024

@bbatsov Can I be added to the cider-cheatsheet.el package authors?

Sure.

Thank you! I'll update the package commentary in a separate PR after this one is finished.

@katomuso
Copy link
Contributor Author

katomuso commented Jun 2, 2024

I've made all the changes as discussed in the review:

  • Renamed cider-cheatsheet-doc-function to cider-cheatsheet-default-action-function and tweaked docstring
  • Renamed cider-cheatsheet-select-path to cider-cheatsheet-select-type, tweaked docstring and removed prefix argument for cider-cheatsheet-select
  • Removed cider-cheatsheet-select-path-separator and cider-cheatsheet-indentation-function

If `path`, then represent each completion candidate as a full path to a var."
:type '(choice (const multi)
(const path))
:package-version '(cider . "0.15.0"))
Copy link
Member

Choose a reason for hiding this comment

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

1.15.0 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, fixed!

function)
:package-version '(cider . "0.15.0"))

(defcustom cider-cheatsheet-select-type 'multi
Copy link
Member

Choose a reason for hiding this comment

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

Let me think a bit about the names multi and path, because I'm not sure those are optimal here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I think so as well, but it was tough to come up with something better.

Copy link
Contributor Author

@katomuso katomuso Jun 2, 2024

Choose a reason for hiding this comment

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

Some alternatives I came up with are multi-step and full-path, or nested and flat.

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, come to think of it, maybe just having a prefix argument for cider-cheatsheet-select will be enough for now.

Copy link
Member

Choose a reason for hiding this comment

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

Fair 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.

Okay, I've pushed the change and updated the docs in #3695.

@katomuso katomuso force-pushed the cheatsheet-custom branch 2 times, most recently from 28ef58e to 1455194 Compare June 2, 2024 22:30
@bbatsov bbatsov merged commit 78e4a1c into clojure-emacs:master Jun 3, 2024
39 checks passed
@bbatsov
Copy link
Member

bbatsov commented Jun 3, 2024

Thanks!

@katomuso katomuso deleted the cheatsheet-custom branch June 3, 2024 13:25
@katomuso katomuso restored the cheatsheet-custom branch June 3, 2024 17:29
@katomuso katomuso deleted the cheatsheet-custom branch June 3, 2024 17:30
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