Function: eshell-ls-dir

eshell-ls-dir is a byte-compiled function defined in em-ls.el.gz.

Signature

(eshell-ls-dir DIRINFO &optional INSERT-NAME ROOT-DIR SIZE-WIDTH)

Documentation

Output the entries in DIRINFO.

If INSERT-NAME is non-nil, the name of DIRINFO will be output. If ROOT-DIR is also non-nil, and a directory name, DIRINFO will be output relative to that directory.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-ls.el.gz
(defun eshell-ls-dir (dirinfo &optional insert-name root-dir size-width)
  "Output the entries in DIRINFO.
If INSERT-NAME is non-nil, the name of DIRINFO will be output.  If
ROOT-DIR is also non-nil, and a directory name, DIRINFO will be output
relative to that directory."
  (let ((dir (car dirinfo)))
    (if (not (cdr dirinfo))
	(funcall error-func (format "%s: No such file or directory\n" dir))
      (if dir-literal
	  (eshell-ls-file dirinfo size-width)
	(if insert-name
	    (funcall insert-func
		     (eshell-ls-decorated-name
		      (cons (concat
			     (if root-dir
				 (file-relative-name dir root-dir)
			       (expand-file-name dir)))
			    (cdr dirinfo))) ":\n"))
	(let ((entries (eshell-directory-files-and-attributes
			dir nil (and (not (or show-all show-almost-all))
				     eshell-ls-exclude-hidden
				     "\\`[^.]") t
				     ;; Asking for UID and GID as
				     ;; strings saves another syscall
				     ;; later when we are going to
				     ;; display user and group names.
				     (if numeric-uid-gid 'integer 'string))))
          (when (and show-almost-all
                     (not show-all))
            (setq entries
                  (cl-remove-if
                   (lambda (entry)
                     (member (car entry) '("." "..")))
                   entries)))
	  (when (and (not (or show-all show-almost-all))
                     eshell-ls-exclude-regexp)
	    (while (and entries (string-match eshell-ls-exclude-regexp
					      (caar entries)))
	      (setq entries (cdr entries)))
	    (let ((e entries))
	      (while (cdr e)
		(if (string-match eshell-ls-exclude-regexp (car (cadr e)))
		    (setcdr e (cddr e))
		  (setq e (cdr e))))))
	  (when (or (eq listing-style 'long-listing) show-size)
	    (let ((total 0.0))
	      (setq size-width 0)
	      (dolist (e entries)
		(if (file-attribute-size (cdr e))
		    (setq total (+ total (file-attribute-size (cdr e)))
			  size-width
			  (max size-width
			       (length (eshell-ls-printable-size
					(file-attribute-size (cdr e))
					(not
					 ;; If we are under -l, count length
					 ;; of sizes in bytes, not in blocks.
					 (eq listing-style 'long-listing))))))))
	      (funcall insert-func "total "
		       (eshell-ls-printable-size total t) "\n")))
	  (let ((default-directory (expand-file-name dir)))
	    (if show-recursive
		(eshell-ls-entries
		 (let ((e entries) (good-entries (list t)))
		   (while e
		     (unless (let ((len (length (caar e))))
			       (and (eq (aref (caar e) 0) ?.)
				    (or (= len 1)
					(and (= len 2)
					     (eq (aref (caar e) 1) ?.)))))
		       (nconc good-entries (list (car e))))
		     (setq e (cdr e)))
		   (cdr good-entries))
		 nil root-dir)
	      (eshell-ls-files (eshell-ls-sort-entries entries)
			       size-width))))))))