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

Integrate with read-extended-command-predicate #61

Merged

Conversation

kenranunderscore
Copy link
Contributor

Motivation: Since Emacs 28.1 (I think) we have the option to add modes to interactive, say (interactive nil haskell-mode emacs-lisp-mode). The Emacs variable read-extended-command-predicate (when set to some predicate, for instance command-completion-default-include-p) then leads to those commands only being shown in M-x completion when the current buffer is in one of those modes.

I've added the :interactive-modes keyword, taking a list of those modes that are then passed to interactive, and tested it accordingly.

Some points/questions:

  • I'm not sure about the keyword naming. :modes would (I think) suggest something regarding the created minor mode, or similar to the :hooks behaviour in use-package, so I opted for a longer name giving the interactive context.
  • :interactive-modes expects an unquoted list of modes. It was easiest to implement it this way, as we can just splice it into interactive, which takes them as &rest. Is this fine?
  • Would it be better to special-case the single-mode version, allowing to omit the parentheses?
  • Should we make it clear that this is only for recent-enough Emacsen?

I personally find it very handy and nice to have my custom commands automatically narrowed down like this; just the ones defined with reformatter-define "stick out" a little bit, hence this PR. I'd be glad if you considered this in some way or other :)

@kenranunderscore
Copy link
Contributor Author

Ah, I see that the suspicion with older Emacsen was correct, given that my tests fail with Emacs 27 CI.

Should the feature itself be made conditional, or does it suffice that most likely only people opt in that do use read-extended-command-predicate? In the latter case, we could maybe just conditionalize the respective tests.

@kenranunderscore kenranunderscore force-pushed the add-mode-specific-commands branch from da57081 to dce9c3f Compare November 10, 2024 06:57
Adds the option to specify a list of modes that the interactive commands
are defined for.  This way, people using a
`read-extended-command-predicate' may have the "-region" and "-buffer"
commands only available via M-x in those modes.
@kenranunderscore
Copy link
Contributor Author

kenranunderscore commented Nov 10, 2024

I opted for the latter, that is, only defining/running those tests (when (fboundp 'command-modes) ...).

Some of the tests have pretty long lines; is that ok?

@kenranunderscore
Copy link
Contributor Author

Friendly bump :)
FWIW I'm using my fork including the change for a while now and haven't run into any problems with Emacs 29.

@purcell
Copy link
Owner

purcell commented Dec 4, 2024

Thanks, yeah, long test lines are fine. Merging now! 🚀🙏

@purcell purcell merged commit f2cb594 into purcell:master Dec 4, 2024
13 checks passed
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