Subject: bug#74781: [PATCH] Add `browse-url-qutebrowser'

From: Daniel Mendler <[email-masked]>
Date: Wed, 11 Dec 2024 15:38:13 +0100

Björn Bidar <[email-masked]> writes:

> Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <[email-masked]> writes:
>
>> Robert Pluim <[email-masked]> writes:
>>
>>>>>>>> On Wed, 11 Dec 2024 10:07:08 +0100, Daniel Mendler <[email-masked]> said:
>>> The emacs help system applies heuristics which are not always
>>> accurate, and donʼt always return an answer, hence the version tags.
>>
>> Thanks, I added the version tags. See the updated patch.
>>
>>>     >> We have `xdg-runtime-dir' in xdg.el
>>>
>>>     Daniel> The goal was to avoid loading `xdg.el' unnecessarily for this trivial
>>>     Daniel> function, which is just a wrapper around `getenv'. Do you suggest to use
>>>     Daniel> `declare-function' and require xdg inside `browse-url-qutebrowser-send'?
>>>
>>> That would work.
>>
>> I would be pragmatic and keep the (getenv "XDG_RUNTIME_DIR"), instead
>> of replacing it by this:
>>
>> (declare-function xdg-runtime-dir "xdg")
>> (require 'xdg)
>
> These are only required because you load a new dependency.
> Further these functions can take care of later eventualities if needed,
> e.g. such as handling when a xdg variable isn't set.
> Also using these functions makes the code easier to read as you can
> follow the code down further to the documentation.

The entire function looks like this:

(defun xdg-runtime-dir ()
  (getenv "XDG_RUNTIME_DIR"))

No eventualities are handled there right now, so it does not seem
justified to load xdg.el only for this small wrapper. Note that
`browse-url' contains other platform-specific code, including
xdg-related code, without loading xdg.el - all the code around
`browse-url-xdg-open'.

See also the files files.el, server.el, startup.el and mpc.el, which all
access XDG_* environment variables via `getenv' without requiring
xdg.el. The `getenv' function calls are certainly not less readable than
`xdg-runtime-dir'.

That being said, I would not mind if there was a (require 'xdg) at the
top of the browse-url.el file, if that's considered acceptable, even on
systems which do not conform to xdg. For example xdg.el is also required
unconditionally by eww.el and xdg is a fairly small library. Then using
`xdg-runtime-dir' would be the better solution of course.

Daniel