reddit / emacs

Can I start "execute-extended-command" with an initial input?

thiscarhasfourtires · 2022-11-05 11:38
I used to be able to do that quite easily when I used `ivy/counsel`, and used to create all kinds of functions. But Doom switched to embark/consult which uses the builtins and I don't know how to do that anymore.
takeonrules · 2022-11-05 13:14
Looking at the method signature of `execute-extended-command`, you can can provide an initial input (e.g. `(defun execute-extended-command (prefixarg &optional command-name typed)`). However, I'm uncertain if that is the specific thing you're after. My read on your problem is that you used to have functions that you created via `ivy/counsel` that were shortcuts(?) to other `M-x` commands. And you're not able to do that easily without `ivy/counsel`. It is possible you are looking to leverage the `call-interactively` function. Some more details on what specifically you are trying to accomplish (the particular initial input) would help begin to craft both a specific solution and point you towards the general path.
oantolin · 2022-11-05 22:41
Do you mean like this? (defun execute-extended-command-with-initial-input (initial) (interactive) (minibuffer-with-setup-hook (lambda () (insert initial)) (command-execute #'execute-extended-command))) Then, for example, `(execute-extended-command-with-initial-input "org")` will give you a prompt with "org" already typed in.
thiscarhasfourtires · 2022-11-05 23:03
That is exactly what it is! You're a champ! Thanks ;)