]> git.eshelyaron.com Git - emacs.git/commitdiff
browse-url-with-browser-kind: Improve browser function selection
authorDaniel Mendler <mail@daniel-mendler.de>
Thu, 12 Dec 2024 11:15:10 +0000 (12:15 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:19:17 +0000 (16:19 +0100)
In order to find an appropriate browser function for the given
kind, first the browser handler lists are consulted.  If no
handler is found, the `browse-url-browser-function',
`browse-url-secondary-browser-function`,
`browse-url-default-browser' and `eww' are tried in that order
until a browser function with a matching kind is found.  This
way the user customization of `browse-url-browser-function' and
`browse-url-secondary-browser-function` is respected by
`browse-url-with-browser-kind'.
* lisp/net/browse-url.el (browse-url-with-browser-kind): Try the
browser functions in the aforementioned order.  (Bug#74820)

(cherry picked from commit 0f645b92ed3e82f149de468df7ebe0eda5104aca)

lisp/net/browse-url.el

index f50cf29365e97eb494993e4ba0025eb217b4e8c0..b5c4fe112b1fda19f8dd520bc3009543371426c4 100644 (file)
@@ -973,7 +973,13 @@ Optional prefix argument ARG non-nil inverts the value of the option
 ;;;###autoload
 (defun browse-url-with-browser-kind (kind url &optional arg)
   "Browse URL with a browser of the given browser KIND.
-KIND is either `internal' or `external'.
+
+KIND is either `internal' or `external'.  In order to find an
+appropriate browser for the given KIND, first the `browse-url-handlers'
+and `browse-url-default-handlers' lists are consulted.  If no handler is
+found, the functions `browse-url-browser-function',
+`browse-url-secondary-browser-function', `browse-url-default-browser'
+and `eww' are tried in that order.
 
 When called interactively, the default browser kind is the
 opposite of the browser kind of `browse-url-browser-function'."
@@ -993,9 +999,14 @@ opposite of the browser kind of `browse-url-browser-function'."
      (cons k url-arg)))
   (let ((function (browse-url-select-handler url kind)))
     (unless function
-      (setq function (if (eq kind 'external)
-                         #'browse-url-default-browser
-                       #'eww)))
+      (setq function
+            (seq-find
+             (lambda (fun)
+               (eq kind (browse-url--browser-kind fun url)))
+             (list browse-url-browser-function
+                   browse-url-secondary-browser-function
+                   #'browse-url-default-browser
+                   #'eww))))
     (funcall function url arg)))
 
 ;;;###autoload