Function: eshell/popd
eshell/popd is a byte-compiled function defined in em-dirs.el.gz.
Signature
(eshell/popd &rest ARGS)
Documentation
Implementation of popd in Lisp.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/em-dirs.el.gz
;;; popd [+n]
(defun eshell/popd (&rest args)
"Implementation of popd in Lisp."
(let ((ref (or (car args) "+0")))
(unless (and (stringp ref)
(string-match "\\`\\([+-][0-9]+\\)\\'" ref))
(error "popd: bad arg `%s'" ref))
(setq ref (string-to-number (match-string 1 ref)))
(cond ((= ref 0)
(unless eshell-dirstack
(error "popd: Directory stack empty"))
(eshell/cd (car eshell-dirstack))
(setq eshell-dirstack (cdr eshell-dirstack))
(eshell/dirs t))
((<= (abs ref) (length eshell-dirstack))
(let* ((ds (cons nil eshell-dirstack))
(cell (nthcdr (if (> ref 0)
(1- ref)
(+ (length eshell-dirstack) ref)) ds))
(dir (cadr cell)))
(eshell/cd dir)
(setcdr cell (cdr (cdr cell)))
(setq eshell-dirstack (cdr ds))
(eshell/dirs t)))
(t
(error "Couldn't popd"))))
nil)