我正在尝试在elisp中创建一个函数来打开带有预填充文本的邪恶前缓冲区,并将光标放在中间的某个位置。但是,我迄今为止所做的就是打开带有预填充文本的缓冲区,并在末尾打开光标:
(evil-ex "HelloWorld")
如果有人可以提供帮助,我会非常感激。
答案 0 :(得分:4)
你可以在启动迷你缓冲区后使用minibuffer-setup-hook
执行一些elisp,这里有一个有用的宏可以让你添加一个临时钩子:minibuffer-with-setup-hook
以下是我使用evil-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