Better mechanism to choose the default editor (and avoid vi if possible)?
PIERRE AUGIER
pierre.augier at univ-grenoble-alpes.fr
Wed Jun 10 21:08:40 UTC 2020
----- Mail original -----
> De: "Manuel Jacob" <me at manueljacob.de>
> À: "PIERRE AUGIER" <pierre.augier at univ-grenoble-alpes.fr>
> Cc: "mercurial" <mercurial at mercurial-scm.org>
> Envoyé: Mercredi 10 Juin 2020 21:17:27
> Objet: Re: Better mechanism to choose the default editor (and avoid vi if possible)?
> On 2020-06-08 15:43, PIERRE AUGIER wrote:
>> ----- Mail original -----
>>> De: "Marcus Harnisch" <mh-mercurial at online.de>
>>> À: "mercurial" <mercurial at mercurial-scm.org>
>>> Envoyé: Dimanche 7 Juin 2020 13:35:06
>>> Objet: Re: Better mechanism to choose the default editor (and avoid vi
>>> if possible)?
>>
>>> On 06/06/2020 23.24, Manuel Jacob wrote:
>>>> In my opinion, on a UNIX-style system, if a distribution targets an
>>>> audience that includes non-power users, it’s the responsibility of
>>>> the
>>>> distribution to set $VISUAL or $EDITOR to a user-friendly default, or
>>>> patch Mercurial to choose a user-friendly default. We should refrain
>>>> from doing the distribution’s job. If every application had its own
>>>> way
>>>> of choosing an editor, the result wouldn’t be very user-friendly.
>>
>> I know at least one distribution targeting "non-power users" (Ubuntu)
>> which does not set $VISUAL or $EDITOR by default and does not patch
>> Mercurial.
>
> Technically, it’s not patching, but the Debian (and subsequently Ubuntu)
> package installs /etc/mercurial/hgrc.d/default-tools.rc, which sets the
> editor to `sensible-editor` and the pager to `sensible-pager`. Do you
> have this file?
The problem with the Mercurial packages in Debian and Ubuntu is the versions.
In my lab, `/usr/bin/hg -v` gives 4.0. Even at home, before 20.04, I was running Ubuntu 18.04 which installs hg 4.5.
Since I'd like to avoid hg < 4.8, I started to install from source. I used to install Mercurial with pip but after very bad experiences with students on Windows and MacOS (in particular with dulwich and hg-git), I develop conda-app, a tool for my students and colleagues to install Mercurial+hg-git+evolve everywhere with the same commands (and without compilation). It's very convenient in classes when students/people come with very different systems (and we know that they have conda installed).
Anyway, at home and even in my lab (Debian) where hg is installed with apt-get, I don't have /etc/mercurial/hgrc.d/default-tools.rc.
> Which editor does `sensible-editor` open on your
> machine? `sensible-editor` falls back to nano before it falls back to
> vi.
sensible-editor opens nano but unfortunately it is unusable! ctr-X prints ^X and the arrows print ^[OC^[OD^[OD^[OC^[OD^[OC.
In contrast `editor` opens nano correctly.
>
>> Do you know a distribution that does something like that? Note also
>> that most potential Mercurial users not very used to command-line
>> tools (students, scientists, ...) on Unix-like OS use something close
>> to Debian/Ubuntu, Fedora or macOS.
>>
>> The default editor for Mercurial is used only if no editor has been
>> defined by other standard methods. We are here considering only this
>> special case (which is not so uncommon, especially for beginners).
>> Trying not to open vi by default in this case does not prevent
>> distributions / administrators to set a particular editor.
>
> For the record, I agree that vi is a terrible default. People unfamiliar
> with it are lost. People familiar with it will probably use at least
> vim. I don’t know anyone who uses vi. For me as a vim user, vi is
> confusing because it’s a bit of vim, but it’s not vim.
>
> Still, I don’t think that Mercurial should make this decision. I’m sure
> that someone could come up with reasons why nano is not a good default
> and the same for any other editor. If you start this kind of discussion,
> you end up with people discussing their favorite vi clone on this
> mailing list (this actually happened).
>
> I would prefer if instead of falling back to vi, Mercurial shows a nice
> error message describing how to set an editor.
Yes, it would clearly be better than falling back to vi.
Another alternative would be that Mercurial explains the situation (no editor defined), asks which editor has to be used (with a reasonable default depending on the OS and a small list of reasonable choices, like for example `nano` if it is installed, `vim` if it is installed, `emacs -Q -nw` if emacs is installed), writes the answer in ~/.hgrc and finally uses the chosen editor.
More information about the Mercurial
mailing list