sds
sds

Reputation: 60064

How to define a wrapper command?

I want to define a modified version of an Emacs command, e.g., browse-url.

The modified version should bind some variables and then defer to the system command, e.g.,

(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)))

The problem is with the ??? part which should turn the function into an interactive command.

I can, of course, copy over the code from browse-url.el:

  (interactive (browse-url-interactive-arg "URL: "))
  (unless (called-interactively-p 'interactive)
    (setq args (or args (list browse-url-new-window-flag))))

but this feels like cheating (not to mention making my code fragile).

Upvotes: 2

Views: 143

Answers (1)

sds
sds

Reputation: 60064

call-interactively seems to foot the bill:

(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)))

Upvotes: 4

Related Questions