From: Daniel Mendler Date: Sat, 7 Dec 2024 21:56:15 +0000 (+0100) Subject: eww: Use browse-url-with-browser-kind in eww-browse-with-external-browser X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=21411d74e314120330c270c71cbd19b5245d872d;p=emacs.git eww: Use browse-url-with-browser-kind in eww-browse-with-external-browser Guarantee that an external browser is used by EWW if `browse-url-secondary-browser-function' is set to `eww-browse-url'. * lisp/net/eww.el (eww-browse-with-external-browser): Use `browse-url-secondary-browser-function' only if it is an external browser, otherwise fall back to `browse-url-with-browser-kind'. (eww-follow-link): Use `eww-browse-with-external-browser' if the EXTERNAL prefix argument is non-nil. Improve docstring. * lisp/net/browse-url.el (browse-url-secondary-browser-function): Update docstring. (Bug#74730) (cherry picked from commit a3610381ff65490da33cd1870dd3dfd491bff06f) --- diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 55c31df989d..389a9eb112f 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -197,10 +197,16 @@ Also see `browse-url-secondary-browser-function' and (defcustom browse-url-secondary-browser-function 'browse-url-default-browser "Function used to launch an alternative browser. -This is usually an external browser (that is, not eww or w3m), -used as the secondary browser choice, typically when a prefix -argument is given to a URL-opening command in those modes that -support this (for instance, eww/shr). + +This browser is used as the secondary browser choice, typically +when a prefix argument is given to a URL-opening command in those +modes that support this (for instance `browse-url-at-point', +`goto-addr-at-point', eww or shr). + +This assumption is that `browse-url-secondary-browser-function' +and `browse-url-browser-function' are set to distinct browsers. +Either one of the two functions should call an external browser +and the other one should not do the same. Also see `browse-url-browser-function'." :version "27.1" diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 6c9851f6f1c..1f1d2069cf7 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -2132,11 +2132,15 @@ Interactively, EVENT is the value of `last-nonmenu-event'." (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." +Use `browse-url-secondary-browser-function' if it is an external +browser, otherwise use `browse-url-with-browser-kind' to open an +external browser." (interactive nil eww-mode) - (funcall browse-url-secondary-browser-function - (or url (plist-get eww-data :url)))) + (setq url (or url (plist-get eww-data :url))) + (if (eq 'external (browse-url--browser-kind + browse-url-secondary-browser-function url)) + (funcall browse-url-secondary-browser-function url) + (browse-url-with-browser-kind 'external url))) (defun eww-remove-tracking (url) "Remove the commong utm_ tracking cookies from URLs." @@ -2150,11 +2154,12 @@ The browser to used is specified by the 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'. + "Browse the URL at point, optionally the position of MOUSE-EVENT. -If EXTERNAL is double prefix, browse in new buffer." +EXTERNAL is the prefix argument. If called interactively with +\\[universal-argument] pressed once, browse the URL using +`eww-browse-with-external-browser'. If called interactively, with +\\[universal-argument] pressed twice, browse in new buffer." (interactive (list current-prefix-arg last-nonmenu-event) eww-mode) @@ -2170,7 +2175,7 @@ If EXTERNAL is double prefix, browse in new buffer." ;; and `browse-url-mailto-function'. (browse-url url)) ((and (consp external) (<= (car external) 4)) - (funcall browse-url-secondary-browser-function url) + (eww-browse-with-external-browser 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)))