Subject: [bug#68412] [PATCH v2] scripts: edit: Accept generic formatting parameter.

From: Simon Tournier <[email-masked]>
Date: Mon, 29 Jan 2024 12:10:54 +0100

Hi,

On sam., 13 janv. 2024 at 00:35, Liliana Marie Prikler <[email-masked]> wrote:

> +@vindex GUIX_EDITOR_LOCATION_FORMAT
> +The default convention used by @code{guix edit} when invoking
> +@code{$EDITOR} is to pass it @code{+@var{line} @var{file}} to open
> +@var{file} at the given @var{line}.
> +You can change this convention for editors that do not support it
> +by setting @env{GUIX_EDITOR_LOCATION_FORMAT}.
> +For instance, to set things up with kate, use:
> +
> +@example
> +export VISUAL=kate
> +export GUIX_EDITOR_LOCATION_FORMAT='--line=$@{LINE@} $@{FILE@}'
> +# Assume you want to hack on kate
> +guix edit kate
> +@end example

First, it appears to me inconsistent to speak about EDITOR and then to
use VISUAL in the example.  I suggest to have:

    The default convention used by @code{guix edit} when invoking
    @code{$EDITOR} or @code{VISUAL} is to pass it @code{+@var{line} @var{file}} to open

and the same example.  Or change the example and replace with:

    export EDITOR=kate
    export GUIX_EDITOR_LOCATION_FORMAT='--line=$@{LINE@} $@{FILE@}'

Second, I think that using markers that can be interpreted by Bash shell
can lead to confusion.  For instance,

    $ LINE=foo; FILE=bar # somewhere in my config for whatever reasons

then:

--8<---------------cut here---------------start------------->8---
$ export GUIX_EDITOR_LOCATION_FORMAT='--line=${LINE} ${FILE}'
$ echo $GUIX_EDITOR_LOCATION_FORMAT
--line=${LINE} ${FILE}

$ export GUIX_EDITOR_LOCATION_FORMAT="--line=${LINE} ${FILE}"
$ echo $GUIX_EDITOR_LOCATION_FORMAT
--line=foo bar
--8<---------------cut here---------------end--------------->8---

Well, simple quote versus double quote appears to me subtle.

Since it is an hard text replacement, why not remove $ and just have the
placeholder {LINE} or {FILE}?  Or <LINE> and <FILE>?  Or whatever that
is not interpreted by common shells.

> +Note, that Guix only matches the literal strings @code{$@{LINE@}} and
> +@code{$@{FILE@}} here.  These may look like shell parameters, but their
> +short form is currently not supported.

Therefore, it would make that more clear or even obsolete.

Cheers,
simon