Function: eshell/pushd
eshell/pushd is a byte-compiled function defined in em-dirs.el.gz.
Signature
(eshell/pushd &rest ARGS)
Documentation
Implementation of pushd in Lisp.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/em-dirs.el.gz
;;; pushd [+n | dir]
(defun eshell/pushd (&rest args) ; all but first ignored
"Implementation of pushd in Lisp."
(let ((path (car args)))
(cond
((null path)
;; no arg -- swap pwd and car of stack unless eshell-pushd-tohome
(cond (eshell-pushd-tohome
(eshell/pushd "~"))
(eshell-dirstack
(let ((old (eshell/pwd)))
(eshell/cd (car eshell-dirstack))
(setq eshell-dirstack (cons old (cdr eshell-dirstack)))
(eshell/dirs t)))
(t
(error "pushd: No other directory"))))
((string-match "^\\+\\([0-9]\\)" path)
;; pushd +n
(setq path (string-to-number (match-string 1 path)))
(cond ((> path (length eshell-dirstack))
(error "Directory stack not that deep"))
((= path 0)
(error "Couldn't cd"))
(eshell-pushd-dextract
(let ((dir (nth (1- path) eshell-dirstack)))
(eshell/popd path)
(eshell/pushd (eshell/pwd))
(eshell/cd dir)
(eshell/dirs t)))
(t
(let* ((ds (cons (eshell/pwd) eshell-dirstack))
(dslen (length ds))
(front (nthcdr path ds))
(back (nreverse (nthcdr (- dslen path) (reverse ds))))
(new-ds (append front back)))
(eshell/cd (car new-ds))
(setq eshell-dirstack (cdr new-ds))
(eshell/dirs t)))))
(t
;; pushd <dir>
(let ((old-wd (eshell/pwd)))
(eshell/cd path)
(if (or (null eshell-pushd-dunique)
(not (member old-wd eshell-dirstack)))
(setq eshell-dirstack (cons old-wd eshell-dirstack)))
(eshell/dirs t)))))
nil)