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

From: Noam Postavsky <[email-masked]>
Date: Thu, 04 Jan 2018 20:04:09 -0500

Jay Kamat <[email-masked]> writes:

> Ah, nice catch! I've updated the patch to handle that case as well. I've
> tested it as well as I could and it seems good to me, but in order to
> fix that case, I had to mess with the regexes a bit, so It's possible I
> might have missed a few cases.

There doesn't need to be trailing whitespace between the last "^" and
subsequent text, bash:

    ~/tmp$ echo foo bar
    foo bar
    ~/tmp$ ^foo^blah^x
    echo blah barx
    blah barx

eshell (with your patch):

    ~/src/emacs $ echo foo bar
    ("foo" "bar")
    ~/src/emacs $ ^foo^blah^x
    ^foo^blah^x: command not found

And as far as I can tell, trailing whitespace should not be dropped
(though it's hard to come up with cases where it matters):

    ~/tmp$ echo 'foo bar '
    foo bar 
    ~/tmp$ ^bar^zz  
    echo 'foo zz   '
    foo zz   

So I think this should do it?

    ...	     
         (string-match
	      "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(?:\\^\\(.*\\)\\)?$"
	      line))
    ;; Save trailing match as `eshell-history-reference' runs string-match.
    (let ((matched-end (match-string 3 line)))
    ...