On 2023-10-13 01:06, Christoph Anton Mitterer wrote:
On Fri, 2023-10-13 at 00:36 +0200, Dragan Simic wrote:
It seems that "--redraw-on-quit" is a possible candidate for
replacing "-X" in the set of default options for less(1)
*If* some changes were made to how git handles this, it might perhaps
be worth to consider not to touch LESS at all, but only add the
required settings via command line arguments (i.e. -F -R ...).
Actually, that would be wrong. If someone sets $LESS or $PAGER (or
$GIT_PAGER, more specifically), it's up to the utility that invokes the
pager internally not to override the user preferences configured through
these environment variables. That's how everyone can customize the
pager behavior.
Or perhaps only remove options from it, if they're known to break the
behaviour with git (like -+R might).
Again, not the way the whole thing with pagination works. If someone
sets their environment variables wrong, it's simply the way they want
it, and it isn't anyone else's business to attempt fixing it
automatically.
I always feel configuration via env vars is a bit fragile:
- especially when one has generic names like POSIXLY_CORRECT there's
some chance that by exporting it to one program, where one wants the
effect, another program started off by that also gets it
unintentionally
- generic terms may be used by multiple programs, causing problems
Well, fragile or not, that's the way it works. It has its downsides for
sure, but it's all about having each utility handle the environment
carefully and document it in its man page(s), so the users can also
carefully craft the values of their customized environment variables.
Also, if one can set only one LESS var in the environment, not one for
less "alone", one for less with git, etc. - that is unless for programs
like bat/delta which have specific own env vars to set the pager.
$LESS can be seen as a global set of the common options for less(1),
which may include the coloring configuration or the enablement of
case-insensitive search, for example, while $MANPAGER, $GIT_PAGER and
$BAT_PAGER may contain utility-specific options for less(1). That's
actually very good, because it makes possible to avoid duplication of
the common options.
So if I set e.g. LESS to something, than typically only to stuff from
which I believe it works as expected for any possible users.
E.g. -F might be such a case.
It's up to everyone to decide what are the common options for less(1)
that they want to set in $LESS.
But if I do that, git won't touch LESS and set the required -R, so I
have to do that manually for git, e.g. either via git_config or by
defining an alias git='LESS=FRX git'.
You don't have to define an alias, there's $GIT_PAGER for that purpose,
as I already explained above.
Moreover, the whole idea of the various utilities touching the $LESS
variable internally is to provide sane defaults to the users that don't
configure $LESS, $PAGER, etc. on their own. Once the user starts to
provide their own environment variable(s), it's no longer up to the
utility to help the user by altering their environment configuration.
But in both cases it would "break" again, should ever another option be
needed and added by git to the default LESS (which is however only set
when it's unset).
And in case of an alias, there would be the additional problem, that
it's typically not picked up in non-interactive shells.
As you can see in my replies, it isn't about taking care of the users
who provide their own environment configuration. It's all about
providing the set of sane defaults, for the users with no custom
configuration.
Long story short, it might make sense for git, to (mostly) ignore LESS
and rather invoke less with -F -R.
No, that would be wrong on multiple levels, as I already explained in
detail.
The problem with that in turn would of course be that it doesn't
automatically propagate down, if e.g. git's pager is set to detla and
delta in turn runs less.
However, that's IMO litte concern, since then it's delta's duty to set
-R (if it think it needs to do so), which it actually does.
I don't know what delta is and how it actually paginates its outputs,
but it should follow the rules of the environment-based pager
configuration that I described in detail above.