Use a minibuffer-setup-hook
You can use a minibuffer-setup-hook
to execute some elisp after starting up the minibuffer, there is a useful macro for this that lets you add a temporary hook: minibuffer-with-setup-hook
Example:
Here is an example where I startup the minibuffer with evil-ex
and move the cursor to the midpoint of the initial value:
(let ((my-string "Hello, World!"))
(minibuffer-with-setup-hook
(lambda () (backward-char (/ (length my-string) 2)))
(evil-ex my-string)))
See the documentation for minibuffer-with-setup-hook
:
minibuffer-with-setup-hook is a Lisp macro in `files.el'.
(minibuffer-with-setup-hook FUN &rest BODY)
Temporarily add FUN to `minibuffer-setup-hook' while executing BODY.
BODY should use the minibuffer at most once.
Recursive uses of the minibuffer are unaffected (FUN is not
called additional times).
minibuffer-setup-hook:
minibuffer-setup-hook is a variable defined in `C source code'.
Documentation:
Normal hook run just after entry to minibuffer. <- important part