2

我正在尝试在 elisp 中创建一个函数来打开带有预填充文本的邪恶前缓冲区,并将光标放在中间的某个位置。但是,到目前为止,我所能做的就是打开带有预填充文本的缓冲区,并在末尾打开光标:

(evil-ex "HelloWorld")

如果有人可以提供帮助,我将不胜感激。

4

1 回答 1

4

使用 minibuffer-setup-hook

您可以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:

minibuffer-setup-hook is a variable defined in `C source code'.

Documentation:
Normal hook run just after entry to minibuffer. <- important part
于 2014-04-01T19:59:17.517 回答