Function: eshell-history-substitution

eshell-history-substitution is a byte-compiled function defined in em-hist.el.gz.

Signature

(eshell-history-substitution LINE)

Documentation

Expand quick hist substitutions formatted as ^foo^bar^.

Returns nil if string does not match quick substitution format, and acts like !!:s/foo/bar/ otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-hist.el.gz
(defun eshell-history-substitution (line)
  "Expand quick hist substitutions formatted as ^foo^bar^.
Returns nil if string does not match quick substitution format,
and acts like !!:s/foo/bar/ otherwise."
  ;; `^string1^string2^'
  ;;      Quick Substitution.  Repeat the last command, replacing
  ;;      STRING1 with STRING2.  Equivalent to `!!:s/string1/string2/'
  (when (and (eshell-using-module 'eshell-pred)
	     (string-match
	      "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(?:\\^\\(.*\\)\\)?$"
	      line))
    ;; Save trailing match as `eshell-history-reference' runs string-match.
    (let ((matched-end (match-string 3 line)))
      (concat
       (eshell-history-reference
	(format "!!:s/%s/%s/"
		(match-string 1 line)
		(match-string 2 line)))
       matched-end))))