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

From: Noam Postavsky <[email-masked]>
Date: Sun, 05 Nov 2017 08:58:22 -0500

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

> 	> 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))