changeset 13883:a4eef7470b6b

(ls-lisp-support-shell-wildcards): New variable. (insert-directory): Convert the filename wildcard to an equivalent Emacs regexp, when `ls-lisp-support-shell-wildcards' is non-nil. Handle file patterns like "/foo*/" as if it were "/foo*", like the shell would. Print zero total for files whose total size is exactly zero (in particular, for no files at all). Say "No match" when no files match the given wildcard. (ls-lisp-format): Make directory listing format more like POSIX ls.
author Richard M. Stallman <rms@gnu.org>
date Thu, 28 Dec 1995 23:36:50 +0000
parents 2631a29a614c
children 26245345f6f1
files lisp/ls-lisp.el
diffstat 1 files changed, 35 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ls-lisp.el	Thu Dec 28 23:28:35 1995 +0000
+++ b/lisp/ls-lisp.el	Thu Dec 28 23:36:50 1995 +0000
@@ -50,27 +50,47 @@
 
 ;;; Code:
 
+(defvar ls-lisp-support-shell-wildcards t
+  "*Non-nil means file patterns are treated as shell wildcards.
+nil means they are treated as Emacs regexps (for backward compatibility).
+This variable is checked by \\[insert-directory] only when `ls-lisp.el'
+package is used.")
+
 (defun insert-directory (file &optional switches wildcard full-directory-p)
-  "Insert directory listing for of FILE, formatted according to SWITCHES.
+  "Insert directory listing for FILE, formatted according to SWITCHES.
 Leaves point after the inserted text.
 Optional third arg WILDCARD means treat FILE as shell wildcard.
 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
 switches do not contain `d', so that a full listing is expected.
 
-This version of the function comes from `ls-lisp.el'.
-It does not support ordinary shell wildcards; instead, it allows
-regular expressions to match file names.
+This version of the function comes from `ls-lisp.el'.  It doesn not
+run any external programs or shells.  It supports ordinary shell
+wildcards if `ls-lisp-support-shell-wildcards' variable is non-nil;
+otherwise, it interprets wildcards as regular expressions to match
+file names.
 
-The switches that work are: A a c i r S s t u"
+Not all `ls' switches are supported.  The switches that work
+are: A a c i r S s t u"
   (let ((handler (find-file-name-handler file 'insert-directory)))
     (if handler
 	(funcall handler 'insert-directory file switches
 		 wildcard full-directory-p)
+      ;; Sometimes we get ".../foo*/" as FILE.  While the shell and
+      ;; `ls' don't mind, we certainly do, because it makes us think
+      ;; there is no wildcard, only a directory name.
+      (if (and ls-lisp-support-shell-wildcards
+	       (string-match "[[?*]" file))
+	  (progn
+	    (or (not (eq (aref file (1- (length file))) ?/))
+		(setq file (substring file 0 (1- (length file)))))
+	    (setq wildcard t)))
       ;; Convert SWITCHES to a list of characters.
       (setq switches (append switches nil))
       (if wildcard
-	  (setq wildcard (file-name-nondirectory file) ; actually emacs regexp
-		;; perhaps convert it from shell to emacs syntax?
+	  (setq wildcard
+		(if ls-lisp-support-shell-wildcards
+		    (wildcard-to-regexp (file-name-nondirectory file))
+		  (file-name-nondirectory file))
 		file (file-name-directory file)))
       (if (or wildcard
 	      full-directory-p)
@@ -100,7 +120,12 @@
 		   ;; seems to stimulate an Emacs bug
 		   ;; ILLEGAL DATATYPE (#o37777777727) or #o67
 		   file-list))
-	    (insert "total \007\n")	; filled in afterwards
+	    ;; ``Total'' line (filled in afterwards).
+	    (insert (if (car-safe file-alist)
+			"total \007\n"
+		      ;; Shell says ``No match'' if no files match
+		      ;; the wildcard; let's say something similar.
+		      "(No match)\ntotal \007\n"))
 	    (setq file-alist
 		  (ls-lisp-handle-switches file-alist switches))
 	    (while file-alist
@@ -116,7 +141,7 @@
 	      (search-backward "total \007")
 	      (goto-char (match-end 0))
 	      (delete-char -1)
-	      (insert (format "%d" (1+ (/ sum 1024))))))
+	      (insert (format "%d" (if (zerop sum) 0 (1+ (/ sum 1024)))))))
 	;; if not full-directory-p, FILE *must not* end in /, as
 	;; file-attributes will not recognize a symlink to a directory
 	;; must make it a relative filename as ls does:
@@ -185,7 +210,7 @@
 	    ;; Emacs should be able to make strings of them.
 	    ;; user-login-name and user-full-name could take an
 	    ;; optional arg.
-	    (format " %3d %8s %8s %8d "
+	    (format " %3d %-8s %-8s %8d "
 		    (nth 1 file-attr)	; no. of links
 		    (if (= (user-uid) (nth 2 file-attr))
 			(user-login-name)