Function: eshell-expand-history-references

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

Signature

(eshell-expand-history-references BEG END)

Documentation

Parse and expand any history references in current input.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-hist.el.gz
(defun eshell-expand-history-references (beg end)
  "Parse and expand any history references in current input."
  (let ((result (eshell-hist-parse-arguments beg end))
	(full-line (buffer-substring-no-properties beg end)))
    (when result
      (let ((textargs (nreverse (nth 0 result)))
	    (posb (nreverse (nth 1 result)))
	    (pose (nreverse (nth 2 result)))
	    (full-line-subst (eshell-history-substitution full-line)))
	(save-excursion
	  (if full-line-subst
	      ;; Found a ^foo^bar substitution
	      (progn
		(goto-char beg)
		(insert-and-inherit full-line-subst)
		(delete-char (- end beg)))
	    ;; Try to expand other substitutions
	    (while textargs
	      (let ((str (eshell-history-reference (car textargs))))
		(unless (eq str (car textargs))
		  (goto-char (car posb))
		  (insert-and-inherit str)
		  (delete-char (- (car pose) (car posb)))))
	      (setq textargs (cdr textargs)
		    posb (cdr posb)
		    pose (cdr pose)))))))))