Re: Inconsistency between fc and C-x C-e

2022-06-10 Thread Chet Ramey

On 6/9/22 8:37 PM, Luciano wrote:



On Wed, Jun 08, 2022 at 05:49:52PM -0400, Greg Wooledge wrote:

You could create a wrapper script, put it in your $HOME/bin/ directory
(and make sure that's in PATH), and then set EDITOR to that wrapper.
That should be much more reliable, especially if other programs also
use $EDITOR (which they might).

Yes, I think that's the most reasonable thing to do, and I'm going to do
that.


It's consistent with what POSIX specifies.



On Thu, Jun 09, 2022 at 11:40:26AM -0400, Chet Ramey wrote:

The edit-and-execute-command key binding runs

fc -e "${VISUAL:-${EDITOR:-emacs}}"

[...] while the fc command without options runs (internally)

"${FCEDIT:-${EDITOR:-vi}}"

Well that explains it!  is there a reason why fc -e is used here for C-x C-e
instead of just plain "${VISUAL:-${EDITOR:-emacs}}" ?


I'm not sure I understand the question. You need to invoke fc to get the
right behavior: get a line from the history list, edit it, and execute the
result. It's a waste to duplicate code to do the same thing.

The default editor string is different because `fc' is supposed to default
to $FCEDIT and it would be unexpected for the C-xC-e key binding to use
that if it's defined.



By the way, git seems to interpret the EDITOR variable in a way
consistent with C-x C-e, while the pass program as I said seems to just
execute $EDITOR, like fc. I wonder if POSIX leaves room for interpretation here.


POSIX says little about the value of EDITOR, but makes it an application
requirement (the same thing as a user requirement) for the argument to
`fc -e' to be "a utility name, subject to search via the PATH variable."
Since $FCEDIT is the default editor, the same requirement holds for it
after expansion.

It's historical convention that VISUAL and EDITOR are subject to the same
restriction, but they are not described separately in the POSIX Environment
Variables section. (And yes, historically they were different and had
different requirements.)

The POSIX utilities that use $EDITOR don't say much, either, but the mailx
description makes it clear that EDITOR needs to expand to a command name
("the name of a utility to invoke").


Anyway, any sane person would probably just follow Greg's advice.


It provides maximum flexibility.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: Inconsistency between fc and C-x C-e

2022-06-10 Thread Chet Ramey

On 6/9/22 11:57 PM, Lawrence Velázquez wrote:

On Thu, Jun 9, 2022, at 8:37 PM, Luciano wrote:

By the way, git seems to interpret the EDITOR variable in a way
consistent with C-x C-e, while the pass program as I said seems to just
execute $EDITOR, like fc. I wonder if POSIX leaves room for
interpretation here.


It does, insofar as it barely concerns itself with EDITOR at all.
It only specifies that the "crontab", "fc", "mailx", and "more"
utilities use EDITOR and advises other applications to avoid using
it in a conflicting manner.  (The descriptions of the aforementioned
utilities are not all that detailed vis-à-vis EDITOR and could
reasonably be interpreted as allowing either method, but it doesn't
really matter as far as other utilities are concerned.)


I didn't look at more than mailx, but the description there makes it clear
that $EDITOR needs to expand to a command name. `more' has similar wording
("The name of the editor shall be taken from the environment variable
EDITOR.") and talks about what to do if the last pathname component in
$EDITOR is `vi' or `ex'.

As I said in a different message, historical convention is that these are
command names.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: Inconsistency between fc and C-x C-e

2022-06-10 Thread Lawrence Velázquez
On Fri, Jun 10, 2022, at 10:19 AM, Chet Ramey wrote:
> I didn't look at more than mailx, but the description there makes it clear
> that $EDITOR needs to expand to a command name. `more' has similar wording
> ("The name of the editor shall be taken from the environment variable
> EDITOR.") and talks about what to do if the last pathname component in
> $EDITOR is `vi' or `ex'.

That's certainly the common-sense interpretation -- and no doubt
the intended one, given the historical behavior you mentioned.
I was reading phrases like "Determine the name of a utility" and
"The name of the editor shall be taken from the environment variable"
as allowing some wiggle room for the variable contents, but I was
probably overthinking it.

-- 
vq