Reputation: 1885
I am trying to create a function in elisp to open the evil ex buffer with prefilled text and place the cursor somewhere in the middle. However, all I've been able to do so far is open the buffer with prefilled text and the cursor at the end with this:
(evil-ex "HelloWorld")
If anyone could help, I would really apprecieate it.
Upvotes: 2
Views: 307
Reputation: 4029
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
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)))
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 is a variable defined in `C source code'.
Documentation:
Normal hook run just after entry to minibuffer. <- important part
Upvotes: 4