Subject: bug#74820: closed (Re: bug#74820: [PATCH] browse-url-with-browser-kind: Improve browser function selection)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 21 Dec 2024 09:35:02 +0000

Your bug report

#74820: [PATCH] browse-url-with-browser-kind: Improve browser function selection

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
74820: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74820
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#74820: [PATCH] browse-url-with-browser-kind: Improve browser function selection
From: Eli Zaretskii <[email-masked]>
To: Daniel Mendler <[email-masked]>
Cc: [email-masked]
Date: Sat, 21 Dec 2024 11:34:45 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Thu, 12 Dec 2024 12:41:50 +0100
> From:  Daniel Mendler via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> 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'.

Thanks, I've now installed this on the master branch, and I'm
therefore closing this bug.

Subject: [PATCH] browse-url-with-browser-kind: Improve browser function selection
From: Daniel Mendler <[email-masked]>
To: [email-masked]
Date: Thu, 12 Dec 2024 12:41:50 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

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'.

>From f2972d6074e314e43fbb9630e5b597ff2ae47b22 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <[email-masked]>
Date: Thu, 12 Dec 2024 12:15:10 +0100
Subject: [PATCH] browse-url-with-browser-kind: Improve browser function
 selection

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.
---
 lisp/net/browse-url.el | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 10165465921..e43f96c1fd5 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -976,7 +976,13 @@ browse-url-at-point
 ;;;###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'."
@@ -996,9 +1002,14 @@ browse-url-with-browser-kind
      (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
-- 
2.45.2