emacs lisp call function with prefix argument programmatically

断了今生、忘了曾经 提交于 2019-12-03 02:03:46

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)

Or you could just use a keyboard macro

(global-set-key (kbd "s-l") (kbd "C-u C-SPC"))

In this example, the key combination "s-l" (s ("super") is the "windows logo" key on a PC keyboard) will go back the mark ring, just like you typed "C-u C-SPC".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!