![](/img/trans.png)
[英]How to call interactive Emacs Lisp function with a prefix argument, from another Emacs Lisp function?
[英]emacs lisp call function with prefix argument programmatically
我想從一些 elisp 代碼中調用 function,就好像我使用前綴參數交互調用它一樣。 具體來說,我想用前綴調用 grep 。
我最接近讓它工作的是使用execute-extended-command
,但這仍然需要我輸入我想用前綴調用的命令......
;; 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)))
文檔說execute-extended-command
使用command-execute
執行從 minibuffer 讀取的命令,但我無法使其工作:
;; doesn't call with prefix...
(global-set-key (kbd "C-c m g")
(lambda () (interactive)
(command-execute 'grep t [t] t)))
有沒有辦法以非交互方式調用帶有前綴的 function ?
如果我對您的理解正確,那么您正在嘗試進行鍵綁定,就像您鍵入Cu Mx grep <ENTER>
一樣。 嘗試這個:
(global-set-key (kbd "C-c m g")
(lambda () (interactive)
(setq current-prefix-arg '(4)) ; C-u
(call-interactively 'grep)))
雖然我可能會為此命名為 function:
(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)
或者你可以只使用鍵盤宏
(global-set-key (kbd "s-l") (kbd "C-u C-SPC"))
在此示例中,組合鍵“sl”(s(“super”)是 PC 鍵盤上的“windows logo”鍵)將 go 向上標記環,就像鍵入“Cu C-SPC”一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.