From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#75052: 31; browse-url-transform-alist is not used by secondary browser Date: Fri, 3 Jan 2025 10:18:09 -0600 Message-ID: References: <87cyhi6y3p.fsf@daniel-mendler.de> <87zfkl28vf.fsf@daniel-mendler.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13474"; mail-complaints-to="usenet@ciao.gmane.io" To: Daniel Mendler , 75052@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 03 17:20:12 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 1tTkPD-0003KY-K9 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Jan 2025 17:20:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkO8-0005aL-Rn; Fri, 03 Jan 2025 11:19: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 1tTkO7-0005Ys-3u for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2025 11: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 1tTkO6-0001Z5-Rt for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2025 11: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=Date:MIME-Version:References:In-Reply-To:From:To:Subject; bh=t/5RFjOmOGXfO6ZoMPCETBoOyZjtTBS2IFivxXi+YMU=; b=YlRnOEB0tFBFokpZ0ix2BnMUJSt1AX0R8JC/vWdqYD4bbnMJNruXD6QvzSyxeD72GekypPrpJxNBUsMW5V9UZ3D9WE85OahJ2GAk7JWuHLI1qjr0dWAWUg/dKZeSdrnpGlkglHfnNQDanww/4gVVpeAE6cJUGg7yhz8WCmQ5gBcYtd924XDqeqouHHncjs8dwuny+yxuffeLruneqHuYUvKfOIqMjB/3lrir4ew+ZCLDuEKs/TY9LxfSDJuWAXD75NywviNZSWTfETzrMkrvCOXJNRVsbeUNECPnSgNpYRnwBge7NBVV03PchfrA/Yjn723uMc/6XvoHS7uQlFm5Aw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tTkO6-0000Mt-0f for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2025 11:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Jan 2025 16:19:01 +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.17359210971343 (code B ref 75052); Fri, 03 Jan 2025 16:19:01 +0000 Original-Received: (at 75052) by debbugs.gnu.org; 3 Jan 2025 16:18:17 +0000 Original-Received: from localhost ([127.0.0.1]:51818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tTkNM-0000La-Qw for submit@debbugs.gnu.org; Fri, 03 Jan 2025 11:18:17 -0500 Original-Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:58761) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tTkNH-0000LM-RV for 75052@debbugs.gnu.org; Fri, 03 Jan 2025 11:18:14 -0500 Original-Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5cecbddb574so21676430a12.1 for <75052@debbugs.gnu.org>; Fri, 03 Jan 2025 08:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735921090; x=1736525890; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date:message-id:reply-to; bh=t/5RFjOmOGXfO6ZoMPCETBoOyZjtTBS2IFivxXi+YMU=; b=SJC/AOZ7RvNWpatEBYcHwGN7ONNAOmwoserJmAKmCobRD40Kxx9uzj+sZbN0Zfzn+L e8mEq7sgdIZ3+Ni5DIeBG4weq9PgjhN4K91+bpOP1H5tfxogTlHqcyUvPU0zKbE/5EJt zTKZYBZsaMhVre/Z2ndqfc5o318edCpvcKxnHBpTTs6f3qN7uTFPrOO7FpG3h7Ad1WE/ 5qhtjfEEJeBDo/zRueAohHArH3831N/8iRAeozgtwoSu5kdMq1SG+357IX49aNvGZ0aE oZl7vLd6GqE47/YPFejigcLjVsUurDMadTckHnbGAeKyblwNI7A1N8iV282T+aE1xiri XD1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735921090; x=1736525890; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t/5RFjOmOGXfO6ZoMPCETBoOyZjtTBS2IFivxXi+YMU=; b=jJFMXFJIPNn1cfv8/v/8tPKvsm+A3a0OqLuQScR5LC5UxDzqksKl9F3n7CZ21Ip76J +agfRA1kHP/t7/sqvool76hJsEl1s0Vb/POHxmly2AgAnfWLIxzasNvRH/Pb6uVWUnEB f4CXFExjQDLf5VcGsmLmfFWhvHNlwRwhZlNqjPL9+s6qQJT3NYgmthnw0s7hk4zhzROH kutCgscPG+KIBtLVoHtmOn0lD5TpKkATabAu9HmPk+1Qm8ALuXSZ4EmI0DwgIVkNNtby 5UW/DkeweNFZjX7UaWEb/qQn7A09vZ4iYJG2FCx2mqQ/oAOq6ph4f38vS+jKzpqOI1GM YaEA== X-Forwarded-Encrypted: i=1; AJvYcCXKjyUuYWLtCJWlPFOS4t8ummNq10lebzjPWsIHISl1obseSQyekd3BRh+DDMeMe8TEW+VQuQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0YymxrmWrcPGLUiLzmUdX9IXTvwcTPk455pHsWSS5MiVAfaB7q/Y I0R7WtgX0vR4nu4TwBEqdDmCifSCSTEi25UdVSSKa9HefPC/wvCJ5/EuGE5y1+bpV/TMr9SCwaU nZYExE5nHdHYDRn/5ePy55z6fBL0= X-Gm-Gg: ASbGncupFWAuiOjeLT7DEuZ1EE1tWBz8dut8bT6E8uHKeEgC76hMaTptzOaGihnpa2v IJp6RlJCazoMedCyNyrwLfQykbjvw1SZwsxt6Ch0v X-Google-Smtp-Source: AGHT+IHRlrp8zpIKVuB4KG8zgihU23sLi0zpCwiA31K5yB3pExG1nn1cc7U7RehfdkVtfp6rgP7q/JnuI6SypfpeBCE= X-Received: by 2002:a05:6402:3225:b0:5cf:3dc3:7a3f with SMTP id 4fb4d7f45d1cf-5d81ddd6563mr46317736a12.5.1735921090280; Fri, 03 Jan 2025 08:18:10 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 3 Jan 2025 10:18:09 -0600 In-Reply-To: <87zfkl28vf.fsf@daniel-mendler.de> 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:298290 Archived-At: Daniel Mendler writes: > Hello Stefan, > > you recently added `browse-url-transform-alist' to `browse-url'. At a > few places in Emacs browser functions are called directly. For direct > browser function calls the transformation alist is not applied. > > Examples: > > - `browse-url-secondary-browser-function' is called by > `browse-url-button-open' or by `package-browse-url' and others. > - `browse-url-with-browser-kind' calls browser functions directly. Thanks for identifying this issue, and for the patch! Sorry for the delay in reviewing it. > I've attached a patch which implements a `browse-url-with-function'. > However I am not sure if we want to add more `browse-url-*' function > variants, since this will make the `browse-url' API increasingly > unclear. There is definitely room to simplify the browse-url API, but let's separate the discussion about the Lisp programmer API from the user facing commands. I think the latter would be important to simplify, but in my view there is no catastrophe if we were to add a few more functions for Lisp programmers. > From 0b7edfc61aace7c692c04f1d0f7a6b6eb987b657 Mon Sep 17 00:00:00 2001 > From: Daniel Mendler > Date: Tue, 24 Dec 2024 01:31:35 +0100 > Subject: [PATCH] New function browse-url-with-function > > `browse-url-with-function' takes a browser function as argument, > the URL and rest arguments, which are passed to the browser > function. `browse-url-with-function' transforms the URL first > with `browse-url-transform-alist' before calling the browser > function. > > Calling browser functions directly is discouraged. Instead > `browse-url' or `browse-url-with-function' should be used, such > that URL transformations are applied. This last paragraph is fine, but should probably be moved to a code comment instead. Maybe it should be in Commentary? > diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el > index cebeb6d4c37..931952a2885 100644 > --- a/lisp/gnus/gnus-sum.el > +++ b/lisp/gnus/gnus-sum.el > @@ -9408,11 +9408,11 @@ gnus-shorten-url > (concat "#" target))))) > (concat host (string-truncate-left rest (- max (length host))))))) > > -(defun gnus-summary-browse-url (&optional external) > +(defun gnus-summary-browse-url (&optional secondary) > "Scan the current article body for links, and offer to browse them. > > -Links are opened using `browse-url' unless a prefix argument is > -given: then `browse-url-secondary-browser-function' is used instead. > +Links are opened using the primary browser unless a prefix argument is > +given. Then the secondary browser is used instead. > If only one link is found, browse that directly, otherwise use > completion to select a link. The first link marked in the I'm not sure this is an improvement, because this hides away the fact that you can customize which browser is being used. > @@ -957,6 +962,19 @@ browse-url > (apply function url args) > (error "No suitable browser for URL %s" url)))) > > +;;;###autoload > +(defun browse-url-with-function (func url &rest args) > + "Open URL with browser FUNC. > +If FUNC is a function use this function. > +If FUNC is nil use the `browse-url', which either calls a handler or the > +primary `browse-url-browser-function'. > +For other non-nil values use `browse-url-secondary-browser-function'." > + (if (not func) > + (apply #'browse-url url args) > + (apply > + (if (functionp func) func browse-url-secondary-browser-function) > + (browse-url--transform url) args))) I find the calls here rather unintuitive, for example I see calls like: (browse-url-with-function current-prefix-arg url) (browse-url-with-function secondary url) The `current-prefix-arg' and `secondary' are not really functions, so when I first read this code, I jumped at it and had to consult the docstring. I believe that the API would be simpler if we had two functions instead: (browse-url-with-function func url &rest args) (browse-url-with-secondary-browser url &rest args) This is not something you would jump at, but quite self-explanatory. I understand that you don't want to add more to an already messy API, but I think we should do more to simplify it elsewhere instead, which would offset the cost of doing that to some extent. Avoiding functions at the cost of more complex function interfaces doesn't strike me as a good tradeoff. We could also consider this idea: > An alternative could be to add keyword arguments to `browse-url' for > consolidation: > > For example: > (browse-url url :kind 'external) ;; replaces `browse-url-with-browser-kind' > (browse-url url :via some-function) ;; alternative to `browse-url-with-function' > (browse-url url :via secondary) First, it seems like `browse-url-with-browser-kind' is intended as a user-facing command, so replacing it with a keyword argument to browse-url won't work. As for the rest, I'd rather use something more direct and boring, because I find :via to be unclear. Here's what I'd do: (browse-url :function function) (browse-url :secondary t) Maybe this option is better than adding the new functions I proposed above?