Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line

From: Noam Postavsky <[email-masked]>
Date: Mon, 01 Jan 2018 20:29:20 -0500

Andreas Schwab <[email-masked]> writes:

> On Dez 31 2017, Noam Postavsky <[email-masked]> wrote:
>
>> Hmm, using history expansion would mean typing
>>
>>     M-p DEL C-a M-f M-d M-d ! ! : $
>>
>> to get
>>
>>     mv !!:$ two.txt
>
> History expansion was invented when command line editing wasn't
> available, it typically makes only sense for entering a new command line
> (while referencing parts of the previous ones).

Yes, but I didn't want to handicap the history expansion case unfairly
by rejecting use of other history/editing commands.

Jay Kamat <[email-masked]> writes:

> I would much prefer a variable (perhaps defaulting to off) to tweak this
> setting on or of rather than adding/removing a function to the hook.
> Removing it in the current way makes it feel more 'deprecated' to me,
> rather than 'disabled by default'.
>
> Would you mind if I submitted a patch to add a new
> `eshell-history-expansion-enabled' variable (or similar)?

Seems like pointless duplication to me.  I think I would prefer having
history expansion enabled by default to that (it wouldn't be that hard
to disable it, after all).

>> In eshell (with and without your patch) I get:
>>
>>     ~/src/emacs $ echo foo bar
>>     ("foo" "bar")
>>     ~/src/emacs $ ^foo bar^blah^
>>     ^foo: command not found
>
> I've attached a new patch which attempts to solve this as well. I'm
> unfamiliar with eshell internals though, so I'm not sure if it's done
> properly. Let me know if anyone sees any issues with it!

With your patch, if I do

    ~/src/emacs $ ^this string not present in history^blah^

I get the latest entry in the history substituted and re-executed.  In
bash I get

    ~/tmp$ ^this string not present in history^blah^
    bash: :s^this string not present in history^blah^: substitution failed

(if it's easier, I think it would be okay if eshell prints an error
using the !!:s/foo/bar/ syntax, but this case must be an error)