我正在尝试在 elisp 中创建一个函数来打开带有预填充文本的邪恶前缓冲区,并将光标放在中间的某个位置。但是,到目前为止,我所能做的就是打开带有预填充文本的缓冲区,并在末尾打开光标:
(evil-ex "HelloWorld")
如果有人可以提供帮助,我将不胜感激。
您可以minibuffer-setup-hook
在启动 minibuffer 后使用 a 来执行一些 elisp,有一个有用的宏可以让您添加一个临时钩子:minibuffer-with-setup-hook
这是一个示例,我使用它启动 minibufferevil-ex
并将光标移动到初始值的中点:
(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