reddit / emacs

Marking commands for read-extended-command-predicate

MistakeNotDotDotDot · 2022-02-25 07:05
At some point in I think 2021, `read-extended-command-predicate` was added, which lets you filter what `M-x` shows you. One of the intended use cases is to prevent commands for one major mode from showing up when working in another major mode. It's nil by default, but you can `(setq read-extended-command-predicate 'command-completion-default-include-p)`... except for the fact that basically no package I can find actually *uses* this, either by using (defun foo () (declare (modes . (lisp-mode))) (interactive) (message "I only show up in some-mode")) or by `(put 'foo 'command-modes '(lisp-mode))`. I'd like to go through all the commands whose names start with (say) `python-` and mark them as being `python-mode` commands. What's the easiest way to do that? PS, is there any downside to package authors doing this? The `declare` variation warns on older versions of emacs, but the `put` variation should work no matter what. I'm really surprised this has almost no adoption/conversation that I could find. Out of all the packages I have cloned locally, only `transient` uses it, and only `vertico` and other packages by the same author use the related `completion-predicate` property.
_viz_ · 2022-02-25 09:59
There's an entry for this in etc/TODO so if you want better support, you can send patches upstream. ;-) I don't think a progmattic way like that will ever work. The entry point commands often share the same prefix so it will end up annoying users instead.
MistakeNotDotDotDot · 2022-02-25 16:42
Oh, to be clear I only want to do it programmatically for my own .emacs.
_viz_ · 2022-02-25 17:01
Sure, but it still looks like a bad idea to me.
MistakeNotDotDotDot · 2022-02-25 17:36
I mean, most programming language modes get automatically activated so there's no manual entry point. What's the problem? (I'd still like to try it and see how it goes. I'm only going to do it for programming language modes at first.)