summary refs log tree commit diff stats
path: root/lisp/+browse-url.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+browse-url.el')
-rw-r--r--lisp/+browse-url.el21
1 files changed, 14 insertions, 7 deletions
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+."
25 (viewer default-args &optional (prompt "URL: ") 25 (viewer default-args &optional (prompt "URL: ")
26 &key 26 &key
27 (custom-group '+browse-url) 27 (custom-group '+browse-url)
28 (name (format "+browse-url-with-%s" viewer))) 28 (name (format "+browse-url-with-%s" viewer))
29 (fallback #'browse-url-generic))
29 "Create a `browse-url' handler function that calls VIEWER on the url. 30 "Create a `browse-url' handler function that calls VIEWER on the url.
30Also create a `customize' setting in CUSTOM-GROUP for VIEWER's 31Also create a `customize' setting in CUSTOM-GROUP for VIEWER's
31arguments. DEFAULT-ARGS specifies the default arguments that 32arguments. DEFAULT-ARGS specifies the default arguments that
@@ -33,7 +34,10 @@ setting should have. PROMPT will be shown to user in the
33function's `interactive' spec, as an argument to 34function's `interactive' spec, as an argument to
34`browse-url-interactive-arg'. The resulting function will be 35`browse-url-interactive-arg'. The resulting function will be
35named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable 36named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable
36\"NAME-args\"." 37\"NAME-args\".
38
39If FALLBACK is non-nil, it's a function to fallback on if the
40`start-process' call fails in anyway."
37 (declare (indent 1)) 41 (declare (indent 1))
38 `(progn 42 `(progn
39 (defcustom ,(intern (format "%s-args" name)) 43 (defcustom ,(intern (format "%s-args" name))
@@ -41,16 +45,19 @@ named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable
41 ,(format "Arguments to pass to %s in `%s'." viewer name) 45 ,(format "Arguments to pass to %s in `%s'." viewer name)
42 :type '(repeat :tag "Command-line argument" string) 46 :type '(repeat :tag "Command-line argument" string)
43 :group ',custom-group) 47 :group ',custom-group)
44 (defun ,(intern name) (url &optional _new-window) 48 (defun ,(intern name) (url &optional new-window)
45 ,(format "Open URL in %s." viewer) 49 ,(format "Open URL in %s." viewer)
46 (interactive (browse-url-interactive-arg ,prompt)) 50 (interactive (browse-url-interactive-arg ,prompt))
47 (let* ((url (browse-url-encode-url url)) 51 (let* ((url (browse-url-encode-url url))
48 (process-environment (browse-url-process-environment))) 52 (process-environment (browse-url-process-environment)))
49 (message ,(format "Opening %%s in %s..." viewer) url) 53 (message ,(format "Opening %%s in %s..." viewer) url)
50 (apply #'start-process 54 (unless (ignore-errors
51 (concat ,viewer " " url) nil 55 (apply #'start-process
52 ,viewer 56 (concat ,viewer " " url) nil
53 (append ,(intern (format "%s-args" name)) (list url))))))) 57 ,viewer
58 (append ,(intern (format "%s-args" name))
59 (list url))))
60 (funcall fallback url new-window))))))
54 61
55;; Reference implementation: mpv 62;; Reference implementation: mpv
56(+browse-url-make-external-viewer-handler "mpv" nil "Video URL: ") 63(+browse-url-make-external-viewer-handler "mpv" nil "Video URL: ")