From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74730: [PATCH] 30.0.92; eww-browse-with-external-browser and eww-follow-link should use browse-url-with-browser-kind Date: Sun, 08 Dec 2024 18:39:28 +0100 Message-ID: <87h67e3whb.fsf@daniel-mendler.de> References: <87frmz40f2.fsf@daniel-mendler.de> <86ikruhg3q.fsf@gnu.org> <874j3ed487.fsf@daniel-mendler.de> <86r06ifkn7.fsf@gnu.org> <8734iycos7.fsf@daniel-mendler.de> <86msh6fggg.fsf@gnu.org> Reply-To: Daniel Mendler Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30887"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74730@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 08 18:40:33 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tKLGi-0007sT-Pl for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 08 Dec 2024 18:40:32 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tKLGH-00023y-6j; Sun, 08 Dec 2024 12:40:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tKLGF-00022k-1y for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 12:40:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tKLGE-0008Gg-Lv for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 12:40:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=WBMIUzY/9u0yNIAoX9Zx0CR1lC7OuzlicNKjES2AIbc=; b=bTmz5MJGLREu2bUlOiqnVOtYLC3BjhNdEmBj9Lcy+CCdNnT3udSX6TaZphO2qXh0lNMZ8NxY6v+s+s6a+oillmI8r1yYk+iMIv34p9TJf0+I/caEmqG8YEXw4vEnrBpmUdCJzCssV7Ab8iVTHnOqqtyOuu4secub9WO+OSF/OLfxIsLYiQ6n3f0erL6UAi0XaMxh8GJbMdBBAye2BlHc2ucxU4fc6vJZPez+ZD1C8HyxoOv/xuIqc0DSUmzU48UPDFxg8CqAw9liHcdsN3Ad2TrfaIMHQw5QXs4kU2EDrfBfdrX/wZhkRViMmLuL8431bVDZ2ci6nxOpCY4bQEHfHg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tKLGE-0005Of-Hl for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 12:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Dec 2024 17:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74730 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74730-submit@debbugs.gnu.org id=B74730.173367957920695 (code B ref 74730); Sun, 08 Dec 2024 17:40:02 +0000 Original-Received: (at 74730) by debbugs.gnu.org; 8 Dec 2024 17:39:39 +0000 Original-Received: from localhost ([127.0.0.1]:51598 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKLFq-0005Ni-HT for submit@debbugs.gnu.org; Sun, 08 Dec 2024 12:39:39 -0500 Original-Received: from server.qxqx.de ([49.12.34.165]:53379 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKLFo-0005NF-Cm for 74730@debbugs.gnu.org; Sun, 08 Dec 2024 12:39:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=daniel-mendler.de; s=key; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WBMIUzY/9u0yNIAoX9Zx0CR1lC7OuzlicNKjES2AIbc=; b=V0eapLTQoVK7/l8L6dnCcwVMGB w7HD8ybbHT2Yn+d3FlVNsSiIPE0LyVf3O7x5Qsmj9+mJVamVwn2Y5E06yrXPVL90KpM1XAboK6/SO eNBRljdSlWYWyE2yFpoJTnwe2N4YoySzRmTV+bI54anhfSsgaQ1ngKhy3+JOAP4tCEa0=; In-Reply-To: <86msh6fggg.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 08 Dec 2024 15:32:31 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296657 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: Updated patch attached. >> (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 is 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 `goto-addr-at-point', eww or shr). > > This doc string should explain the assumptions about this and the > other variable, browse-url-browser-function: that either one or the > other invokes the external browser, and the other one should then NOT > do the same. Users should be aware and understand the rules of the > game here, which are now slightly more complex than they were before, > so removing the previous assumption without replacing it with anything > makes the doc string less useful. I expanded the docstring. >> (interactive nil eww-mode) >> - (funcall browse-url-secondary-browser-function >> + (funcall (if (memq browse-url-secondary-browser-function >> + '(eww eww-browse-url)) >> + #'browse-url >> + browse-url-secondary-browser-function) > > I think we should allow here (and document) more just 2 literal > functions hard-coded in this command. Perhaps some special property > on the function's symbol? Then these two specific functions can be > supported via the property, and what's more important, users and > applications could use other functions with the same semantics. In this case I think it is better to use `browse-url-with-browser-kind' as I had initially suggested. This will be better than introducing yet another property only for this purpose. >> (defun eww-follow-link (&optional external mouse-event) >> "Browse the URL under point. >> If EXTERNAL is single prefix, browse the URL using > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > What does this mean? does it mean that EXTERNAL is non-nil in > interactive usage if the command is invoked with C-u? If so, let's > say that. (Yes, I know that problem came from the original doc > string.) I improved the docstring. >> @@ -2180,7 +2182,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) >> + (eww-browse-with-external-browser url) > > I'm not sure I agree. The call to eww-browse-with-external-browser > will no longer ensure an external browser is used, after these > changes. Why not call browse-url-default-browser instead? Now, it is ensured that the external browser is called. Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-eww-Use-browse-url-with-browser-kind-in-eww-browse-w.patch >From f56022cc4b1f9c007ba583ece8f2c714a92eefc6 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 7 Dec 2024 22:56:15 +0100 Subject: [PATCH] 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. --- lisp/net/browse-url.el | 14 ++++++++++---- lisp/net/eww.el | 23 ++++++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index c10bc671a88..8ec025d017b 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -198,10 +198,16 @@ browse-url-browser-function (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 4d4d4d6beac..4609755a902 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -2142,11 +2142,15 @@ eww-submit (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." @@ -2160,11 +2164,12 @@ eww--transform-url 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) @@ -2180,7 +2185,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) + (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))) -- 2.45.2 --=-=-=--