使用elisp在邪恶的迷你缓冲区中移动光标

时间:2014-04-01 00:07:15

标签: emacs elisp evil-mode

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

(evil-ex "HelloWorld")

如果有人可以提供帮助,我会非常感激。

1 个答案:

答案 0 :(得分:4)

使用minibuffer-setup-hook

你可以在启动迷你缓冲区后使用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