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