Subject: [PATCH] 30.0.92; eww-browse-with-external-browser and eww-follow-link should use browse-url-with-browser-kind

From: Daniel Mendler <[email-masked]>
Date: Sat, 07 Dec 2024 23:02:09 +0100

Tags: patch

The command `eww-browse-with-external-browser' uses
`browse-url-secondary-browser-function'. This makes the command
ineffective in the common setup where
`browse-url-secondary-browser-function' is set to `eww-browse-url' and
`browse-url-browser-function' is set to an external browser.

Fortunately we can use `browse-url-with-browser-kind' instead, which
guarantees that an external browser is launched.

Furthermore `eww-follow-link' should use `browse-url-with-browser-kind'
if the EXTERNAL prefix argument is non-nil.

I've looked at all other uses of `browse-url-browser-function' and
`browse-url-secondary-browser-function' in the Emacs code base and I
have not found other problems. Most commands use a prefix argument to
switch to the secondary browser, relying on the primary browser by
default. The problem is limited to `eww-browse-with-external-browser'
and `eww-follow-link'.

In GNU Emacs 30.0.92 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.2, Xaw scroll bars) of 2024-11-20

>From 361b9d970631b3547bd859fb8686597e651447ce Mon Sep 17 00:00:00 2001
From: Daniel Mendler <[email-masked]>
Date: Sat, 7 Dec 2024 22:56:15 +0100
Subject: [PATCH] eww: Use browse-url-browser-kind for external browsing

Guarantee that an external browser is used by Eww even if
`browse-url-secondary-browser-function' is set to `eww-browse-url'.

* lisp/net/eww.el (eww-browse-with-external-browser): Use
`browse-url-with-browser-kind'.
(eww-follow-link): Use `browse-url-with-browser-kind' if the
EXTERNAL prefix argument is non-nil.
---
 lisp/net/eww.el | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 4d4d4d6beac..bace519c7c4 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -2141,12 +2141,11 @@ eww-submit
 	(mm-url-encode-www-form-urlencoded values))))))
 
 (defun eww-browse-with-external-browser (&optional url)
-  "Browse the current URL with an external browser.
-The browser to used is specified by the
-`browse-url-secondary-browser-function' variable."
+  "Browse the current URL with an external browser."
   (interactive nil eww-mode)
-  (funcall browse-url-secondary-browser-function
-           (or url (plist-get eww-data :url))))
+  (browse-url-with-browser-kind
+   'external
+   (or url (plist-get eww-data :url))))
 
 (defun eww-remove-tracking (url)
   "Remove the commong utm_ tracking cookies from URLs."
@@ -2161,9 +2160,7 @@ eww--transform-url
 
 (defun eww-follow-link (&optional external mouse-event)
   "Browse the URL under point.
-If EXTERNAL is single prefix, browse the URL using
-`browse-url-secondary-browser-function'.
-
+If EXTERNAL is single prefix, browse the URL using an external browser.
 If EXTERNAL is double prefix, browse in new buffer."
   (interactive
    (list current-prefix-arg last-nonmenu-event)
@@ -2180,7 +2177,7 @@ eww-follow-link
       ;; and `browse-url-mailto-function'.
       (browse-url url))
      ((and (consp external) (<= (car external) 4))
-      (funcall browse-url-secondary-browser-function url)
+      (browse-url-with-browser-kind 'external url)
       (shr--blink-link))
      ;; This is a #target url in the same page as the current one.
      ((and (setq target (url-target (url-generic-parse-url url)))
-- 
2.45.2