Mercurial > emacs
annotate lisp/eshell/em-ls.el @ 66112:9bb08ad57594
*** empty log message ***
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Sun, 16 Oct 2005 02:23:23 +0000 |
parents | 34bd8e434dd7 |
children | 8c8902a666bf edf295560b5a |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37661
diff
changeset
|
1 ;;; em-ls.el --- implementation of ls in Lisp |
29876 | 2 |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64560
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004, |
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64560
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
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 2, or (at your option) | |
13 ;; any later version. | |
14 | |
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. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
29876 | 24 |
25 (provide 'em-ls) | |
26 | |
27 (eval-when-compile (require 'esh-maint)) | |
28 | |
29 (defgroup eshell-ls nil | |
30 "This module implements the \"ls\" utility fully in Lisp. If it is | |
31 passed any unrecognized command switches, it will revert to the | |
32 operating system's version. This version of \"ls\" uses text | |
33 properties to colorize its output based on the setting of | |
34 `eshell-ls-use-colors'." | |
35 :tag "Implementation of `ls' in Lisp" | |
36 :group 'eshell-module) | |
37 | |
38 ;;; Commentary: | |
39 | |
40 ;; Most of the command switches recognized by GNU's ls utility are | |
41 ;; supported ([(fileutils)ls invocation]). | |
42 | |
43 (require 'esh-util) | |
44 (require 'esh-opt) | |
45 | |
46 ;;; User Variables: | |
47 | |
48 (defvar eshell-ls-orig-insert-directory | |
49 (symbol-function 'insert-directory) | |
50 "Preserve the original definition of `insert-directory'.") | |
51 | |
52 (defcustom eshell-ls-unload-hook | |
53 (list | |
54 (function | |
55 (lambda () | |
56 (fset 'insert-directory eshell-ls-orig-insert-directory)))) | |
57 "*When unloading `eshell-ls', restore the definition of `insert-directory'." | |
58 :type 'hook | |
59 :group 'eshell-ls) | |
60 | |
33020 | 61 (defcustom eshell-ls-initial-args nil |
62 "*If non-nil, this list of args is included before any call to `ls'. | |
63 This is useful for enabling human-readable format (-h), for example." | |
64 :type '(repeat :tag "Arguments" string) | |
65 :group 'eshell-ls) | |
66 | |
39984
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
67 (defcustom eshell-ls-dired-initial-args nil |
64560
8e6e95602853
(eshell-ls-decorated-name): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
68 "*If non-nil, args is included before any call to `ls' in Dired. |
39984
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
69 This is useful for enabling human-readable format (-h), for example." |
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
70 :type '(repeat :tag "Arguments" string) |
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
71 :group 'eshell-ls) |
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
72 |
29876 | 73 (defcustom eshell-ls-use-in-dired nil |
64560
8e6e95602853
(eshell-ls-decorated-name): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
74 "*If non-nil, use `eshell-ls' to read directories in Dired." |
29876 | 75 :set (lambda (symbol value) |
76 (if value | |
77 (unless (and (boundp 'eshell-ls-use-in-dired) | |
78 eshell-ls-use-in-dired) | |
79 (fset 'insert-directory 'eshell-ls-insert-directory)) | |
80 (when (and (boundp 'eshell-ls-insert-directory) | |
81 eshell-ls-use-in-dired) | |
82 (fset 'insert-directory eshell-ls-orig-insert-directory))) | |
83 (setq eshell-ls-use-in-dired value)) | |
84 :type 'boolean | |
85 :require 'em-ls | |
86 :group 'eshell-ls) | |
87 | |
88 (defcustom eshell-ls-default-blocksize 1024 | |
89 "*The default blocksize to use when display file sizes with -s." | |
90 :type 'integer | |
91 :group 'eshell-ls) | |
92 | |
33020 | 93 (defcustom eshell-ls-exclude-regexp nil |
29876 | 94 "*Unless -a is specified, files matching this regexp will not be shown." |
35718
96d933eb13f4
(eshell-ls-exclude-regexp): Fix :type.
Dave Love <fx@gnu.org>
parents:
33020
diff
changeset
|
95 :type '(choice regexp (const nil)) |
29876 | 96 :group 'eshell-ls) |
97 | |
33020 | 98 (defcustom eshell-ls-exclude-hidden t |
99 "*Unless -a is specified, files beginning with . will not be shown. | |
100 Using this boolean, instead of `eshell-ls-exclude-regexp', is both | |
101 faster and conserves more memory." | |
102 :type 'boolean | |
103 :group 'eshell-ls) | |
104 | |
29876 | 105 (defcustom eshell-ls-use-colors t |
106 "*If non-nil, use colors in file listings." | |
107 :type 'boolean | |
108 :group 'eshell-ls) | |
109 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
110 (defface eshell-ls-directory |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
111 '((((class color) (background light)) (:foreground "Blue" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
112 (((class color) (background dark)) (:foreground "SkyBlue" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
113 (t (:weight bold))) |
29876 | 114 "*The face used for highlight directories." |
115 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
116 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
117 (put 'eshell-ls-directory-face 'face-alias 'eshell-ls-directory) |
29876 | 118 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
119 (defface eshell-ls-symlink |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
120 '((((class color) (background light)) (:foreground "Dark Cyan" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
121 (((class color) (background dark)) (:foreground "Cyan" :weight bold))) |
29876 | 122 "*The face used for highlight symbolic links." |
123 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
124 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
125 (put 'eshell-ls-symlink-face 'face-alias 'eshell-ls-symlink) |
29876 | 126 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
127 (defface eshell-ls-executable |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
128 '((((class color) (background light)) (:foreground "ForestGreen" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
129 (((class color) (background dark)) (:foreground "Green" :weight bold))) |
29876 | 130 "*The face used for highlighting executables (not directories, though)." |
131 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
132 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
133 (put 'eshell-ls-executable-face 'face-alias 'eshell-ls-executable) |
29876 | 134 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
135 (defface eshell-ls-readonly |
29876 | 136 '((((class color) (background light)) (:foreground "Brown")) |
137 (((class color) (background dark)) (:foreground "Pink"))) | |
138 "*The face used for highlighting read-only files." | |
139 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
140 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
141 (put 'eshell-ls-readonly-face 'face-alias 'eshell-ls-readonly) |
29876 | 142 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
143 (defface eshell-ls-unreadable |
29876 | 144 '((((class color) (background light)) (:foreground "Grey30")) |
145 (((class color) (background dark)) (:foreground "DarkGrey"))) | |
146 "*The face used for highlighting unreadable files." | |
147 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
148 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
149 (put 'eshell-ls-unreadable-face 'face-alias 'eshell-ls-unreadable) |
29876 | 150 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
151 (defface eshell-ls-special |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
152 '((((class color) (background light)) (:foreground "Magenta" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
153 (((class color) (background dark)) (:foreground "Magenta" :weight bold))) |
29876 | 154 "*The face used for highlighting non-regular files." |
155 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
156 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
157 (put 'eshell-ls-special-face 'face-alias 'eshell-ls-special) |
29876 | 158 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
159 (defface eshell-ls-missing |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
160 '((((class color) (background light)) (:foreground "Red" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
161 (((class color) (background dark)) (:foreground "Red" :weight bold))) |
64560
8e6e95602853
(eshell-ls-decorated-name): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
162 "*The face used for highlighting non-existent file names." |
29876 | 163 :group 'eshell-ls) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
164 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
165 (put 'eshell-ls-missing-face 'face-alias 'eshell-ls-missing) |
29876 | 166 |
167 (defcustom eshell-ls-archive-regexp | |
168 (concat "\\.\\(t\\(a[rz]\\|gz\\)\\|arj\\|lzh\\|" | |
169 "zip\\|[zZ]\\|gz\\|bz2\\|deb\\|rpm\\)\\'") | |
170 "*A regular expression that matches names of file archives. | |
171 This typically includes both traditional archives and compressed | |
172 files." | |
173 :type 'regexp | |
174 :group 'eshell-ls) | |
175 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
176 (defface eshell-ls-archive |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
177 '((((class color) (background light)) (:foreground "Orchid" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
178 (((class color) (background dark)) (:foreground "Orchid" :weight bold))) |
29876 | 179 "*The face used for highlighting archived and compressed file names." |
180 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
181 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
182 (put 'eshell-ls-archive-face 'face-alias 'eshell-ls-archive) |
29876 | 183 |
184 (defcustom eshell-ls-backup-regexp | |
185 "\\(\\`\\.?#\\|\\(\\.bak\\|~\\)\\'\\)" | |
186 "*A regular expression that matches names of backup files." | |
187 :type 'regexp | |
188 :group 'eshell-ls) | |
189 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
190 (defface eshell-ls-backup |
29876 | 191 '((((class color) (background light)) (:foreground "OrangeRed")) |
192 (((class color) (background dark)) (:foreground "LightSalmon"))) | |
193 "*The face used for highlighting backup file names." | |
194 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
195 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
196 (put 'eshell-ls-backup-face 'face-alias 'eshell-ls-backup) |
29876 | 197 |
198 (defcustom eshell-ls-product-regexp | |
48704
18ebc473a07d
(eshell-ls-product-regexp): Fix typo.
Andreas Schwab <schwab@suse.de>
parents:
46853
diff
changeset
|
199 "\\.\\(elc\\|o\\(bj\\)?\\|a\\|lib\\|res\\)\\'" |
29876 | 200 "*A regular expression that matches names of product files. |
201 Products are files that get generated from a source file, and hence | |
202 ought to be recreatable if they are deleted." | |
203 :type 'regexp | |
204 :group 'eshell-ls) | |
205 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
206 (defface eshell-ls-product |
29876 | 207 '((((class color) (background light)) (:foreground "OrangeRed")) |
208 (((class color) (background dark)) (:foreground "LightSalmon"))) | |
209 "*The face used for highlighting files that are build products." | |
210 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
211 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
212 (put 'eshell-ls-product-face 'face-alias 'eshell-ls-product) |
29876 | 213 |
214 (defcustom eshell-ls-clutter-regexp | |
215 "\\(^texput\\.log\\|^core\\)\\'" | |
216 "*A regular expression that matches names of junk files. | |
217 These are mainly files that get created for various reasons, but don't | |
218 really need to stick around for very long." | |
219 :type 'regexp | |
220 :group 'eshell-ls) | |
221 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
222 (defface eshell-ls-clutter |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
223 '((((class color) (background light)) (:foreground "OrangeRed" :weight bold)) |
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
39984
diff
changeset
|
224 (((class color) (background dark)) (:foreground "OrangeRed" :weight bold))) |
29876 | 225 "*The face used for highlighting junk file names." |
226 :group 'eshell-ls) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
227 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
228 (put 'eshell-ls-clutter-face 'face-alias 'eshell-ls-clutter) |
29876 | 229 |
230 (defsubst eshell-ls-filetype-p (attrs type) | |
231 "Test whether ATTRS specifies a directory." | |
232 (if (nth 8 attrs) | |
233 (eq (aref (nth 8 attrs) 0) type))) | |
234 | |
235 (defmacro eshell-ls-applicable (attrs index func file) | |
236 "Test whether, for ATTRS, the user UID can do what corresponds to INDEX. | |
237 This is really just for efficiency, to avoid having to stat the file | |
238 yet again." | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
239 `(if (numberp (nth 2 ,attrs)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
240 (if (= (user-uid) (nth 2 ,attrs)) |
33020 | 241 (not (eq (aref (nth 8 ,attrs) ,index) ?-)) |
242 (,(eval func) ,file)) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
243 (not (eq (aref (nth 8 ,attrs) |
33020 | 244 (+ ,index (if (member (nth 2 ,attrs) |
245 (eshell-current-ange-uids)) | |
246 0 6))) | |
247 ?-)))) | |
29876 | 248 |
249 (defcustom eshell-ls-highlight-alist nil | |
250 "*This alist correlates test functions to color. | |
251 The format of the members of this alist is | |
252 | |
253 (TEST-SEXP . FACE) | |
254 | |
255 If TEST-SEXP evals to non-nil, that face will be used to highlight the | |
256 name of the file. The first match wins. `file' and `attrs' are in | |
257 scope during the evaluation of TEST-SEXP." | |
258 :type '(repeat (cons function face)) | |
259 :group 'eshell-ls) | |
260 | |
261 ;;; Functions: | |
262 | |
263 (defun eshell-ls-insert-directory | |
264 (file switches &optional wildcard full-directory-p) | |
265 "Insert directory listing for FILE, formatted according to SWITCHES. | |
266 Leaves point after the inserted text. | |
267 SWITCHES may be a string of options, or a list of strings. | |
268 Optional third arg WILDCARD means treat FILE as shell wildcard. | |
269 Optional fourth arg FULL-DIRECTORY-P means file is a directory and | |
270 switches do not contain `d', so that a full listing is expected. | |
271 | |
272 This version of the function uses `eshell/ls'. If any of the switches | |
273 passed are not recognized, the operating system's version will be used | |
274 instead." | |
275 (let ((handler (find-file-name-handler file 'insert-directory))) | |
276 (if handler | |
277 (funcall handler 'insert-directory file switches | |
278 wildcard full-directory-p) | |
279 (if (stringp switches) | |
280 (setq switches (split-string switches))) | |
281 (let (eshell-current-handles | |
282 eshell-current-subjob-p) | |
283 ;; use the fancy highlighting in `eshell-ls' rather than font-lock | |
284 (when (and eshell-ls-use-colors | |
285 (featurep 'font-lock)) | |
286 (font-lock-mode -1) | |
37326
19d97e9f6689
(eshell-ls-insert-directory): Set font-lock-defaults to nil, to
John Wiegley <johnw@newartisans.com>
parents:
35718
diff
changeset
|
287 (setq font-lock-defaults nil) |
29876 | 288 (if (boundp 'font-lock-buffers) |
289 (set 'font-lock-buffers | |
290 (delq (current-buffer) | |
291 (symbol-value 'font-lock-buffers))))) | |
292 (let ((insert-func 'insert) | |
293 (error-func 'insert) | |
33020 | 294 (flush-func 'ignore) |
39984
5e4848f89017
(eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents:
38414
diff
changeset
|
295 eshell-ls-dired-initial-args) |
29876 | 296 (eshell-do-ls (append switches (list file)))))))) |
297 | |
298 (defsubst eshell/ls (&rest args) | |
299 "An alias version of `eshell-do-ls'." | |
300 (let ((insert-func 'eshell-buffered-print) | |
301 (error-func 'eshell-error) | |
302 (flush-func 'eshell-flush)) | |
303 (eshell-do-ls args))) | |
304 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37326
diff
changeset
|
305 (put 'eshell/ls 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37326
diff
changeset
|
306 |
29876 | 307 (eval-when-compile |
308 (defvar block-size) | |
309 (defvar dereference-links) | |
310 (defvar dir-literal) | |
311 (defvar error-func) | |
312 (defvar flush-func) | |
313 (defvar human-readable) | |
314 (defvar ignore-pattern) | |
315 (defvar insert-func) | |
316 (defvar listing-style) | |
317 (defvar numeric-uid-gid) | |
318 (defvar reverse-list) | |
319 (defvar show-all) | |
320 (defvar show-recursive) | |
321 (defvar show-size) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
322 (defvar sort-method) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
323 (defvar ange-cache)) |
29876 | 324 |
325 (defun eshell-do-ls (&rest args) | |
326 "Implementation of \"ls\" in Lisp, passing ARGS." | |
327 (funcall flush-func -1) | |
328 ;; process the command arguments, and begin listing files | |
329 (eshell-eval-using-options | |
33020 | 330 "ls" (if eshell-ls-initial-args |
331 (list eshell-ls-initial-args args) | |
332 args) | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
333 `((?a "all" nil show-all |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
334 "show all files in directory") |
29876 | 335 (?c nil by-ctime sort-method |
336 "sort by modification time") | |
337 (?d "directory" nil dir-literal | |
338 "list directory entries instead of contents") | |
339 (?k "kilobytes" 1024 block-size | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
340 "using 1024 as the block size") |
29876 | 341 (?h "human-readable" 1024 human-readable |
342 "print sizes in human readable format") | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
343 (?H "si" 1000 human-readable |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
344 "likewise, but use powers of 1000 not 1024") |
29876 | 345 (?I "ignore" t ignore-pattern |
346 "do not list implied entries matching pattern") | |
347 (?l nil long-listing listing-style | |
348 "use a long listing format") | |
349 (?n "numeric-uid-gid" nil numeric-uid-gid | |
350 "list numeric UIDs and GIDs instead of names") | |
351 (?r "reverse" nil reverse-list | |
352 "reverse order while sorting") | |
353 (?s "size" nil show-size | |
354 "print size of each file, in blocks") | |
355 (?t nil by-mtime sort-method | |
356 "sort by modification time") | |
357 (?u nil by-atime sort-method | |
358 "sort by last access time") | |
359 (?x nil by-lines listing-style | |
360 "list entries by lines instead of by columns") | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
361 (?C nil by-columns listing-style |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
362 "list entries by columns") |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
363 (?L "deference" nil dereference-links |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
364 "list entries pointed to by symbolic links") |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
365 (?R "recursive" nil show-recursive |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
366 "list subdirectories recursively") |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
367 (?S nil by-size sort-method |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
368 "sort by file size") |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
369 (?U nil unsorted sort-method |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
370 "do not sort; list entries in directory order") |
29876 | 371 (?X nil by-extension sort-method |
372 "sort alphabetically by entry extension") | |
373 (?1 nil single-column listing-style | |
374 "list one file per line") | |
375 (nil "help" nil nil | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
376 "show this usage display") |
29876 | 377 :external "ls" |
378 :usage "[OPTION]... [FILE]... | |
379 List information about the FILEs (the current directory by default). | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
380 Sort entries alphabetically across.") |
29876 | 381 ;; setup some defaults, based on what the user selected |
382 (unless block-size | |
383 (setq block-size eshell-ls-default-blocksize)) | |
384 (unless listing-style | |
385 (setq listing-style 'by-columns)) | |
386 (unless args | |
387 (setq args (list "."))) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
388 (let ((eshell-ls-exclude-regexp eshell-ls-exclude-regexp) ange-cache) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
389 (when ignore-pattern |
29876 | 390 (unless (eshell-using-module 'eshell-glob) |
391 (error (concat "-I option requires that `eshell-glob'" | |
392 " be a member of `eshell-modules-list'"))) | |
393 (set-text-properties 0 (length ignore-pattern) nil ignore-pattern) | |
33020 | 394 (setq eshell-ls-exclude-regexp |
395 (if eshell-ls-exclude-regexp | |
29876 | 396 (concat "\\(" eshell-ls-exclude-regexp "\\|" |
33020 | 397 (eshell-glob-regexp ignore-pattern) "\\)") |
398 (eshell-glob-regexp ignore-pattern)))) | |
29876 | 399 ;; list the files! |
400 (eshell-ls-entries | |
401 (mapcar (function | |
402 (lambda (arg) | |
403 (cons (if (and (eshell-under-windows-p) | |
404 (file-name-absolute-p arg)) | |
405 (expand-file-name arg) | |
406 arg) | |
33020 | 407 (eshell-file-attributes arg)))) |
408 args) | |
29876 | 409 t (expand-file-name default-directory))) |
410 (funcall flush-func))) | |
411 | |
412 (defsubst eshell-ls-printable-size (filesize &optional by-blocksize) | |
413 "Return a printable FILESIZE." | |
414 (eshell-printable-size filesize human-readable | |
415 (and by-blocksize block-size) | |
416 eshell-ls-use-colors)) | |
417 | |
418 (defsubst eshell-ls-size-string (attrs size-width) | |
419 "Return the size string for ATTRS length, using SIZE-WIDTH." | |
420 (let* ((str (eshell-ls-printable-size (nth 7 attrs) t)) | |
421 (len (length str))) | |
422 (if (< len size-width) | |
423 (concat (make-string (- size-width len) ? ) str) | |
424 str))) | |
425 | |
426 (defun eshell-ls-annotate (fileinfo) | |
427 "Given a FILEINFO object, return a resolved, decorated FILEINFO. | |
428 This means resolving any symbolic links, determining what face the | |
429 name should be displayed as, etc. Think of it as cooking a FILEINFO." | |
430 (if (not (and (stringp (cadr fileinfo)) | |
431 (or dereference-links | |
432 (eq listing-style 'long-listing)))) | |
433 (setcar fileinfo (eshell-ls-decorated-name fileinfo)) | |
434 (let (dir attr) | |
435 (unless (file-name-absolute-p (cadr fileinfo)) | |
436 (setq dir (file-truename | |
437 (file-name-directory | |
438 (expand-file-name (car fileinfo)))))) | |
439 (setq attr | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
440 (eshell-file-attributes |
29876 | 441 (let ((target (if dir |
442 (expand-file-name (cadr fileinfo) dir) | |
443 (cadr fileinfo)))) | |
444 (if dereference-links | |
445 (file-truename target) | |
446 target)))) | |
447 (if (or dereference-links | |
448 (string-match "^\\.\\.?$" (car fileinfo))) | |
449 (progn | |
450 (setcdr fileinfo attr) | |
451 (setcar fileinfo (eshell-ls-decorated-name fileinfo))) | |
452 (assert (eq listing-style 'long-listing)) | |
453 (setcar fileinfo | |
454 (concat (eshell-ls-decorated-name fileinfo) " -> " | |
455 (eshell-ls-decorated-name | |
456 (cons (cadr fileinfo) attr))))))) | |
457 fileinfo) | |
458 | |
459 (defun eshell-ls-file (fileinfo &optional size-width copy-fileinfo) | |
460 "Output FILE in long format. | |
461 FILE may be a string, or a cons cell whose car is the filename and | |
462 whose cdr is the list of file attributes." | |
463 (if (not (cdr fileinfo)) | |
464 (funcall error-func (format "%s: No such file or directory\n" | |
465 (car fileinfo))) | |
466 (setq fileinfo | |
467 (eshell-ls-annotate (if copy-fileinfo | |
468 (cons (car fileinfo) | |
469 (cdr fileinfo)) | |
470 fileinfo))) | |
471 (let ((file (car fileinfo)) | |
472 (attrs (cdr fileinfo))) | |
473 (if (not (eq listing-style 'long-listing)) | |
474 (if show-size | |
475 (funcall insert-func (eshell-ls-size-string attrs size-width) | |
476 " " file "\n") | |
477 (funcall insert-func file "\n")) | |
478 (let ((line | |
479 (concat | |
480 (if show-size | |
481 (concat (eshell-ls-size-string attrs size-width) " ")) | |
482 (format | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
483 "%s%4d %-8s %-8s " |
29876 | 484 (or (nth 8 attrs) "??????????") |
485 (or (nth 1 attrs) 0) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
486 (or (let ((user (nth 2 attrs))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
487 (and (not numeric-uid-gid) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
488 user |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
489 (eshell-substring |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
490 (if (numberp user) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
491 (user-login-name user) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
492 user) 8))) |
29876 | 493 (nth 2 attrs) |
494 "") | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
495 (or (let ((group (nth 3 attrs))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
496 (and (not numeric-uid-gid) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
497 group |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
498 (eshell-substring |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
499 (if (numberp group) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
500 (eshell-group-name group) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
501 group) 8))) |
29876 | 502 (nth 3 attrs) |
503 "")) | |
504 (let* ((str (eshell-ls-printable-size (nth 7 attrs))) | |
505 (len (length str))) | |
53080
76ece241e712
(eshell-ls-file): There are times with size-width is nil and
John Wiegley <johnw@newartisans.com>
parents:
53066
diff
changeset
|
506 (if (< len (or size-width 4)) |
76ece241e712
(eshell-ls-file): There are times with size-width is nil and
John Wiegley <johnw@newartisans.com>
parents:
53066
diff
changeset
|
507 (concat (make-string (- (or size-width 4) len) ? ) str) |
29876 | 508 str)) |
509 " " (format-time-string | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
510 (concat |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
511 "%b %e " |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
512 (if (= (nth 5 (decode-time (current-time))) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
513 (nth 5 (decode-time |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
514 (nth (cond |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
515 ((eq sort-method 'by-atime) 4) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
516 ((eq sort-method 'by-ctime) 6) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
517 (t 5)) attrs)))) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
518 "%H:%M" |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
519 " %Y")) (nth (cond |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
520 ((eq sort-method 'by-atime) 4) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
521 ((eq sort-method 'by-ctime) 6) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
522 (t 5)) attrs)) " "))) |
29876 | 523 (funcall insert-func line file "\n")))))) |
524 | |
525 (defun eshell-ls-dir (dirinfo &optional insert-name root-dir size-width) | |
526 "Output the entries in DIRINFO. | |
527 If INSERT-NAME is non-nil, the name of DIRINFO will be output. If | |
528 ROOT-DIR is also non-nil, and a directory name, DIRINFO will be output | |
529 relative to that directory." | |
530 (let ((dir (car dirinfo))) | |
531 (if (not (cdr dirinfo)) | |
532 (funcall error-func (format "%s: No such file or directory\n" dir)) | |
533 (if dir-literal | |
534 (eshell-ls-file dirinfo size-width) | |
535 (if insert-name | |
536 (funcall insert-func | |
537 (eshell-ls-decorated-name | |
538 (cons (concat | |
539 (if root-dir | |
540 (file-relative-name dir root-dir) | |
541 (expand-file-name dir))) | |
542 (cdr dirinfo))) ":\n")) | |
33020 | 543 (let ((entries (eshell-directory-files-and-attributes |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
544 dir nil (and (not show-all) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
545 eshell-ls-exclude-hidden |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
546 "\\`[^.]") t))) |
33020 | 547 (when (and (not show-all) eshell-ls-exclude-regexp) |
548 (while (and entries (string-match eshell-ls-exclude-regexp | |
549 (caar entries))) | |
29876 | 550 (setq entries (cdr entries))) |
551 (let ((e entries)) | |
552 (while (cdr e) | |
553 (if (string-match eshell-ls-exclude-regexp (car (cadr e))) | |
554 (setcdr e (cddr e)) | |
555 (setq e (cdr e)))))) | |
556 (when (or (eq listing-style 'long-listing) show-size) | |
557 (let ((total 0.0)) | |
558 (setq size-width 0) | |
559 (eshell-for e entries | |
560 (if (nth 7 (cdr e)) | |
561 (setq total (+ total (nth 7 (cdr e))) | |
562 size-width | |
563 (max size-width | |
564 (length (eshell-ls-printable-size | |
565 (nth 7 (cdr e)) t)))))) | |
566 (funcall insert-func "total " | |
567 (eshell-ls-printable-size total t) "\n"))) | |
568 (let ((default-directory (expand-file-name dir))) | |
569 (if show-recursive | |
570 (eshell-ls-entries | |
571 (let ((e entries) (good-entries (list t))) | |
572 (while e | |
573 (unless (let ((len (length (caar e)))) | |
574 (and (eq (aref (caar e) 0) ?.) | |
575 (or (= len 1) | |
576 (and (= len 2) | |
577 (eq (aref (caar e) 1) ?.))))) | |
578 (nconc good-entries (list (car e)))) | |
579 (setq e (cdr e))) | |
580 (cdr good-entries)) | |
581 nil root-dir) | |
582 (eshell-ls-files (eshell-ls-sort-entries entries) | |
583 size-width)))))))) | |
584 | |
585 (defsubst eshell-ls-compare-entries (l r inx func) | |
586 "Compare the time of two files, L and R, the attribute indexed by INX." | |
587 (let ((lt (nth inx (cdr l))) | |
588 (rt (nth inx (cdr r)))) | |
589 (if (equal lt rt) | |
590 (string-lessp (directory-file-name (car l)) | |
591 (directory-file-name (car r))) | |
592 (funcall func rt lt)))) | |
593 | |
594 (defun eshell-ls-sort-entries (entries) | |
595 "Sort the given ENTRIES, which may be files, directories or both. | |
596 In Eshell's implementation of ls, ENTRIES is always reversed." | |
597 (if (eq sort-method 'unsorted) | |
598 (nreverse entries) | |
599 (sort entries | |
600 (function | |
601 (lambda (l r) | |
602 (let ((result | |
603 (cond | |
604 ((eq sort-method 'by-atime) | |
33020 | 605 (eshell-ls-compare-entries l r 4 'eshell-time-less-p)) |
29876 | 606 ((eq sort-method 'by-mtime) |
33020 | 607 (eshell-ls-compare-entries l r 5 'eshell-time-less-p)) |
29876 | 608 ((eq sort-method 'by-ctime) |
33020 | 609 (eshell-ls-compare-entries l r 6 'eshell-time-less-p)) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
610 ((eq sort-method 'by-size) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
611 (eshell-ls-compare-entries l r 7 '<)) |
29876 | 612 ((eq sort-method 'by-extension) |
613 (let ((lx (file-name-extension | |
614 (directory-file-name (car l)))) | |
615 (rx (file-name-extension | |
616 (directory-file-name (car r))))) | |
617 (cond | |
618 ((or (and (not lx) (not rx)) | |
619 (equal lx rx)) | |
620 (string-lessp (directory-file-name (car l)) | |
621 (directory-file-name (car r)))) | |
622 ((not lx) t) | |
623 ((not rx) nil) | |
624 (t | |
625 (string-lessp lx rx))))) | |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
626 (t |
29876 | 627 (string-lessp (directory-file-name (car l)) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
628 (directory-file-name (car r))))))) |
29876 | 629 (if reverse-list |
630 (not result) | |
631 result))))))) | |
632 | |
633 (defun eshell-ls-files (files &optional size-width copy-fileinfo) | |
634 "Output a list of FILES. | |
635 Each member of FILES is either a string or a cons cell of the form | |
636 \(FILE . ATTRS)." | |
637 (if (memq listing-style '(long-listing single-column)) | |
638 (eshell-for file files | |
639 (if file | |
640 (eshell-ls-file file size-width copy-fileinfo))) | |
641 (let ((f files) | |
642 last-f | |
643 display-files | |
644 ignore) | |
645 (while f | |
646 (if (cdar f) | |
647 (setq last-f f | |
648 f (cdr f)) | |
649 (unless ignore | |
650 (funcall error-func | |
651 (format "%s: No such file or directory\n" (caar f)))) | |
652 (if (eq f files) | |
653 (setq files (cdr files) | |
654 f files) | |
655 (if (not (cdr f)) | |
656 (progn | |
657 (setcdr last-f nil) | |
658 (setq f nil)) | |
659 (setcar f (cadr f)) | |
660 (setcdr f (cddr f)))))) | |
661 (if (not show-size) | |
662 (setq display-files (mapcar 'eshell-ls-annotate files)) | |
663 (eshell-for file files | |
664 (let* ((str (eshell-ls-printable-size (nth 7 (cdr file)) t)) | |
665 (len (length str))) | |
666 (if (< len size-width) | |
667 (setq str (concat (make-string (- size-width len) ? ) str))) | |
668 (setq file (eshell-ls-annotate file) | |
669 display-files (cons (cons (concat str " " (car file)) | |
670 (cdr file)) | |
671 display-files)))) | |
672 (setq display-files (nreverse display-files))) | |
673 (let* ((col-vals | |
674 (if (eq listing-style 'by-columns) | |
675 (eshell-ls-find-column-lengths display-files) | |
676 (assert (eq listing-style 'by-lines)) | |
677 (eshell-ls-find-column-widths display-files))) | |
678 (col-widths (car col-vals)) | |
679 (display-files (cdr col-vals)) | |
680 (columns (length col-widths)) | |
681 (col-index 1) | |
682 need-return) | |
683 (eshell-for file display-files | |
684 (let ((name | |
685 (if (car file) | |
686 (if show-size | |
687 (concat (substring (car file) 0 size-width) | |
688 (eshell-ls-decorated-name | |
689 (cons (substring (car file) size-width) | |
690 (cdr file)))) | |
691 (eshell-ls-decorated-name file)) | |
692 ""))) | |
693 (if (< col-index columns) | |
694 (setq need-return | |
695 (concat need-return name | |
696 (make-string | |
697 (max 0 (- (aref col-widths | |
698 (1- col-index)) | |
699 (length name))) ? )) | |
700 col-index (1+ col-index)) | |
701 (funcall insert-func need-return name "\n") | |
702 (setq col-index 1 need-return nil)))) | |
703 (if need-return | |
704 (funcall insert-func need-return "\n")))))) | |
705 | |
706 (defun eshell-ls-entries (entries &optional separate root-dir) | |
707 "Output PATH's directory ENTRIES, formatted according to OPTIONS. | |
708 Each member of ENTRIES may either be a string or a cons cell, the car | |
709 of which is the file name, and the cdr of which is the list of | |
710 attributes. | |
711 If SEPARATE is non-nil, directories name will be entirely separated | |
712 from the filenames. This is the normal behavior, except when doing a | |
713 recursive listing. | |
714 ROOT-DIR, if non-nil, specifies the root directory of the listing, to | |
715 which non-absolute directory names will be made relative if ever they | |
716 need to be printed." | |
717 (let (dirs files show-names need-return (size-width 0)) | |
718 (eshell-for entry entries | |
719 (if (and (not dir-literal) | |
720 (or (eshell-ls-filetype-p (cdr entry) ?d) | |
721 (and (eshell-ls-filetype-p (cdr entry) ?l) | |
722 (file-directory-p (car entry))))) | |
723 (progn | |
724 (unless separate | |
725 (setq files (cons entry files) | |
726 size-width | |
727 (if show-size | |
728 (max size-width | |
729 (length (eshell-ls-printable-size | |
730 (nth 7 (cdr entry)) t)))))) | |
731 (setq dirs (cons entry dirs))) | |
732 (setq files (cons entry files) | |
733 size-width | |
734 (if show-size | |
735 (max size-width | |
736 (length (eshell-ls-printable-size | |
737 (nth 7 (cdr entry)) t))))))) | |
738 (when files | |
739 (eshell-ls-files (eshell-ls-sort-entries files) | |
740 size-width show-recursive) | |
741 (setq need-return t)) | |
742 (setq show-names (or show-recursive | |
743 (> (+ (length files) (length dirs)) 1))) | |
744 (eshell-for dir (eshell-ls-sort-entries dirs) | |
745 (if (and need-return (not dir-literal)) | |
746 (funcall insert-func "\n")) | |
747 (eshell-ls-dir dir show-names | |
33020 | 748 (unless (file-name-absolute-p (car dir)) root-dir) |
749 size-width) | |
29876 | 750 (setq need-return t)))) |
751 | |
752 (defun eshell-ls-find-column-widths (files) | |
753 "Find the best fitting column widths for FILES. | |
754 It will be returned as a vector, whose length is the number of columns | |
755 to use, and each member of which is the width of that column | |
756 \(including spacing)." | |
757 (let* ((numcols 0) | |
758 (width 0) | |
759 (widths | |
760 (mapcar | |
761 (function | |
762 (lambda (file) | |
763 (+ 2 (length (car file))))) | |
764 files)) | |
765 ;; must account for the added space... | |
766 (max-width (+ (window-width) 2)) | |
767 (best-width 0) | |
768 col-widths) | |
769 | |
770 ;; determine the largest number of columns in the first row | |
771 (let ((w widths)) | |
772 (while (and w (< width max-width)) | |
773 (setq width (+ width (car w)) | |
774 numcols (1+ numcols) | |
775 w (cdr w)))) | |
776 | |
777 ;; refine it based on the following rows | |
778 (while (> numcols 0) | |
779 (let ((i 0) | |
780 (colw (make-vector numcols 0)) | |
781 (w widths)) | |
782 (while w | |
783 (if (= i numcols) | |
784 (setq i 0)) | |
785 (aset colw i (max (aref colw i) (car w))) | |
786 (setq w (cdr w) i (1+ i))) | |
787 (setq i 0 width 0) | |
788 (while (< i numcols) | |
789 (setq width (+ width (aref colw i)) | |
790 i (1+ i))) | |
791 (if (and (< width max-width) | |
792 (> width best-width)) | |
793 (setq col-widths colw | |
794 best-width width))) | |
795 (setq numcols (1- numcols))) | |
796 | |
797 (cons (or col-widths (vector max-width)) files))) | |
798 | |
799 (defun eshell-ls-find-column-lengths (files) | |
800 "Find the best fitting column lengths for FILES. | |
801 It will be returned as a vector, whose length is the number of columns | |
802 to use, and each member of which is the width of that column | |
803 \(including spacing)." | |
804 (let* ((numcols 1) | |
805 (width 0) | |
806 (widths | |
807 (mapcar | |
808 (function | |
809 (lambda (file) | |
810 (+ 2 (length (car file))))) | |
811 files)) | |
812 (max-width (+ (window-width) 2)) | |
813 col-widths | |
814 colw) | |
815 | |
816 ;; refine it based on the following rows | |
817 (while numcols | |
818 (let* ((rows (ceiling (/ (length widths) | |
819 (float numcols)))) | |
820 (w widths) | |
821 (len (* rows numcols)) | |
822 (index 0) | |
823 (i 0)) | |
824 (setq width 0) | |
825 (unless (or (= rows 0) | |
826 (<= (/ (length widths) (float rows)) | |
827 (float (1- numcols)))) | |
828 (setq colw (make-vector numcols 0)) | |
829 (while (> len 0) | |
830 (if (= i numcols) | |
831 (setq i 0 index (1+ index))) | |
832 (aset colw i | |
833 (max (aref colw i) | |
834 (or (nth (+ (* i rows) index) w) 0))) | |
835 (setq len (1- len) i (1+ i))) | |
836 (setq i 0) | |
837 (while (< i numcols) | |
838 (setq width (+ width (aref colw i)) | |
839 i (1+ i)))) | |
840 (if (>= width max-width) | |
841 (setq numcols nil) | |
842 (if colw | |
843 (setq col-widths colw)) | |
844 (if (>= numcols (length widths)) | |
845 (setq numcols nil) | |
846 (setq numcols (1+ numcols)))))) | |
847 | |
848 (if (not col-widths) | |
849 (cons (vector max-width) files) | |
850 (setq numcols (length col-widths)) | |
851 (let* ((rows (ceiling (/ (length widths) | |
852 (float numcols)))) | |
853 (len (* rows numcols)) | |
854 (newfiles (make-list len nil)) | |
855 (index 0) | |
856 (i 0) | |
857 (j 0)) | |
858 (while (< j len) | |
859 (if (= i numcols) | |
860 (setq i 0 index (1+ index))) | |
861 (setcar (nthcdr j newfiles) | |
862 (nth (+ (* i rows) index) files)) | |
863 (setq j (1+ j) i (1+ i))) | |
864 (cons col-widths newfiles))))) | |
865 | |
866 (defun eshell-ls-decorated-name (file) | |
64560
8e6e95602853
(eshell-ls-decorated-name): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
867 "Return FILE, possibly decorated." |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
868 (if eshell-ls-use-colors |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
869 (let ((face |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
870 (cond |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
871 ((not (cdr file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
872 'eshell-ls-missing) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
873 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
874 ((stringp (cadr file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
875 'eshell-ls-symlink) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
876 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
877 ((eq (cadr file) t) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
878 'eshell-ls-directory) |
29876 | 879 |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
880 ((not (eshell-ls-filetype-p (cdr file) ?-)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
881 'eshell-ls-special) |
29876 | 882 |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
883 ((and (/= (user-uid) 0) ; root can execute anything |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
884 (eshell-ls-applicable (cdr file) 3 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
885 'file-executable-p (car file))) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
886 'eshell-ls-executable) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
887 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
888 ((not (eshell-ls-applicable (cdr file) 1 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
889 'file-readable-p (car file))) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
890 'eshell-ls-unreadable) |
29876 | 891 |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
892 ((string-match eshell-ls-archive-regexp (car file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
893 'eshell-ls-archive) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
894 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
895 ((string-match eshell-ls-backup-regexp (car file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
896 'eshell-ls-backup) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
897 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
898 ((string-match eshell-ls-product-regexp (car file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
899 'eshell-ls-product) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
900 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
901 ((string-match eshell-ls-clutter-regexp (car file)) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
902 'eshell-ls-clutter) |
29876 | 903 |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
904 ((not (eshell-ls-applicable (cdr file) 2 |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
905 'file-writable-p (car file))) |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
53080
diff
changeset
|
906 'eshell-ls-readonly) |
46853
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
907 (eshell-ls-highlight-alist |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
908 (let ((tests eshell-ls-highlight-alist) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
909 value) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
910 (while tests |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
911 (if (funcall (caar tests) (car file) (cdr file)) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
912 (setq value (cdar tests) tests nil) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
913 (setq tests (cdr tests)))) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
914 value))))) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
915 (if face |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
916 (add-text-properties 0 (length (car file)) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
917 (list 'face face) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
918 (car file))))) |
cb339473da3b
I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents:
46852
diff
changeset
|
919 (car file)) |
29876 | 920 |
921 ;;; Code: | |
922 | |
52401 | 923 ;;; arch-tag: 9295181c-0cb2-499c-999b-89f5359842cb |
29876 | 924 ;;; em-ls.el ends here |