unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 75052@debbugs.gnu.org
Cc: Stefan Kangas <stefankangas@gmail.com>
Subject: bug#75052: 31; browse-url-transform-alist is not used by secondary browser
Date: Mon, 23 Dec 2024 19:41:30 +0100	[thread overview]
Message-ID: <87cyhi6y3p.fsf@daniel-mendler.de> (raw)

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.

A possible solution could be to add a function
`browse-url-with-function' which takes a function argument:

(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 default `browse-url'.
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)))

All call sites which call a browse function directly could use
`browse-url-with-function' instead. Calling browser functions directly
should be discouraged. For example `package-browse-url' would simplify
to this:

(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)))))
    (unless url
      (user-error "No website for %s" (package-desc-name desc)))
    (browse-url-with-function secondary url)))

Similarly `browse-url-with-browser-kind':

(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))))
    (browse-url-with-function function url arg)))

Does this sound like an acceptable plan? Thank you.

Daniel





             reply	other threads:[~2024-12-23 18:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-23 18:41 Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-24  1:00 ` bug#75052: 31; browse-url-transform-alist is not used by secondary browser Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-03 16:18   ` Stefan Kangas
2025-01-03 16:47     ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-04  2:55       ` Stefan Kangas
2025-01-04 11:17         ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-04 11:59           ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cyhi6y3p.fsf@daniel-mendler.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=75052@debbugs.gnu.org \
    --cc=mail@daniel-mendler.de \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).