From 4b2e57e396314e63d70558e0aa5ad32c1cf87532 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 14 Jan 2022 17:20:23 -0600 Subject: David Bowie --- lisp/+browse-url.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lisp/+browse-url.el') diff --git a/lisp/+browse-url.el b/lisp/+browse-url.el index 89b21e4..cf0742b 100644 --- a/lisp/+browse-url.el +++ b/lisp/+browse-url.el @@ -25,7 +25,8 @@ that the latter is deprecated in Emacs 28+." (viewer default-args &optional (prompt "URL: ") &key (custom-group '+browse-url) - (name (format "+browse-url-with-%s" viewer))) + (name (format "+browse-url-with-%s" viewer)) + (fallback #'browse-url-generic)) "Create a `browse-url' handler function that calls VIEWER on the url. Also create a `customize' setting in CUSTOM-GROUP for VIEWER's arguments. DEFAULT-ARGS specifies the default arguments that @@ -33,7 +34,10 @@ setting should have. PROMPT will be shown to user in the function's `interactive' spec, as an argument to `browse-url-interactive-arg'. The resulting function will be named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable -\"NAME-args\"." +\"NAME-args\". + +If FALLBACK is non-nil, it's a function to fallback on if the +`start-process' call fails in anyway." (declare (indent 1)) `(progn (defcustom ,(intern (format "%s-args" name)) @@ -41,16 +45,19 @@ named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable ,(format "Arguments to pass to %s in `%s'." viewer name) :type '(repeat :tag "Command-line argument" string) :group ',custom-group) - (defun ,(intern name) (url &optional _new-window) + (defun ,(intern name) (url &optional new-window) ,(format "Open URL in %s." viewer) (interactive (browse-url-interactive-arg ,prompt)) (let* ((url (browse-url-encode-url url)) (process-environment (browse-url-process-environment))) (message ,(format "Opening %%s in %s..." viewer) url) - (apply #'start-process - (concat ,viewer " " url) nil - ,viewer - (append ,(intern (format "%s-args" name)) (list url))))))) + (unless (ignore-errors + (apply #'start-process + (concat ,viewer " " url) nil + ,viewer + (append ,(intern (format "%s-args" name)) + (list url)))) + (funcall fallback url new-window)))))) ;; Reference implementation: mpv (+browse-url-make-external-viewer-handler "mpv" nil "Video URL: ") -- cgit 1.4.1-21-gabe81