我想定义Emacs命令的修改版本,例如browse-url
。
修改后的版本应绑定一些变量,然后按照系统命令,例如,
(defun browse-url-incognito (url &rest args)
???
(let ((browse-url-browser-function 'browse-url-generic)
(browse-url-generic-program "google-chrome")
(browse-url-generic-args '("--incognito")))
(apply 'browse-url url args)))
问题在于???
部分应该将该功能转换为交互式命令。
我当然可以复制browse-url.el
:
(interactive (browse-url-interactive-arg "URL: "))
(unless (called-interactively-p 'interactive)
(setq args (or args (list browse-url-new-window-flag))))
但这感觉就像作弊(更不用说让我的代码变得脆弱了)。
答案 0 :(得分:4)
call-interactively
似乎还在努力:
(defun browse-url-incognito ()
"Call `browse-url' displaying in a chrome incognito window."
(interactive)
(let ((browse-url-browser-function 'browse-url-generic)
(browse-url-generic-program "google-chrome")
(browse-url-generic-args '("--incognito")))
(call-interactively 'browse-url)))