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#75052: 31; browse-url-transform-alist is not used by secondary browser Date: Sat, 04 Jan 2025 12:17:59 +0100 Message-ID: <878qrqomjc.fsf@daniel-mendler.de> References: <87cyhi6y3p.fsf@daniel-mendler.de> <87zfkl28vf.fsf@daniel-mendler.de> <87frlz3kvs.fsf@daniel-mendler.de> Reply-To: Daniel Mendler Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18212"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 75052@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 04 12:19:28 2025 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 1tU2Bj-0004Yr-Ir for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Jan 2025 12:19:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tU2BP-0005yZ-5G; Sat, 04 Jan 2025 06:19:07 -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 1tU2BL-0005yQ-0Z for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:19: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 1tU2BK-0008Qo-L9 for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:19: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=QaeGGX6OD9ihVRCIJsKGZEElTC0WxRHonnxpM8I2BhI=; b=hQzpp3ILGYiBKLtAhbPSWRfLT6HjmAZZQgM282e2903VHgeliVzkeRT6zaMsOqYleCxReZE67HwfMy2sWuhWWMpu//nGCcYlB5Yx+pdUMCrubg51ZoMRDwv4ZwVMPj3QPvw0ybj0tPwGyGcVKChUsUTPOv65czCxocwZK5FwAAbyYIGIyX70Jbnj/SHpdYqYikRI2sLZajo1B+A7bbY3Yb0s7Rgz6/TbAKGS5zMucKFL0Z4NYFZhhrD4QvaW/G4CWPbD6+c0tSIKuaWb5WZpt6k47AMpDx1oMNF/nGVBvv83/eERPLE/Yj4tUuntKFnq89XdWN4XoWRQOW/x2wMY9A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tU2BK-0001t7-9z for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:19: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: Sat, 04 Jan 2025 11:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75052 X-GNU-PR-Package: emacs Original-Received: via spool by 75052-submit@debbugs.gnu.org id=B75052.17359894917198 (code B ref 75052); Sat, 04 Jan 2025 11:19:02 +0000 Original-Received: (at 75052) by debbugs.gnu.org; 4 Jan 2025 11:18:11 +0000 Original-Received: from localhost ([127.0.0.1]:53546 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tU2AV-0001s2-2O for submit@debbugs.gnu.org; Sat, 04 Jan 2025 06:18:11 -0500 Original-Received: from server.qxqx.de ([2a01:4f8:c012:9177::1]:55813 helo=mail.qxqx.de) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tU2AS-0001rK-6y for 75052@debbugs.gnu.org; Sat, 04 Jan 2025 06:18:09 -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=QaeGGX6OD9ihVRCIJsKGZEElTC0WxRHonnxpM8I2BhI=; b=QnjMyfkRQ8myFy+Z9iumWKYHzV xr9zg3yOgU8OcTw3eq5z5IEEf16On9DwF5z8a7+UP2xmk7b0A2t1+efSEVViu0yIhoqNPxIUC+yFx t1qZjGQaYthNCxP7CaGvTSzNrfdifeitWJppuY1X1WYJuXXl0wegakGF/O6Q9RAZ2dvc=; In-Reply-To: (Stefan Kangas's message of "Fri, 3 Jan 2025 20:55:56 -0600") 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:298359 Archived-At: Stefan Kangas writes: >> Another perhaps simpler and significantly more minimal approach would be >> to let-bind `browse-url-browser-function' to >> `browse-url-secondary-browser-function' at all call-sites instead of >> calling `browse-url-secondary-browser-function' directly. Inside the >> let, `browse-url' would be called as usual. >> >> However the problem with that approach is that it wouldn't be entirely >> backward compatible, since the `browse-url-handlers' take precedence >> over the `browse-url-browser-function'. In order to circumvent this >> problem we could introduce a new variable >> `browse-url-override-browser-function' which would take precedence in >> `browse-url'. `package-browse-url' would become the following: >> >> #+begin_src emacs-lisp >> (defun package-browse-url (desc &optional secondary) >> (interactive (list (package--query-desc) current-prefix-arg) >> package-menu-mode) >> (unless desc >> (user-error "No package here")) >> (let ((url (cdr (assoc :url (package-desc-extras desc)))) >> (browse-url-override-browser-function >> (and secondary browse-url-secondary-browser-function))) >> (unless url >> (user-error "No website for %s" (package-desc-name desc))) >> (browse-url url))) >> #+end_src >> >> However this small incompatibility may even be acceptable. In case URL >> handlers are defined, you may want them to take precedence in any case. >> >> I believe the problem is only pronounced in >> `browse-url-with-browser-kind' which under all circumstances wants to >> use the browser function it has chosen. In order to achieve that it >> could let-bind `browse-url-handlers' and `browse-url-default-handlers' >> to nil. The function would become this: >> >> #+begin_src emacs-lisp >> (defun browse-url-with-browser-kind (kind url &optional arg) >> (interactive ...) >> (let ((function (browse-url-select-handler url kind))) >> (unless function >> (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)))) >> ;; Ensure that function is used >> (let ((browse-url-browser-function function) >> (browse-url-default-handlers nil) >> (browse-url-handlers)) >> (browse-url url arg)))) >> #+end_src > > I quite like this idea, and I think it buys us some improvements even, > as you detail above, while the compatibility issues are fixed with the > new variable. > > This is the only idea so far that guarantees that the environment > variables, etc., that we set now and in future in `browse-url`, are used > also for the secondary browser. IIUC, it would also give us exactly one > function that Lisp programs should normally call: `browse-url`. Yes, it is best if all calls just go through `browse-url'. Also we avoid adding more functions such that the API isn't made more complex. Just to be clear - I think we don't actually need the override variable if we accept a minor change in behavior with respect to the handlers. If a specific handler is defined we may always want it to take precedence, except in the case of `browse-url-with-browser-kind', but there we can simply rebind the handler variables to nil. > Could you perhaps send a patch? Yes, I'll send a patch and then you can take another look. Daniel