summaryrefslogtreecommitdiff
path: root/lisp/ls-lisp.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-12-28 23:36:50 +0000
committerRichard M. Stallman <rms@gnu.org>1995-12-28 23:36:50 +0000
commit0d1adb24c3de91db2990f415dd1b3ce1aea4450e (patch)
tree416c11f0c9de3f697d37b4d7e48d263c40d36726 /lisp/ls-lisp.el
parent22901567fcac5d60564d2522afdb9d9cfbb51593 (diff)
downloademacs-0d1adb24c3de91db2990f415dd1b3ce1aea4450e.tar.gz
(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.
Diffstat (limited to 'lisp/ls-lisp.el')
-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 @@
;;; 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 @@ The switches that work are: A a c i r S s t u"
;; 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 @@ The switches that work are: A a c i r S s t u"
(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 @@ The switches that work are: A a c i r S s t u"
;; 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)