Function: eshell/history

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

Signature

(eshell/history &rest ARGS)

Documentation

List in help buffer the buffer's input history.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-hist.el.gz
(defun eshell/history (&rest args)
  "List in help buffer the buffer's input history."
  (eshell-init-print-buffer)
  (eshell-eval-using-options
   "history" args
   '((?r "read" nil read-history
	 "read from history file to current history list")
     (?w "write" nil write-history
	 "write current history list to history file")
     (?a "append" nil append-history
	 "append current history list to history file")
     (?h "help" nil nil "display this usage message")
     :usage "[n] [-rwa [filename]]"
     :post-usage
"When Eshell is started, history is read from `eshell-history-file-name'.
This is also the location where history info will be saved by this command,
unless a different file is specified on the command line.")
   (and (or (not (ring-p eshell-history-ring))
	   (ring-empty-p eshell-history-ring))
	(error "No history"))
   (let (length file)
     (when (and args (string-match "^[0-9]+$" (car args)))
       (setq length (min (string-to-number (car args))
			 (ring-length eshell-history-ring))
	     args (cdr args)))
     (and length
	  (or read-history write-history append-history)
	  (error "history: extra arguments"))
     (when (and args (stringp (car args)))
       (setq file (car args)
	     args (cdr args)))
     (cond
      (read-history (eshell-read-history file))
      (write-history (eshell-write-history file))
      (append-history (eshell-write-history file t))
      (t
       (let* ((index (1- (or length (ring-length eshell-history-ring))))
	      (ref (- (ring-length eshell-history-ring) index)))
	 ;; We have to build up a list ourselves from the ring vector.
	 (while (>= index 0)
	   (eshell-buffered-print
	    (format "%5d  %s\n" ref (eshell-get-history index)))
	   (setq index (1- index)
		 ref (1+ ref)))))))
   (eshell-flush)
   nil))