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

From: Noam Postavsky <[email-masked]>
Date: Mon, 01 Jan 2018 22:58:06 -0500

Jay Kamat <[email-masked]> writes:

> Ah, I did notice that, but I was not sure whether it was a bug or
> desired behavior (as it seemed to occur for me even before this
> patch).

Oh right, I didn't notice because I tested with spaces.  Still, I think
since we're trying to make this behave like bash, we should try to get
as close as possible.

> I've added a tiny change to the patch to fix that, but it has the side
> effect of doing:
>
>> *[j@laythe emacs-bisect]$ echo "foo"(:s/bar/baz/)
>> foo: substitution failed
>
> But I think that's an OK change, especially if we want to error out on
> ^bar^baz when no search is found.

> I also discovered another issue (which existed before as well):
>
>> *[j@laythe emacs-bisect]$ echo one one one
>> ("one" "one" "one")
>> *[j@laythe emacs-bisect]$ !!:sg/one/two
>> :sg/one/two
>> Wrong type argument: integer-or-marker-p, nil
>
> but I'd rather take a look at that later on to avoid cluttering this
> changeset. (and I'm not sure if I'm just using the feature incorrectly).

!!:gs/one/two/ seems to work.  The error message could be improved
though (but yes, we should do that separately).

> +(defun eshell-history-substitution (line)
> +  "Expand whole-line history substitutions by converting them to
> +!!:s/a/b/ syntax.
> +Returns nil if no match found."

Couldn't you error here (if the line matches ^...^...^) instead of
returning nil, and then avoid affecting the other substitution?
(although I agree signaling an error in the other place is probably
acceptable)