]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-ls.el
Merge from emacs-24; up to 2012-12-17T11:17:34Z!rgm@gnu.org
[gnu-emacs] / lisp / eshell / em-ls.el
index 84af53efe5802ae03f0a04a5a758b2a1c03a24ba..73ed617b871d493d668c05e2fa448c3c03f33a56 100644 (file)
@@ -1,7 +1,6 @@
 ;;; em-ls.el --- implementation of ls in Lisp
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl)
-  (require 'eshell))
+(eval-when-compile (require 'eshell))
+(require 'cl-lib)
 (require 'esh-util)
 (require 'esh-opt)
 
 ;;;###autoload
-(eshell-defgroup eshell-ls nil
+(progn
+(defgroup eshell-ls nil
   "This module implements the \"ls\" utility fully in Lisp.  If it is
 passed any unrecognized command switches, it will revert to the
 operating system's version.  This version of \"ls\" uses text
 properties to colorize its output based on the setting of
 `eshell-ls-use-colors'."
   :tag "Implementation of `ls' in Lisp"
-  :group 'eshell-module)
+  :group 'eshell-module))
 
 ;;; User Variables:
 
@@ -58,6 +57,14 @@ properties to colorize its output based on the setting of
   :type 'hook
   :group 'eshell-ls)
 
+(defcustom eshell-ls-date-format "%Y-%m-%d"
+  "How to display time information in `eshell-ls-file'.
+This is passed to `format-time-string' as a format string.
+To display the date using the current locale, use \"%b \%e\"."
+  :version "24.1"
+  :type 'string
+  :group 'eshell-ls)
+
 (defcustom eshell-ls-initial-args nil
   "If non-nil, this list of args is included before any call to `ls'.
 This is useful for enabling human-readable format (-h), for example."
@@ -304,7 +311,7 @@ instead."
   (let ((insert-func 'eshell-buffered-print)
        (error-func 'eshell-error)
        (flush-func 'eshell-flush))
-    (eshell-do-ls args)))
+    (apply 'eshell-do-ls args)))
 
 (put 'eshell/ls 'eshell-no-numeric-conversions t)
 
@@ -320,6 +327,7 @@ instead."
 (defvar numeric-uid-gid)
 (defvar reverse-list)
 (defvar show-all)
+(defvar show-almost-all)
 (defvar show-recursive)
 (defvar show-size)
 (defvar sort-method)
@@ -329,13 +337,15 @@ instead."
 (defun eshell-do-ls (&rest args)
   "Implementation of \"ls\" in Lisp, passing ARGS."
   (funcall flush-func -1)
-  ;; process the command arguments, and begin listing files
+  ;; Process the command arguments, and begin listing files.
   (eshell-eval-using-options
    "ls" (if eshell-ls-initial-args
            (list eshell-ls-initial-args args)
          args)
    `((?a "all" nil show-all
-        "show all files in directory")
+        "do not ignore entries starting with .")
+     (?A "almost-all" nil show-almost-all
+        "do not list implied . and ..")
      (?c nil by-ctime sort-method
         "sort by last status change time")
      (?d "directory" nil dir-literal
@@ -455,7 +465,7 @@ name should be displayed as, etc.  Think of it as cooking a FILEINFO."
          (progn
            (setcdr fileinfo attr)
            (setcar fileinfo (eshell-ls-decorated-name fileinfo)))
-       (assert (eq listing-style 'long-listing))
+       (cl-assert (eq listing-style 'long-listing))
        (setcar fileinfo
                (concat (eshell-ls-decorated-name fileinfo) " -> "
                        (eshell-ls-decorated-name
@@ -509,7 +519,7 @@ whose cdr is the list of file attributes."
                    str))
                " " (format-time-string
                     (concat
-                     "%b %e "
+                     eshell-ls-date-format " "
                      (if (= (nth 5 (decode-time (current-time)))
                             (nth 5 (decode-time
                                     (nth (cond
@@ -550,7 +560,15 @@ relative to that directory."
                                     ;; later when we are going to
                                     ;; display user and group names.
                                     (if numeric-uid-gid 'integer 'string))))
-         (when (and (not show-all) eshell-ls-exclude-regexp)
+          (when (and show-almost-all
+                     (not show-all))
+            (setq entries
+                  (cl-remove-if
+                   (lambda (entry)
+                     (member (caar entry) '("." "..")))
+                   entries)))
+         (when (and (not show-all)
+                     eshell-ls-exclude-regexp)
            (while (and entries (string-match eshell-ls-exclude-regexp
                                              (caar entries)))
              (setq entries (cdr entries)))
@@ -562,7 +580,7 @@ relative to that directory."
          (when (or (eq listing-style 'long-listing) show-size)
            (let ((total 0.0))
              (setq size-width 0)
-             (eshell-for e entries
+             (dolist (e entries)
                (if (nth 7 (cdr e))
                    (setq total (+ total (nth 7 (cdr e)))
                          size-width
@@ -652,7 +670,7 @@ Each member of FILES is either a string or a cons cell of the form
               (not (eq eshell-in-pipeline-p 'last))
               (not (eq listing-style 'by-lines)))
          (memq listing-style '(long-listing single-column)))
-      (eshell-for file files
+      (dolist (file files)
        (if file
            (eshell-ls-file file size-width copy-fileinfo)))
     (let ((f files)
@@ -677,7 +695,7 @@ Each member of FILES is either a string or a cons cell of the form
              (setcdr f (cddr f))))))
       (if (not show-size)
          (setq display-files (mapcar 'eshell-ls-annotate files))
-       (eshell-for file files
+       (dolist (file files)
          (let* ((str (eshell-ls-printable-size (nth 7 (cdr file)) t))
                 (len (length str)))
            (if (< len size-width)
@@ -690,14 +708,14 @@ Each member of FILES is either a string or a cons cell of the form
       (let* ((col-vals
              (if (eq listing-style 'by-columns)
                  (eshell-ls-find-column-lengths display-files)
-               (assert (eq listing-style 'by-lines))
+               (cl-assert (eq listing-style 'by-lines))
                (eshell-ls-find-column-widths display-files)))
             (col-widths (car col-vals))
             (display-files (cdr col-vals))
             (columns (length col-widths))
             (col-index 1)
             need-return)
-       (eshell-for file display-files
+       (dolist (file display-files)
          (let ((name
                 (if (car file)
                     (if show-size
@@ -732,7 +750,7 @@ ROOT-DIR, if non-nil, specifies the root directory of the listing, to
 which non-absolute directory names will be made relative if ever they
 need to be printed."
   (let (dirs files show-names need-return (size-width 0))
-    (eshell-for entry entries
+    (dolist (entry entries)
       (if (and (not dir-literal)
               (or (eshell-ls-filetype-p (cdr entry) ?d)
                   (and (eshell-ls-filetype-p (cdr entry) ?l)
@@ -758,7 +776,7 @@ need to be printed."
       (setq need-return t))
     (setq show-names (or show-recursive
                         (> (+ (length files) (length dirs)) 1)))
-    (eshell-for dir (eshell-ls-sort-entries dirs)
+    (dolist (dir (eshell-ls-sort-entries dirs))
       (if (and need-return (not dir-literal))
          (funcall insert-func "\n"))
       (eshell-ls-dir dir show-names