2

我想定义 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))))

但这感觉像是在作弊(更不用说让我的代码变得脆弱了)。

4

1 回答 1

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)))
于 2013-06-03T04:56:13.793 回答