unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#75052: 31; browse-url-transform-alist is not used by secondary browser
@ 2024-12-23 18:41 Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-12-24  1:00 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-23 18:41 UTC (permalink / raw)
  To: 75052; +Cc: Stefan Kangas

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-24  1:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-23 18:41 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
2024-12-24  1:00 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors

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).