以编程方式使用前缀参数的emacs lisp调用函数 [英] emacs lisp call function with prefix argument programmatically
问题描述
我想从一些elisp代码调用一个函数,就像我用一个前缀参数交互地调用它一样。具体来说,我想用一个前缀调用grep。
I want to call a function from some elisp code as if I had called it interactively with a prefix argument. Specifically, I want to call grep with a prefix.
最接近它的工作是使用 execute-extended-command
,仍然要求我键入我要调用的一个前缀...
The closest I've gotten to making it work is using execute-extended-command
, but that still requires that I type in the command I want to call with a prefix...
;; calls command with a prefix, but I have to type the command to be called...
(global-set-key (kbd "C-c m g")
(lambda () (interactive)
(execute-extended-command t)))
文档说执行扩展命令
使用 command-execute
执行从minibuffer读取的命令,但是我无法使其工作:
The documentation says that execute-extended-command
uses command-execute
to execute the command read from the minibuffer, but I haven't been able to make it work:
;; doesn't call with prefix...
(global-set-key (kbd "C-c m g")
(lambda () (interactive)
(command-execute 'grep t [t] t)))
有没有办法调用一个前缀而非非 -
Is there any way to call a function with a prefix yet non-interactively?
推荐答案
如果我理解你的权利,你正在试图做一个绑定,类似于您键入 Cu Mx grep< ENTER>
。尝试这样:
If I'm understanding you right, you're trying to make a keybinding that will act like you typed C-u M-x grep <ENTER>
. Try this:
(global-set-key (kbd "C-c m g")
(lambda () (interactive)
(setq current-prefix-arg '(4)) ; C-u
(call-interactively 'grep)))
尽管我可能会为此命名一个函数:
Although I would probably make a named function for this:
(defun grep-with-prefix-arg ()
(interactive)
(setq current-prefix-arg '(4)) ; C-u
(call-interactively 'grep))
(global-set-key (kbd "C-c m g") 'grep-with-prefix-arg)
这篇关于以编程方式使用前缀参数的emacs lisp调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!