Subject: bug#29157: 25.3; Eshell parsing fails sometimes, e.g. "date" and "sed"

From: Pierre Neidhardt <[email-masked]>
Date: Sun, 05 Nov 2017 15:16:33 +0100

Noam Postavsky <[email-masked]> writes:

> Pierre Neidhardt <[email-masked]> writes:
>
>> - emacs -Q
>> - M-x eshell
>>
>> 	> date +%Z
>> 	Invalid time specification
>
>     ~/src/emacs $ which date
>     eshell/date is an alias for ‘current-time-string’ in ‘em-unix.el’.
>     ~/src/emacs $ which *date
>     /bin/date
>     ~/src/emacs $ *date +%Z
>     EST

Duh!  That was stupid, sorry.  Anyways, that might ring an alarm here:
maybe eshell/date should not exist.  What's the point of having it?  I'm
not sure.  It is obviously less powerful than the system `date'.

>> 	> echo $PATH | sed "s/[^o]foo[^o]/bar/g"
>> 	Unknown predicate character ‘b’
>
> M-x toggle-debug-on-error gives more hints about this.  Apparently this
> matches a "history reference":
>
>     (defun eshell-history-reference (reference)
>       "Expand directory stack REFERENCE.
>     The syntax used here was taken from the Bash info manual.
>     Returns the resultant reference, or the same string REFERENCE if none
>     matched."
>       ;; `^string1^string2^'
>       ;;      Quick Substitution.  Repeat the last command, replacing
>       ;;      STRING1 with STRING2.  Equivalent to `!!:s/string1/string2/'
>
> Debugger entered--Lisp error: (error "Unknown predicate character ‘b’")
>   signal(error ("Unknown predicate character ‘b’"))
>   error("Unknown predicate character `%c'" 98)
>   eshell-parse-modifiers()
>   eshell-hist-parse-modifier("printf '<<%s>>\\n' \"s/[^o]foo/\"" ":s/o]foo[/o]/bar/g\"/")
>   eshell-history-reference("\"s/[^o]foo[^o]/bar/g\"")
>   eshell-expand-history-references(#<marker at 43 in *eshell*> 81)
>   run-hook-with-args(eshell-expand-history-references #<marker at 43 in *eshell*> 81)
>   eshell-send-input(nil)
>   funcall-interactively(eshell-send-input nil)
>   call-interactively(eshell-send-input nil nil)
>   command-execute(eshell-send-input)
>
>
> My suggestion for this is just to stop adding
> eshell-expand-history-references to eshell-expand-input-functions, and
> maybe even deprecate eshell-expand-history-references.  I find the
> history expansion mechanism to be an annoyance in bash as well.
>
> --- i/lisp/eshell/em-hist.el
> +++ w/lisp/eshell/em-hist.el
> @@ -218,9 +218,6 @@ eshell-input-filter-initial-space
>  
>  (defun eshell-hist-initialize ()
>    "Initialize the history management code for one Eshell buffer."
> -  (add-hook 'eshell-expand-input-functions
> -	    'eshell-expand-history-references nil t)
> -
>    (when (eshell-using-module 'eshell-cmpl)
>      (add-hook 'pcomplete-try-first-hook
>  	      'eshell-complete-history-reference nil t))

That does it for me.  I did not even know this feature existed.  I'd it
proves more useful in an environment with poor selection / editing
capabilities, i.e. a terminal shell.  Emacs does not need that when you
can fuzzy-search your history and modify your prompt with arbitrary
bindings / Lisp code.

-- 
Pierre Neidhardt

There are more things in heaven and earth than any place else.