1 ;;; em-ls.el --- implementation of ls in Lisp
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Most of the command switches recognized by GNU's ls utility are
26 ;; supported ([(fileutils)ls invocation]).
30 (eval-when-compile (require 'eshell
))
35 (eshell-defgroup eshell-ls nil
36 "This module implements the \"ls\" utility fully in Lisp. If it is
37 passed any unrecognized command switches, it will revert to the
38 operating system's version. This version of \"ls\" uses text
39 properties to colorize its output based on the setting of
40 `eshell-ls-use-colors'."
41 :tag
"Implementation of `ls' in Lisp"
42 :group
'eshell-module
)
46 (defvar eshell-ls-orig-insert-directory
47 (symbol-function 'insert-directory
)
48 "Preserve the original definition of `insert-directory'.")
50 (defcustom eshell-ls-unload-hook
54 (fset 'insert-directory eshell-ls-orig-insert-directory
))))
55 "*When unloading `eshell-ls', restore the definition of `insert-directory'."
59 (defcustom eshell-ls-initial-args nil
60 "*If non-nil, this list of args is included before any call to `ls'.
61 This is useful for enabling human-readable format (-h), for example."
62 :type
'(repeat :tag
"Arguments" string
)
65 (defcustom eshell-ls-dired-initial-args nil
66 "*If non-nil, args is included before any call to `ls' in Dired.
67 This is useful for enabling human-readable format (-h), for example."
68 :type
'(repeat :tag
"Arguments" string
)
71 (defcustom eshell-ls-use-in-dired nil
72 "*If non-nil, use `eshell-ls' to read directories in Dired."
73 :set
(lambda (symbol value
)
75 (unless (and (boundp 'eshell-ls-use-in-dired
)
76 eshell-ls-use-in-dired
)
77 (fset 'insert-directory
'eshell-ls-insert-directory
))
78 (when (and (boundp 'eshell-ls-insert-directory
)
79 eshell-ls-use-in-dired
)
80 (fset 'insert-directory eshell-ls-orig-insert-directory
)))
81 (setq eshell-ls-use-in-dired value
))
86 (defcustom eshell-ls-default-blocksize
1024
87 "*The default blocksize to use when display file sizes with -s."
91 (defcustom eshell-ls-exclude-regexp nil
92 "*Unless -a is specified, files matching this regexp will not be shown."
93 :type
'(choice regexp
(const nil
))
96 (defcustom eshell-ls-exclude-hidden t
97 "*Unless -a is specified, files beginning with . will not be shown.
98 Using this boolean, instead of `eshell-ls-exclude-regexp', is both
99 faster and conserves more memory."
103 (defcustom eshell-ls-use-colors t
104 "*If non-nil, use colors in file listings."
108 (defface eshell-ls-directory
109 '((((class color
) (background light
)) (:foreground
"Blue" :weight bold
))
110 (((class color
) (background dark
)) (:foreground
"SkyBlue" :weight bold
))
112 "*The face used for highlight directories."
114 ;; backward-compatibility alias
115 (put 'eshell-ls-directory-face
'face-alias
'eshell-ls-directory
)
117 (defface eshell-ls-symlink
118 '((((class color
) (background light
)) (:foreground
"Dark Cyan" :weight bold
))
119 (((class color
) (background dark
)) (:foreground
"Cyan" :weight bold
)))
120 "*The face used for highlight symbolic links."
122 ;; backward-compatibility alias
123 (put 'eshell-ls-symlink-face
'face-alias
'eshell-ls-symlink
)
125 (defface eshell-ls-executable
126 '((((class color
) (background light
)) (:foreground
"ForestGreen" :weight bold
))
127 (((class color
) (background dark
)) (:foreground
"Green" :weight bold
)))
128 "*The face used for highlighting executables (not directories, though)."
130 ;; backward-compatibility alias
131 (put 'eshell-ls-executable-face
'face-alias
'eshell-ls-executable
)
133 (defface eshell-ls-readonly
134 '((((class color
) (background light
)) (:foreground
"Brown"))
135 (((class color
) (background dark
)) (:foreground
"Pink")))
136 "*The face used for highlighting read-only files."
138 ;; backward-compatibility alias
139 (put 'eshell-ls-readonly-face
'face-alias
'eshell-ls-readonly
)
141 (defface eshell-ls-unreadable
142 '((((class color
) (background light
)) (:foreground
"Grey30"))
143 (((class color
) (background dark
)) (:foreground
"DarkGrey")))
144 "*The face used for highlighting unreadable files."
146 ;; backward-compatibility alias
147 (put 'eshell-ls-unreadable-face
'face-alias
'eshell-ls-unreadable
)
149 (defface eshell-ls-special
150 '((((class color
) (background light
)) (:foreground
"Magenta" :weight bold
))
151 (((class color
) (background dark
)) (:foreground
"Magenta" :weight bold
)))
152 "*The face used for highlighting non-regular files."
154 ;; backward-compatibility alias
155 (put 'eshell-ls-special-face
'face-alias
'eshell-ls-special
)
157 (defface eshell-ls-missing
158 '((((class color
) (background light
)) (:foreground
"Red" :weight bold
))
159 (((class color
) (background dark
)) (:foreground
"Red" :weight bold
)))
160 "*The face used for highlighting non-existent file names."
162 ;; backward-compatibility alias
163 (put 'eshell-ls-missing-face
'face-alias
'eshell-ls-missing
)
165 (defcustom eshell-ls-archive-regexp
166 (concat "\\.\\(t\\(a[rz]\\|gz\\)\\|arj\\|lzh\\|"
167 "zip\\|[zZ]\\|gz\\|bz2\\|deb\\|rpm\\)\\'")
168 "*A regular expression that matches names of file archives.
169 This typically includes both traditional archives and compressed
174 (defface eshell-ls-archive
175 '((((class color
) (background light
)) (:foreground
"Orchid" :weight bold
))
176 (((class color
) (background dark
)) (:foreground
"Orchid" :weight bold
)))
177 "*The face used for highlighting archived and compressed file names."
179 ;; backward-compatibility alias
180 (put 'eshell-ls-archive-face
'face-alias
'eshell-ls-archive
)
182 (defcustom eshell-ls-backup-regexp
183 "\\(\\`\\.?#\\|\\(\\.bak\\|~\\)\\'\\)"
184 "*A regular expression that matches names of backup files."
188 (defface eshell-ls-backup
189 '((((class color
) (background light
)) (:foreground
"OrangeRed"))
190 (((class color
) (background dark
)) (:foreground
"LightSalmon")))
191 "*The face used for highlighting backup file names."
193 ;; backward-compatibility alias
194 (put 'eshell-ls-backup-face
'face-alias
'eshell-ls-backup
)
196 (defcustom eshell-ls-product-regexp
197 "\\.\\(elc\\|o\\(bj\\)?\\|a\\|lib\\|res\\)\\'"
198 "*A regular expression that matches names of product files.
199 Products are files that get generated from a source file, and hence
200 ought to be recreatable if they are deleted."
204 (defface eshell-ls-product
205 '((((class color
) (background light
)) (:foreground
"OrangeRed"))
206 (((class color
) (background dark
)) (:foreground
"LightSalmon")))
207 "*The face used for highlighting files that are build products."
209 ;; backward-compatibility alias
210 (put 'eshell-ls-product-face
'face-alias
'eshell-ls-product
)
212 (defcustom eshell-ls-clutter-regexp
213 "\\(^texput\\.log\\|^core\\)\\'"
214 "*A regular expression that matches names of junk files.
215 These are mainly files that get created for various reasons, but don't
216 really need to stick around for very long."
220 (defface eshell-ls-clutter
221 '((((class color
) (background light
)) (:foreground
"OrangeRed" :weight bold
))
222 (((class color
) (background dark
)) (:foreground
"OrangeRed" :weight bold
)))
223 "*The face used for highlighting junk file names."
225 ;; backward-compatibility alias
226 (put 'eshell-ls-clutter-face
'face-alias
'eshell-ls-clutter
)
228 (defsubst eshell-ls-filetype-p
(attrs type
)
229 "Test whether ATTRS specifies a directory."
231 (eq (aref (nth 8 attrs
) 0) type
)))
233 (defmacro eshell-ls-applicable
(attrs index func file
)
234 "Test whether, for ATTRS, the user UID can do what corresponds to INDEX.
235 This is really just for efficiency, to avoid having to stat the file
237 `(if (numberp (nth 2 ,attrs
))
238 (if (= (user-uid) (nth 2 ,attrs
))
239 (not (eq (aref (nth 8 ,attrs
) ,index
) ?-
))
240 (,(eval func
) ,file
))
241 (not (eq (aref (nth 8 ,attrs
)
242 (+ ,index
(if (member (nth 2 ,attrs
)
243 (eshell-current-ange-uids))
247 (defcustom eshell-ls-highlight-alist nil
248 "*This alist correlates test functions to color.
249 The format of the members of this alist is
253 If TEST-SEXP evals to non-nil, that face will be used to highlight the
254 name of the file. The first match wins. `file' and `attrs' are in
255 scope during the evaluation of TEST-SEXP."
256 :type
'(repeat (cons function face
))
261 (defun eshell-ls-insert-directory
262 (file switches
&optional wildcard full-directory-p
)
263 "Insert directory listing for FILE, formatted according to SWITCHES.
264 Leaves point after the inserted text.
265 SWITCHES may be a string of options, or a list of strings.
266 Optional third arg WILDCARD means treat FILE as shell wildcard.
267 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
268 switches do not contain `d', so that a full listing is expected.
270 This version of the function uses `eshell/ls'. If any of the switches
271 passed are not recognized, the operating system's version will be used
273 (let ((handler (find-file-name-handler file
'insert-directory
)))
275 (funcall handler
'insert-directory file switches
276 wildcard full-directory-p
)
277 (if (stringp switches
)
278 (setq switches
(split-string switches
)))
279 (let (eshell-current-handles
280 eshell-current-subjob-p
282 ;; use the fancy highlighting in `eshell-ls' rather than font-lock
283 (when (and eshell-ls-use-colors
284 (featurep 'font-lock
))
286 (setq font-lock-defaults nil
)
287 (if (boundp 'font-lock-buffers
)
288 (set 'font-lock-buffers
289 (delq (current-buffer)
290 (symbol-value 'font-lock-buffers
)))))
291 (let ((insert-func 'insert
)
294 eshell-ls-dired-initial-args
)
295 (eshell-do-ls (append switches
(list file
))))))))
297 (defsubst eshell
/ls
(&rest args
)
298 "An alias version of `eshell-do-ls'."
299 (let ((insert-func 'eshell-buffered-print
)
300 (error-func 'eshell-error
)
301 (flush-func 'eshell-flush
))
302 (eshell-do-ls args
)))
304 (put 'eshell
/ls
'eshell-no-numeric-conversions t
)
307 (defvar dereference-links
)
311 (defvar human-readable
)
312 (defvar ignore-pattern
)
314 (defvar listing-style
)
315 (defvar numeric-uid-gid
)
316 (defvar reverse-list
)
318 (defvar show-recursive
)
324 (defun eshell-do-ls (&rest args
)
325 "Implementation of \"ls\" in Lisp, passing ARGS."
326 (funcall flush-func -
1)
327 ;; process the command arguments, and begin listing files
328 (eshell-eval-using-options
329 "ls" (if eshell-ls-initial-args
330 (list eshell-ls-initial-args args
)
332 `((?a
"all" nil show-all
333 "show all files in directory")
334 (?c nil by-ctime sort-method
335 "sort by last status change time")
336 (?d
"directory" nil dir-literal
337 "list directory entries instead of contents")
338 (?k
"kilobytes" 1024 block-size
339 "using 1024 as the block size")
340 (?h
"human-readable" 1024 human-readable
341 "print sizes in human readable format")
342 (?H
"si" 1000 human-readable
343 "likewise, but use powers of 1000 not 1024")
344 (?I
"ignore" t ignore-pattern
345 "do not list implied entries matching pattern")
346 (?l nil long-listing listing-style
347 "use a long listing format")
348 (?n
"numeric-uid-gid" nil numeric-uid-gid
349 "list numeric UIDs and GIDs instead of names")
350 (?r
"reverse" nil reverse-list
351 "reverse order while sorting")
352 (?s
"size" nil show-size
353 "print size of each file, in blocks")
354 (?t nil by-mtime sort-method
355 "sort by modification time")
356 (?u nil by-atime sort-method
357 "sort by last access time")
358 (?x nil by-lines listing-style
359 "list entries by lines instead of by columns")
360 (?C nil by-columns listing-style
361 "list entries by columns")
362 (?L
"deference" nil dereference-links
363 "list entries pointed to by symbolic links")
364 (?R
"recursive" nil show-recursive
365 "list subdirectories recursively")
366 (?S nil by-size sort-method
368 (?U nil unsorted sort-method
369 "do not sort; list entries in directory order")
370 (?X nil by-extension sort-method
371 "sort alphabetically by entry extension")
372 (?
1 nil single-column listing-style
373 "list one file per line")
374 (nil "dired" nil dired-flag
375 "Here for compatibility with GNU ls.")
377 "show this usage display")
379 :usage
"[OPTION]... [FILE]...
380 List information about the FILEs (the current directory by default).
381 Sort entries alphabetically across.")
382 ;; setup some defaults, based on what the user selected
384 (setq block-size eshell-ls-default-blocksize
))
385 (unless listing-style
386 (setq listing-style
'by-columns
))
388 (setq args
(list ".")))
389 (let ((eshell-ls-exclude-regexp eshell-ls-exclude-regexp
) ange-cache
)
391 (unless (eshell-using-module 'eshell-glob
)
392 (error (concat "-I option requires that `eshell-glob'"
393 " be a member of `eshell-modules-list'")))
394 (set-text-properties 0 (length ignore-pattern
) nil ignore-pattern
)
395 (setq eshell-ls-exclude-regexp
396 (if eshell-ls-exclude-regexp
397 (concat "\\(" eshell-ls-exclude-regexp
"\\|"
398 (eshell-glob-regexp ignore-pattern
) "\\)")
399 (eshell-glob-regexp ignore-pattern
))))
404 (cons (if (and (eshell-under-windows-p)
405 (file-name-absolute-p arg
))
406 (expand-file-name arg
)
408 (eshell-file-attributes arg
))))
410 t
(expand-file-name default-directory
)))
411 (funcall flush-func
)))
413 (defsubst eshell-ls-printable-size
(filesize &optional by-blocksize
)
414 "Return a printable FILESIZE."
415 (eshell-printable-size filesize human-readable
416 (and by-blocksize block-size
)
417 eshell-ls-use-colors
))
419 (defsubst eshell-ls-size-string
(attrs size-width
)
420 "Return the size string for ATTRS length, using SIZE-WIDTH."
421 (let* ((str (eshell-ls-printable-size (nth 7 attrs
) t
))
423 (if (< len size-width
)
424 (concat (make-string (- size-width len
) ?
) str
)
427 (defun eshell-ls-annotate (fileinfo)
428 "Given a FILEINFO object, return a resolved, decorated FILEINFO.
429 This means resolving any symbolic links, determining what face the
430 name should be displayed as, etc. Think of it as cooking a FILEINFO."
431 (if (not (and (stringp (cadr fileinfo
))
432 (or dereference-links
433 (eq listing-style
'long-listing
))))
434 (setcar fileinfo
(eshell-ls-decorated-name fileinfo
))
436 (unless (file-name-absolute-p (cadr fileinfo
))
437 (setq dir
(file-truename
439 (expand-file-name (car fileinfo
))))))
441 (eshell-file-attributes
442 (let ((target (if dir
443 (expand-file-name (cadr fileinfo
) dir
)
445 (if dereference-links
446 (file-truename target
)
448 (if (or dereference-links
449 (string-match "^\\.\\.?$" (car fileinfo
)))
451 (setcdr fileinfo attr
)
452 (setcar fileinfo
(eshell-ls-decorated-name fileinfo
)))
453 (assert (eq listing-style
'long-listing
))
455 (concat (eshell-ls-decorated-name fileinfo
) " -> "
456 (eshell-ls-decorated-name
457 (cons (cadr fileinfo
) attr
)))))))
460 (defun eshell-ls-file (fileinfo &optional size-width copy-fileinfo
)
461 "Output FILE in long format.
462 FILE may be a string, or a cons cell whose car is the filename and
463 whose cdr is the list of file attributes."
464 (if (not (cdr fileinfo
))
465 (funcall error-func
(format "%s: No such file or directory\n"
468 (eshell-ls-annotate (if copy-fileinfo
472 (let ((file (car fileinfo
))
473 (attrs (cdr fileinfo
)))
474 (if (not (eq listing-style
'long-listing
))
476 (funcall insert-func
(eshell-ls-size-string attrs size-width
)
478 (funcall insert-func file
"\n"))
482 (concat (eshell-ls-size-string attrs size-width
) " "))
485 (or (nth 8 attrs
) "??????????")
487 (or (let ((user (nth 2 attrs
)))
488 (and (not numeric-uid-gid
)
492 (user-login-name user
)
496 (or (let ((group (nth 3 attrs
)))
497 (and (not numeric-uid-gid
)
501 (eshell-group-name group
)
505 (let* ((str (eshell-ls-printable-size (nth 7 attrs
)))
507 (if (< len
(or size-width
4))
508 (concat (make-string (- (or size-width
4) len
) ?
) str
)
510 " " (format-time-string
513 (if (= (nth 5 (decode-time (current-time)))
516 ((eq sort-method
'by-atime
) 4)
517 ((eq sort-method
'by-ctime
) 6)
521 ((eq sort-method
'by-atime
) 4)
522 ((eq sort-method
'by-ctime
) 6)
523 (t 5)) attrs
)) " ")))
524 (funcall insert-func line file
"\n"))))))
526 (defun eshell-ls-dir (dirinfo &optional insert-name root-dir size-width
)
527 "Output the entries in DIRINFO.
528 If INSERT-NAME is non-nil, the name of DIRINFO will be output. If
529 ROOT-DIR is also non-nil, and a directory name, DIRINFO will be output
530 relative to that directory."
531 (let ((dir (car dirinfo
)))
532 (if (not (cdr dirinfo
))
533 (funcall error-func
(format "%s: No such file or directory\n" dir
))
535 (eshell-ls-file dirinfo size-width
)
538 (eshell-ls-decorated-name
541 (file-relative-name dir root-dir
)
542 (expand-file-name dir
)))
543 (cdr dirinfo
))) ":\n"))
544 (let ((entries (eshell-directory-files-and-attributes
545 dir nil
(and (not show-all
)
546 eshell-ls-exclude-hidden
548 (when (and (not show-all
) eshell-ls-exclude-regexp
)
549 (while (and entries
(string-match eshell-ls-exclude-regexp
551 (setq entries
(cdr entries
)))
554 (if (string-match eshell-ls-exclude-regexp
(car (cadr e
)))
557 (when (or (eq listing-style
'long-listing
) show-size
)
560 (eshell-for e entries
562 (setq total
(+ total
(nth 7 (cdr e
)))
565 (length (eshell-ls-printable-size
566 (nth 7 (cdr e
)) t
))))))
567 (funcall insert-func
"total "
568 (eshell-ls-printable-size total t
) "\n")))
569 (let ((default-directory (expand-file-name dir
)))
572 (let ((e entries
) (good-entries (list t
)))
574 (unless (let ((len (length (caar e
))))
575 (and (eq (aref (caar e
) 0) ?.
)
578 (eq (aref (caar e
) 1) ?.
)))))
579 (nconc good-entries
(list (car e
))))
583 (eshell-ls-files (eshell-ls-sort-entries entries
)
586 (defsubst eshell-ls-compare-entries
(l r inx func
)
587 "Compare the time of two files, L and R, the attribute indexed by INX."
588 (let ((lt (nth inx
(cdr l
)))
589 (rt (nth inx
(cdr r
))))
591 (string-lessp (directory-file-name (car l
))
592 (directory-file-name (car r
)))
593 (funcall func rt lt
))))
595 (defun eshell-ls-sort-entries (entries)
596 "Sort the given ENTRIES, which may be files, directories or both.
597 In Eshell's implementation of ls, ENTRIES is always reversed."
598 (if (eq sort-method
'unsorted
)
605 ((eq sort-method
'by-atime
)
606 (eshell-ls-compare-entries l r
4 'eshell-time-less-p
))
607 ((eq sort-method
'by-mtime
)
608 (eshell-ls-compare-entries l r
5 'eshell-time-less-p
))
609 ((eq sort-method
'by-ctime
)
610 (eshell-ls-compare-entries l r
6 'eshell-time-less-p
))
611 ((eq sort-method
'by-size
)
612 (eshell-ls-compare-entries l r
7 '<))
613 ((eq sort-method
'by-extension
)
614 (let ((lx (file-name-extension
615 (directory-file-name (car l
))))
616 (rx (file-name-extension
617 (directory-file-name (car r
)))))
619 ((or (and (not lx
) (not rx
))
621 (string-lessp (directory-file-name (car l
))
622 (directory-file-name (car r
))))
626 (string-lessp lx rx
)))))
628 (string-lessp (directory-file-name (car l
))
629 (directory-file-name (car r
)))))))
634 (defun eshell-ls-files (files &optional size-width copy-fileinfo
)
635 "Output a list of FILES.
636 Each member of FILES is either a string or a cons cell of the form
638 ;; Mimic behavior of coreutils ls, which lists a single file per
639 ;; line when output is not a tty. Exceptions: if -x was supplied,
640 ;; or if we are the _last_ command in a pipeline.
641 ;; FIXME Not really the same since not testing output destination.
642 (if (or (and eshell-in-pipeline-p
643 (not (eq eshell-in-pipeline-p
'last
))
644 (not (eq listing-style
'by-lines
)))
645 (memq listing-style
'(long-listing single-column
)))
646 (eshell-for file files
648 (eshell-ls-file file size-width copy-fileinfo
)))
659 (format "%s: No such file or directory\n" (caar f
))))
661 (setq files
(cdr files
)
668 (setcdr f
(cddr f
))))))
670 (setq display-files
(mapcar 'eshell-ls-annotate files
))
671 (eshell-for file files
672 (let* ((str (eshell-ls-printable-size (nth 7 (cdr file
)) t
))
674 (if (< len size-width
)
675 (setq str
(concat (make-string (- size-width len
) ?
) str
)))
676 (setq file
(eshell-ls-annotate file
)
677 display-files
(cons (cons (concat str
" " (car file
))
680 (setq display-files
(nreverse display-files
)))
682 (if (eq listing-style
'by-columns
)
683 (eshell-ls-find-column-lengths display-files
)
684 (assert (eq listing-style
'by-lines
))
685 (eshell-ls-find-column-widths display-files
)))
686 (col-widths (car col-vals
))
687 (display-files (cdr col-vals
))
688 (columns (length col-widths
))
691 (eshell-for file display-files
695 (concat (substring (car file
) 0 size-width
)
696 (eshell-ls-decorated-name
697 (cons (substring (car file
) size-width
)
699 (eshell-ls-decorated-name file
))
701 (if (< col-index columns
)
703 (concat need-return name
705 (max 0 (- (aref col-widths
708 col-index
(1+ col-index
))
709 (funcall insert-func need-return name
"\n")
710 (setq col-index
1 need-return nil
))))
712 (funcall insert-func need-return
"\n"))))))
714 (defun eshell-ls-entries (entries &optional separate root-dir
)
715 "Output PATH's directory ENTRIES, formatted according to OPTIONS.
716 Each member of ENTRIES may either be a string or a cons cell, the car
717 of which is the file name, and the cdr of which is the list of
719 If SEPARATE is non-nil, directories name will be entirely separated
720 from the filenames. This is the normal behavior, except when doing a
722 ROOT-DIR, if non-nil, specifies the root directory of the listing, to
723 which non-absolute directory names will be made relative if ever they
725 (let (dirs files show-names need-return
(size-width 0))
726 (eshell-for entry entries
727 (if (and (not dir-literal
)
728 (or (eshell-ls-filetype-p (cdr entry
) ?d
)
729 (and (eshell-ls-filetype-p (cdr entry
) ?l
)
730 (file-directory-p (car entry
)))))
733 (setq files
(cons entry files
)
737 (length (eshell-ls-printable-size
738 (nth 7 (cdr entry
)) t
))))))
739 (setq dirs
(cons entry dirs
)))
740 (setq files
(cons entry files
)
744 (length (eshell-ls-printable-size
745 (nth 7 (cdr entry
)) t
)))))))
747 (eshell-ls-files (eshell-ls-sort-entries files
)
748 size-width show-recursive
)
749 (setq need-return t
))
750 (setq show-names
(or show-recursive
751 (> (+ (length files
) (length dirs
)) 1)))
752 (eshell-for dir
(eshell-ls-sort-entries dirs
)
753 (if (and need-return
(not dir-literal
))
754 (funcall insert-func
"\n"))
755 (eshell-ls-dir dir show-names
756 (unless (file-name-absolute-p (car dir
)) root-dir
)
758 (setq need-return t
))))
760 (defun eshell-ls-find-column-widths (files)
761 "Find the best fitting column widths for FILES.
762 It will be returned as a vector, whose length is the number of columns
763 to use, and each member of which is the width of that column
764 \(including spacing)."
771 (+ 2 (length (car file
)))))
773 ;; must account for the added space...
774 (max-width (+ (window-width) 2))
778 ;; determine the largest number of columns in the first row
780 (while (and w
(< width max-width
))
781 (setq width
(+ width
(car w
))
785 ;; refine it based on the following rows
788 (colw (make-vector numcols
0))
793 (aset colw i
(max (aref colw i
) (car w
)))
794 (setq w
(cdr w
) i
(1+ i
)))
797 (setq width
(+ width
(aref colw i
))
799 (if (and (< width max-width
)
800 (> width best-width
))
801 (setq col-widths colw
803 (setq numcols
(1- numcols
)))
805 (cons (or col-widths
(vector max-width
)) files
)))
807 (defun eshell-ls-find-column-lengths (files)
808 "Find the best fitting column lengths for FILES.
809 It will be returned as a vector, whose length is the number of columns
810 to use, and each member of which is the width of that column
811 \(including spacing)."
818 (+ 2 (length (car file
)))))
820 (max-width (+ (window-width) 2))
824 ;; refine it based on the following rows
826 (let* ((rows (ceiling (/ (length widths
)
829 (len (* rows numcols
))
833 (unless (or (= rows
0)
834 (<= (/ (length widths
) (float rows
))
835 (float (1- numcols
))))
836 (setq colw
(make-vector numcols
0))
839 (setq i
0 index
(1+ index
)))
842 (or (nth (+ (* i rows
) index
) w
) 0)))
843 (setq len
(1- len
) i
(1+ i
)))
846 (setq width
(+ width
(aref colw i
))
848 (if (>= width max-width
)
851 (setq col-widths colw
))
852 (if (>= numcols
(length widths
))
854 (setq numcols
(1+ numcols
))))))
857 (cons (vector max-width
) files
)
858 (setq numcols
(length col-widths
))
859 (let* ((rows (ceiling (/ (length widths
)
861 (len (* rows numcols
))
862 (newfiles (make-list len nil
))
868 (setq i
0 index
(1+ index
)))
869 (setcar (nthcdr j newfiles
)
870 (nth (+ (* i rows
) index
) files
))
871 (setq j
(1+ j
) i
(1+ i
)))
872 (cons col-widths newfiles
)))))
874 (defun eshell-ls-decorated-name (file)
875 "Return FILE, possibly decorated."
876 (if eshell-ls-use-colors
882 ((stringp (cadr file
))
886 'eshell-ls-directory
)
888 ((not (eshell-ls-filetype-p (cdr file
) ?-
))
891 ((and (/= (user-uid) 0) ; root can execute anything
892 (eshell-ls-applicable (cdr file
) 3
893 'file-executable-p
(car file
)))
894 'eshell-ls-executable
)
896 ((not (eshell-ls-applicable (cdr file
) 1
897 'file-readable-p
(car file
)))
898 'eshell-ls-unreadable
)
900 ((string-match eshell-ls-archive-regexp
(car file
))
903 ((string-match eshell-ls-backup-regexp
(car file
))
906 ((string-match eshell-ls-product-regexp
(car file
))
909 ((string-match eshell-ls-clutter-regexp
(car file
))
912 ((not (eshell-ls-applicable (cdr file
) 2
913 'file-writable-p
(car file
)))
915 (eshell-ls-highlight-alist
916 (let ((tests eshell-ls-highlight-alist
)
919 (if (funcall (caar tests
) (car file
) (cdr file
))
920 (setq value
(cdar tests
) tests nil
)
921 (setq tests
(cdr tests
))))
924 (add-text-properties 0 (length (car file
))
932 ;; generated-autoload-file: "esh-groups.el"
935 ;; arch-tag: 9295181c-0cb2-499c-999b-89f5359842cb
936 ;;; em-ls.el ends here