aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-12-28 23:36:50 +0000
committerRichard M. Stallman1995-12-28 23:36:50 +0000
commit3045b1630257e91e19499bb2d1a8bd2760bacd63 (patch)
tree78e762300a53bf8f789f421512d4a7253848578a
parenta7ee71e81512c2abd91c3545c54dbe6b7484e188 (diff)
downloademacs-3045b1630257e91e19499bb2d1a8bd2760bacd63.tar.gz
emacs-3045b1630257e91e19499bb2d1a8bd2760bacd63.zip
(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.
-rw-r--r--lisp/ls-lisp.el45
1 files changed, 35 insertions, 10 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 4aa431501a8..1f0b24b6b1b 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -50,27 +50,47 @@
50 50
51;;; Code: 51;;; Code:
52 52
53(defvar ls-lisp-support-shell-wildcards t
54 "*Non-nil means file patterns are treated as shell wildcards.
55nil means they are treated as Emacs regexps (for backward compatibility).
56This variable is checked by \\[insert-directory] only when `ls-lisp.el'
57package is used.")
58
53(defun insert-directory (file &optional switches wildcard full-directory-p) 59(defun insert-directory (file &optional switches wildcard full-directory-p)
54 "Insert directory listing for of FILE, formatted according to SWITCHES. 60 "Insert directory listing for FILE, formatted according to SWITCHES.
55Leaves point after the inserted text. 61Leaves point after the inserted text.
56Optional third arg WILDCARD means treat FILE as shell wildcard. 62Optional third arg WILDCARD means treat FILE as shell wildcard.
57Optional fourth arg FULL-DIRECTORY-P means file is a directory and 63Optional fourth arg FULL-DIRECTORY-P means file is a directory and
58switches do not contain `d', so that a full listing is expected. 64switches do not contain `d', so that a full listing is expected.
59 65
60This version of the function comes from `ls-lisp.el'. 66This version of the function comes from `ls-lisp.el'. It doesn not
61It does not support ordinary shell wildcards; instead, it allows 67run any external programs or shells. It supports ordinary shell
62regular expressions to match file names. 68wildcards if `ls-lisp-support-shell-wildcards' variable is non-nil;
69otherwise, it interprets wildcards as regular expressions to match
70file names.
63 71
64The switches that work are: A a c i r S s t u" 72Not all `ls' switches are supported. The switches that work
73are: A a c i r S s t u"
65 (let ((handler (find-file-name-handler file 'insert-directory))) 74 (let ((handler (find-file-name-handler file 'insert-directory)))
66 (if handler 75 (if handler
67 (funcall handler 'insert-directory file switches 76 (funcall handler 'insert-directory file switches
68 wildcard full-directory-p) 77 wildcard full-directory-p)
78 ;; Sometimes we get ".../foo*/" as FILE. While the shell and
79 ;; `ls' don't mind, we certainly do, because it makes us think
80 ;; there is no wildcard, only a directory name.
81 (if (and ls-lisp-support-shell-wildcards
82 (string-match "[[?*]" file))
83 (progn
84 (or (not (eq (aref file (1- (length file))) ?/))
85 (setq file (substring file 0 (1- (length file)))))
86 (setq wildcard t)))
69 ;; Convert SWITCHES to a list of characters. 87 ;; Convert SWITCHES to a list of characters.
70 (setq switches (append switches nil)) 88 (setq switches (append switches nil))
71 (if wildcard 89 (if wildcard
72 (setq wildcard (file-name-nondirectory file) ; actually emacs regexp 90 (setq wildcard
73 ;; perhaps convert it from shell to emacs syntax? 91 (if ls-lisp-support-shell-wildcards
92 (wildcard-to-regexp (file-name-nondirectory file))
93 (file-name-nondirectory file))
74 file (file-name-directory file))) 94 file (file-name-directory file)))
75 (if (or wildcard 95 (if (or wildcard
76 full-directory-p) 96 full-directory-p)
@@ -100,7 +120,12 @@ The switches that work are: A a c i r S s t u"
100 ;; seems to stimulate an Emacs bug 120 ;; seems to stimulate an Emacs bug
101 ;; ILLEGAL DATATYPE (#o37777777727) or #o67 121 ;; ILLEGAL DATATYPE (#o37777777727) or #o67
102 file-list)) 122 file-list))
103 (insert "total \007\n") ; filled in afterwards 123 ;; ``Total'' line (filled in afterwards).
124 (insert (if (car-safe file-alist)
125 "total \007\n"
126 ;; Shell says ``No match'' if no files match
127 ;; the wildcard; let's say something similar.
128 "(No match)\ntotal \007\n"))
104 (setq file-alist 129 (setq file-alist
105 (ls-lisp-handle-switches file-alist switches)) 130 (ls-lisp-handle-switches file-alist switches))
106 (while file-alist 131 (while file-alist
@@ -116,7 +141,7 @@ The switches that work are: A a c i r S s t u"
116 (search-backward "total \007") 141 (search-backward "total \007")
117 (goto-char (match-end 0)) 142 (goto-char (match-end 0))
118 (delete-char -1) 143 (delete-char -1)
119 (insert (format "%d" (1+ (/ sum 1024)))))) 144 (insert (format "%d" (if (zerop sum) 0 (1+ (/ sum 1024)))))))
120 ;; if not full-directory-p, FILE *must not* end in /, as 145 ;; if not full-directory-p, FILE *must not* end in /, as
121 ;; file-attributes will not recognize a symlink to a directory 146 ;; file-attributes will not recognize a symlink to a directory
122 ;; must make it a relative filename as ls does: 147 ;; must make it a relative filename as ls does:
@@ -185,7 +210,7 @@ The switches that work are: A a c i r S s t u"
185 ;; Emacs should be able to make strings of them. 210 ;; Emacs should be able to make strings of them.
186 ;; user-login-name and user-full-name could take an 211 ;; user-login-name and user-full-name could take an
187 ;; optional arg. 212 ;; optional arg.
188 (format " %3d %8s %8s %8d " 213 (format " %3d %-8s %-8s %8d "
189 (nth 1 file-attr) ; no. of links 214 (nth 1 file-attr) ; no. of links
190 (if (= (user-uid) (nth 2 file-attr)) 215 (if (= (user-uid) (nth 2 file-attr))
191 (user-login-name) 216 (user-login-name)