Mercurial > emacs
annotate lisp/eshell/esh-util.el @ 86990:215c0c9ff916
Move to ../net.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 02 Dec 2007 21:50:44 +0000 |
parents | 59b6ce989ba4 |
children | 7a4a3f1c72ee |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37664
diff
changeset
|
1 ;;; esh-util.el --- general utilities |
29870 | 2 |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
75346 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
29870 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29870 | 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) |
29870 | 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. | |
29870 | 24 |
25 (provide 'esh-util) | |
26 | |
27 (eval-when-compile (require 'esh-maint)) | |
28 | |
29 (defgroup eshell-util nil | |
30 "This is general utility code, meant for use by Eshell itself." | |
31 :tag "General utilities" | |
32 :group 'eshell) | |
33 | |
34 ;;; Commentary: | |
35 | |
36 (require 'pp) | |
37 | |
38 ;;; User Variables: | |
39 | |
33020 | 40 (defcustom eshell-stringify-t t |
41 "*If non-nil, the string representation of t is 't'. | |
42 If nil, t will be represented only in the exit code of the function, | |
43 and not printed as a string. This causes Lisp functions to behave | |
44 similarly to external commands, as far as successful result output." | |
45 :type 'boolean | |
46 :group 'eshell-util) | |
47 | |
29870 | 48 (defcustom eshell-group-file "/etc/group" |
49 "*If non-nil, the name of the group file on your system." | |
50 :type '(choice (const :tag "No group file" nil) file) | |
51 :group 'eshell-util) | |
52 | |
53 (defcustom eshell-passwd-file "/etc/passwd" | |
54 "*If non-nil, the name of the passwd file on your system." | |
55 :type '(choice (const :tag "No passwd file" nil) file) | |
56 :group 'eshell-util) | |
57 | |
58 (defcustom eshell-hosts-file "/etc/hosts" | |
59 "*The name of the /etc/hosts file." | |
60 :type '(choice (const :tag "No hosts file" nil) file) | |
61 :group 'eshell-util) | |
62 | |
63 (defcustom eshell-handle-errors t | |
64 "*If non-nil, Eshell will handle errors itself. | |
65 Setting this to nil is offered as an aid to debugging only." | |
66 :type 'boolean | |
67 :group 'eshell-util) | |
68 | |
69 (defcustom eshell-private-file-modes 384 ; umask 177 | |
70 "*The file-modes value to use for creating \"private\" files." | |
71 :type 'integer | |
72 :group 'eshell-util) | |
73 | |
74 (defcustom eshell-private-directory-modes 448 ; umask 077 | |
75 "*The file-modes value to use for creating \"private\" directories." | |
76 :type 'integer | |
77 :group 'eshell-util) | |
78 | |
79 (defcustom eshell-tar-regexp | |
80 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'" | |
81 "*Regular expression used to match tar file names." | |
82 :type 'regexp | |
83 :group 'eshell-util) | |
84 | |
85 (defcustom eshell-convert-numeric-arguments t | |
86 "*If non-nil, converting arguments of numeric form to Lisp numbers. | |
87 Numeric form is tested using the regular expression | |
37664
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
88 `eshell-number-regexp'. |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
89 |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
90 NOTE: If you find that numeric conversions are intefering with the |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
91 specification of filenames (for example, in calling `find-file', or |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
92 some other Lisp function that deals with files, not numbers), add the |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
93 following in your .emacs file: |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
94 |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
95 (put 'find-file 'eshell-no-numeric-conversions t) |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
96 |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
97 Any function with the property `eshell-no-numeric-conversions' set to |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
98 a non-nil value, will be passed strings, not numbers, even when an |
74b3a3b5aa87
(eshell-convert-numeric-arguments): Annotated the documentation string
John Wiegley <johnw@newartisans.com>
parents:
37659
diff
changeset
|
99 argument matches `eshell-number-regexp'." |
29870 | 100 :type 'boolean |
101 :group 'eshell-util) | |
102 | |
37659
7dc0e015c205
(eshell-number-regexp): Now that number conversions only happen for
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
103 (defcustom eshell-number-regexp "-?\\([0-9]*\\.\\)?[0-9]+\\(e[-0-9.]+\\)?" |
29870 | 104 "*Regular expression used to match numeric arguments. |
105 If `eshell-convert-numeric-arguments' is non-nil, and an argument | |
106 matches this regexp, it will be converted to a Lisp number, using the | |
107 function `string-to-number'." | |
108 :type 'regexp | |
109 :group 'eshell-util) | |
110 | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
111 (defcustom eshell-ange-ls-uids nil |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
112 "*List of user/host/id strings, used to determine remote ownership." |
35588 | 113 :type '(repeat (cons :tag "Host for User/UID map" |
114 (string :tag "Hostname") | |
115 (repeat (cons :tag "User/UID List" | |
116 (string :tag "Username") | |
117 (repeat :tag "UIDs" string))))) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
118 :group 'eshell-util) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
119 |
29870 | 120 ;;; Internal Variables: |
121 | |
122 (defvar eshell-group-names nil | |
123 "A cache to hold the names of groups.") | |
124 | |
125 (defvar eshell-group-timestamp nil | |
126 "A timestamp of when the group file was read.") | |
127 | |
128 (defvar eshell-user-names nil | |
129 "A cache to hold the names of users.") | |
130 | |
131 (defvar eshell-user-timestamp nil | |
132 "A timestamp of when the user file was read.") | |
133 | |
134 (defvar eshell-host-names nil | |
135 "A cache the names of frequently accessed hosts.") | |
136 | |
137 (defvar eshell-host-timestamp nil | |
138 "A timestamp of when the hosts file was read.") | |
139 | |
140 ;;; Functions: | |
141 | |
142 (defsubst eshell-under-windows-p () | |
143 "Return non-nil if we are running under MS-DOS/Windows." | |
144 (memq system-type '(ms-dos windows-nt))) | |
145 | |
146 (defmacro eshell-condition-case (tag form &rest handlers) | |
147 "Like `condition-case', but only if `eshell-pass-through-errors' is nil." | |
148 (if eshell-handle-errors | |
149 `(condition-case ,tag | |
150 ,form | |
151 ,@handlers) | |
152 form)) | |
153 | |
154 (put 'eshell-condition-case 'lisp-indent-function 2) | |
155 | |
156 (defmacro eshell-deftest (module name label &rest forms) | |
157 (if (and (fboundp 'cl-compiling-file) (cl-compiling-file)) | |
158 nil | |
159 (let ((fsym (intern (concat "eshell-test--" (symbol-name name))))) | |
160 `(eval-when-compile | |
161 (ignore | |
162 (defun ,fsym () ,label | |
163 (eshell-run-test (quote ,module) (quote ,fsym) ,label | |
164 (quote (progn ,@forms))))))))) | |
165 | |
166 (put 'eshell-deftest 'lisp-indent-function 2) | |
167 | |
168 (defun eshell-find-delimiter | |
169 (open close &optional bound reverse-p backslash-p) | |
170 "From point, find the CLOSE delimiter corresponding to OPEN. | |
171 The matching is bounded by BOUND. | |
172 If REVERSE-P is non-nil, process the region backwards. | |
173 If BACKSLASH-P is non-nil, and OPEN and CLOSE are the same character, | |
174 then quoting is done by a backslash, rather than a doubled delimiter." | |
175 (save-excursion | |
176 (let ((depth 1) | |
177 (bound (or bound (point-max)))) | |
178 (if (if reverse-p | |
179 (eq (char-before) close) | |
180 (eq (char-after) open)) | |
181 (forward-char (if reverse-p -1 1))) | |
182 (while (and (> depth 0) | |
183 (funcall (if reverse-p '> '<) (point) bound)) | |
184 (let ((c (if reverse-p (char-before) (char-after))) nc) | |
185 (cond ((and (not reverse-p) | |
186 (or (not (eq open close)) | |
187 backslash-p) | |
188 (eq c ?\\) | |
189 (setq nc (char-after (1+ (point)))) | |
190 (or (eq nc open) (eq nc close))) | |
191 (forward-char 1)) | |
192 ((and reverse-p | |
193 (or (not (eq open close)) | |
194 backslash-p) | |
195 (or (eq c open) (eq c close)) | |
196 (eq (char-before (1- (point))) | |
197 ?\\)) | |
198 (forward-char -1)) | |
199 ((eq open close) | |
200 (if (eq c open) | |
201 (if (and (not backslash-p) | |
202 (eq (if reverse-p | |
203 (char-before (1- (point))) | |
204 (char-after (1+ (point)))) open)) | |
205 (forward-char (if reverse-p -1 1)) | |
206 (setq depth (1- depth))))) | |
207 ((= c open) | |
208 (setq depth (+ depth (if reverse-p -1 1)))) | |
209 ((= c close) | |
210 (setq depth (+ depth (if reverse-p 1 -1)))))) | |
211 (forward-char (if reverse-p -1 1))) | |
212 (if (= depth 0) | |
213 (if reverse-p (point) (1- (point))))))) | |
214 | |
215 (defun eshell-convert (string) | |
216 "Convert STRING into a more native looking Lisp object." | |
217 (if (not (stringp string)) | |
218 string | |
219 (let ((len (length string))) | |
220 (if (= len 0) | |
221 string | |
222 (if (eq (aref string (1- len)) ?\n) | |
223 (setq string (substring string 0 (1- len)))) | |
224 (if (string-match "\n" string) | |
225 (split-string string "\n") | |
226 (if (and eshell-convert-numeric-arguments | |
227 (string-match | |
228 (concat "\\`\\s-*" eshell-number-regexp | |
229 "\\s-*\\'") string)) | |
230 (string-to-number string) | |
231 string)))))) | |
232 | |
233 (defun eshell-sublist (l &optional n m) | |
234 "Return from LIST the N to M elements. | |
235 If N or M is nil, it means the end of the list." | |
45736
fa968fe464d3
(eshell-copy-list): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
236 (let* ((a (copy-sequence l)) |
29870 | 237 result) |
238 (if (and m (consp (nthcdr m a))) | |
239 (setcdr (nthcdr m a) nil)) | |
240 (if n | |
241 (setq a (nthcdr n a)) | |
242 (setq n (1- (length a)) | |
243 a (last a))) | |
244 a)) | |
245 | |
246 (defun eshell-split-path (path) | |
247 "Split a path into multiple subparts." | |
248 (let ((len (length path)) | |
249 (i 0) (li 0) | |
250 parts) | |
251 (if (and (eshell-under-windows-p) | |
252 (> len 2) | |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
253 (eq (aref path 0) ?/) |
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
254 (eq (aref path 1) ?/)) |
29870 | 255 (setq i 2)) |
256 (while (< i len) | |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
257 (if (and (eq (aref path i) ?/) |
29870 | 258 (not (get-text-property i 'escaped path))) |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
259 (setq parts (cons (if (= li i) "/" |
29870 | 260 (substring path li (1+ i))) parts) |
261 li (1+ i))) | |
262 (setq i (1+ i))) | |
263 (if (< li i) | |
264 (setq parts (cons (substring path li i) parts))) | |
265 (if (and (eshell-under-windows-p) | |
266 (string-match "\\`[A-Za-z]:\\'" (car (last parts)))) | |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
267 (setcar (last parts) (concat (car (last parts)) "/"))) |
29870 | 268 (nreverse parts))) |
269 | |
270 (defun eshell-to-flat-string (value) | |
271 "Make value a string. If separated by newlines change them to spaces." | |
272 (let ((text (eshell-stringify value))) | |
273 (if (string-match "\n+\\'" text) | |
274 (setq text (replace-match "" t t text))) | |
275 (while (string-match "\n+" text) | |
276 (setq text (replace-match " " t t text))) | |
277 text)) | |
278 | |
279 (defmacro eshell-for (for-var for-list &rest forms) | |
280 "Iterate through a list" | |
281 `(let ((list-iter ,for-list)) | |
282 (while list-iter | |
283 (let ((,for-var (car list-iter))) | |
284 ,@forms) | |
285 (setq list-iter (cdr list-iter))))) | |
286 | |
287 (put 'eshell-for 'lisp-indent-function 2) | |
288 | |
31241 | 289 (defun eshell-flatten-list (args) |
29870 | 290 "Flatten any lists within ARGS, so that there are no sublists." |
291 (let ((new-list (list t))) | |
292 (eshell-for a args | |
65168
b93526432c17
*** empty log message ***
John Wiegley <johnw@newartisans.com>
parents:
65164
diff
changeset
|
293 (if (and (listp a) |
29870 | 294 (listp (cdr a))) |
295 (nconc new-list (eshell-flatten-list a)) | |
296 (nconc new-list (list a)))) | |
297 (cdr new-list))) | |
298 | |
299 (defun eshell-uniqify-list (l) | |
300 "Remove occurring multiples in L. You probably want to sort first." | |
301 (let ((m l)) | |
302 (while m | |
303 (while (and (cdr m) | |
304 (string= (car m) | |
305 (cadr m))) | |
306 (setcdr m (cddr m))) | |
307 (setq m (cdr m)))) | |
308 l) | |
309 | |
310 (defun eshell-stringify (object) | |
311 "Convert OBJECT into a string value." | |
312 (cond | |
313 ((stringp object) object) | |
314 ((and (listp object) | |
315 (not (eq object nil))) | |
316 (let ((string (pp-to-string object))) | |
317 (substring string 0 (1- (length string))))) | |
318 ((numberp object) | |
319 (number-to-string object)) | |
320 (t | |
33020 | 321 (unless (and (eq object t) |
322 (not eshell-stringify-t)) | |
323 (pp-to-string object))))) | |
29870 | 324 |
325 (defsubst eshell-stringify-list (args) | |
326 "Convert each element of ARGS into a string value." | |
327 (mapcar 'eshell-stringify args)) | |
328 | |
329 (defsubst eshell-flatten-and-stringify (&rest args) | |
330 "Flatten and stringify all of the ARGS into a single string." | |
331 (mapconcat 'eshell-stringify (eshell-flatten-list args) " ")) | |
332 | |
333 ;; the next two are from GNUS, and really should be made part of Emacs | |
334 ;; some day | |
335 (defsubst eshell-time-less-p (t1 t2) | |
336 "Say whether time T1 is less than time T2." | |
337 (or (< (car t1) (car t2)) | |
338 (and (= (car t1) (car t2)) | |
339 (< (nth 1 t1) (nth 1 t2))))) | |
340 | |
341 (defsubst eshell-time-to-seconds (time) | |
342 "Convert TIME to a floating point number." | |
343 (+ (* (car time) 65536.0) | |
344 (cadr time) | |
345 (/ (or (car (cdr (cdr time))) 0) 1000000.0))) | |
346 | |
347 (defsubst eshell-directory-files (regexp &optional directory) | |
348 "Return a list of files in the given DIRECTORY matching REGEXP." | |
349 (directory-files (or directory default-directory) | |
350 directory regexp)) | |
351 | |
352 (defun eshell-regexp-arg (prompt) | |
353 "Return list of regexp and prefix arg using PROMPT." | |
354 (let* (;; Don't clobber this. | |
355 (last-command last-command) | |
356 (regexp (read-from-minibuffer prompt nil nil nil | |
357 'minibuffer-history-search-history))) | |
358 (list (if (string-equal regexp "") | |
359 (setcar minibuffer-history-search-history | |
360 (nth 1 minibuffer-history-search-history)) | |
361 regexp) | |
362 (prefix-numeric-value current-prefix-arg)))) | |
363 | |
364 (defun eshell-printable-size (filesize &optional human-readable | |
365 block-size use-colors) | |
366 "Return a printable FILESIZE." | |
367 (let ((size (float (or filesize 0)))) | |
368 (if human-readable | |
369 (if (< size human-readable) | |
370 (if (= (round size) 0) | |
371 "0" | |
372 (if block-size | |
373 "1.0k" | |
374 (format "%.0f" size))) | |
375 (setq size (/ size human-readable)) | |
376 (if (< size human-readable) | |
377 (if (<= size 9.94) | |
378 (format "%.1fk" size) | |
379 (format "%.0fk" size)) | |
380 (setq size (/ size human-readable)) | |
381 (if (< size human-readable) | |
382 (let ((str (if (<= size 9.94) | |
383 (format "%.1fM" size) | |
384 (format "%.0fM" size)))) | |
385 (if use-colors | |
386 (put-text-property 0 (length str) | |
387 'face 'bold str)) | |
388 str) | |
389 (setq size (/ size human-readable)) | |
390 (if (< size human-readable) | |
391 (let ((str (if (<= size 9.94) | |
392 (format "%.1fG" size) | |
393 (format "%.0fG" size)))) | |
394 (if use-colors | |
395 (put-text-property 0 (length str) | |
396 'face 'bold-italic str)) | |
397 str))))) | |
398 (if block-size | |
399 (setq size (/ size block-size))) | |
400 (format "%.0f" size)))) | |
401 | |
402 (defun eshell-winnow-list (entries exclude &optional predicates) | |
403 "Pare down the ENTRIES list using the EXCLUDE regexp, and PREDICATES. | |
404 The original list is not affected. If the result is only one element | |
405 long, it will be returned itself, rather than returning a one-element | |
406 list." | |
407 (let ((flist (list t)) | |
408 valid p listified) | |
409 (unless (listp entries) | |
410 (setq entries (list entries) | |
411 listified t)) | |
412 (eshell-for entry entries | |
413 (unless (and exclude (string-match exclude entry)) | |
414 (setq p predicates valid (null p)) | |
415 (while p | |
416 (if (funcall (car p) entry) | |
417 (setq valid t) | |
418 (setq p nil valid nil)) | |
419 (setq p (cdr p))) | |
420 (when valid | |
421 (nconc flist (list entry))))) | |
422 (if listified | |
423 (cadr flist) | |
424 (cdr flist)))) | |
425 | |
426 (defsubst eshell-redisplay () | |
427 "Allow Emacs to redisplay buffers." | |
428 ;; for some strange reason, Emacs 21 is prone to trigger an | |
429 ;; "args out of range" error in `sit-for', if this function | |
430 ;; runs while point is in the minibuffer and the users attempt | |
431 ;; to use completion. Don't ask me. | |
432 (ignore-errors (sit-for 0 0))) | |
433 | |
434 (defun eshell-read-passwd-file (file) | |
435 "Return an alist correlating gids to group names in FILE." | |
436 (let (names) | |
437 (when (file-readable-p file) | |
438 (with-temp-buffer | |
439 (insert-file-contents file) | |
440 (goto-char (point-min)) | |
441 (while (not (eobp)) | |
442 (let* ((fields | |
443 (split-string (buffer-substring | |
444 (point) (progn (end-of-line) | |
445 (point))) ":"))) | |
31240 | 446 (if (and (and fields (nth 0 fields) (nth 2 fields)) |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
447 (not (assq (string-to-number (nth 2 fields)) names))) |
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
448 (setq names (cons (cons (string-to-number (nth 2 fields)) |
29870 | 449 (nth 0 fields)) |
450 names)))) | |
451 (forward-line)))) | |
452 names)) | |
453 | |
454 (defun eshell-read-passwd (file result-var timestamp-var) | |
455 "Read the contents of /etc/passwd for user names." | |
456 (if (or (not (symbol-value result-var)) | |
457 (not (symbol-value timestamp-var)) | |
458 (eshell-time-less-p | |
459 (symbol-value timestamp-var) | |
460 (nth 5 (file-attributes file)))) | |
461 (progn | |
462 (set result-var (eshell-read-passwd-file file)) | |
463 (set timestamp-var (current-time)))) | |
464 (symbol-value result-var)) | |
465 | |
466 (defun eshell-read-group-names () | |
467 "Read the contents of /etc/group for group names." | |
468 (if eshell-group-file | |
469 (eshell-read-passwd eshell-group-file 'eshell-group-names | |
470 'eshell-group-timestamp))) | |
471 | |
472 (defsubst eshell-group-id (name) | |
473 "Return the user id for user NAME." | |
474 (car (rassoc name (eshell-read-group-names)))) | |
475 | |
476 (defsubst eshell-group-name (gid) | |
477 "Return the group name for the given GID." | |
478 (cdr (assoc gid (eshell-read-group-names)))) | |
479 | |
480 (defun eshell-read-user-names () | |
481 "Read the contents of /etc/passwd for user names." | |
482 (if eshell-passwd-file | |
483 (eshell-read-passwd eshell-passwd-file 'eshell-user-names | |
484 'eshell-user-timestamp))) | |
485 | |
486 (defsubst eshell-user-id (name) | |
487 "Return the user id for user NAME." | |
488 (car (rassoc name (eshell-read-user-names)))) | |
489 | |
490 (defalias 'eshell-user-name 'user-login-name) | |
491 | |
492 (defun eshell-read-hosts-file (filename) | |
493 "Read in the hosts from the /etc/hosts file." | |
494 (let (hosts) | |
495 (with-temp-buffer | |
496 (insert-file-contents eshell-hosts-file) | |
497 (goto-char (point-min)) | |
498 (while (re-search-forward | |
499 "^\\(\\S-+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t) | |
500 (if (match-string 1) | |
501 (add-to-list 'hosts (match-string 1))) | |
502 (if (match-string 2) | |
503 (add-to-list 'hosts (match-string 2))) | |
504 (if (match-string 4) | |
505 (add-to-list 'hosts (match-string 4))))) | |
506 (sort hosts 'string-lessp))) | |
507 | |
508 (defun eshell-read-hosts (file result-var timestamp-var) | |
509 "Read the contents of /etc/passwd for user names." | |
510 (if (or (not (symbol-value result-var)) | |
511 (not (symbol-value timestamp-var)) | |
512 (eshell-time-less-p | |
513 (symbol-value timestamp-var) | |
514 (nth 5 (file-attributes file)))) | |
515 (progn | |
516 (set result-var (eshell-read-hosts-file file)) | |
517 (set timestamp-var (current-time)))) | |
518 (symbol-value result-var)) | |
519 | |
520 (defun eshell-read-host-names () | |
521 "Read the contents of /etc/hosts for host names." | |
522 (if eshell-hosts-file | |
523 (eshell-read-hosts eshell-hosts-file 'eshell-host-names | |
524 'eshell-host-timestamp))) | |
525 | |
526 (unless (fboundp 'line-end-position) | |
527 (defsubst line-end-position (&optional N) | |
528 (save-excursion (end-of-line N) (point)))) | |
529 | |
530 (unless (fboundp 'line-beginning-position) | |
531 (defsubst line-beginning-position (&optional N) | |
532 (save-excursion (beginning-of-line N) (point)))) | |
533 | |
534 (unless (fboundp 'subst-char-in-string) | |
535 (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
536 "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
537 Unless optional argument INPLACE is non-nil, return a new string." | |
538 (let ((i (length string)) | |
539 (newstr (if inplace string (copy-sequence string)))) | |
540 (while (> i 0) | |
541 (setq i (1- i)) | |
542 (if (eq (aref newstr i) fromchar) | |
543 (aset newstr i tochar))) | |
544 newstr))) | |
545 | |
546 (defsubst eshell-copy-environment () | |
547 "Return an unrelated copy of `process-environment'." | |
548 (mapcar 'concat process-environment)) | |
549 | |
550 (defun eshell-subgroups (groupsym) | |
551 "Return all of the subgroups of GROUPSYM." | |
552 (let ((subgroups (get groupsym 'custom-group)) | |
553 (subg (list t))) | |
554 (while subgroups | |
555 (if (eq (cadr (car subgroups)) 'custom-group) | |
556 (nconc subg (list (caar subgroups)))) | |
557 (setq subgroups (cdr subgroups))) | |
558 (cdr subg))) | |
559 | |
560 (defmacro eshell-with-file-modes (modes &rest forms) | |
561 "Evaluate, with file-modes set to MODES, the given FORMS." | |
562 `(let ((modes (default-file-modes))) | |
563 (set-default-file-modes ,modes) | |
564 (unwind-protect | |
565 (progn ,@forms) | |
566 (set-default-file-modes modes)))) | |
567 | |
568 (defmacro eshell-with-private-file-modes (&rest forms) | |
569 "Evaluate FORMS with private file modes set." | |
570 `(eshell-with-file-modes ,eshell-private-file-modes ,@forms)) | |
571 | |
572 (defsubst eshell-make-private-directory (dir &optional parents) | |
573 "Make DIR with file-modes set to `eshell-private-directory-modes'." | |
574 (eshell-with-file-modes eshell-private-directory-modes | |
575 (make-directory dir parents))) | |
576 | |
577 (defsubst eshell-substring (string sublen) | |
578 "Return the beginning of STRING, up to SUBLEN bytes." | |
579 (if string | |
580 (if (> (length string) sublen) | |
581 (substring string 0 sublen) | |
582 string))) | |
583 | |
584 (unless (fboundp 'directory-files-and-attributes) | |
47963
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
585 (defun directory-files-and-attributes (directory &optional full match nosort) |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
586 "Return a list of names of files and their attributes in DIRECTORY. |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
587 There are three optional arguments: |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
588 If FULL is non-nil, return absolute file names. Otherwise return names |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
589 that are relative to the specified directory. |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
590 If MATCH is non-nil, mention only file names that match the regexp MATCH. |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
591 If NOSORT is non-nil, the list is not sorted--its order is unpredictable. |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
592 NOSORT is useful if you plan to sort the result yourself." |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
593 (let ((directory (expand-file-name directory)) ange-cache) |
29870 | 594 (mapcar |
595 (function | |
596 (lambda (file) | |
47963
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
597 (cons file (eshell-file-attributes (expand-file-name file directory))))) |
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
598 (directory-files directory full match nosort))))) |
29870 | 599 |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
600 (eval-when-compile |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
601 (defvar ange-cache)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
602 |
29870 | 603 (defun eshell-directory-files-and-attributes (dir &optional full match nosort) |
604 "Make sure to use the handler for `directory-file-and-attributes'." | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
605 (let* ((dir (expand-file-name dir)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
606 (dfh (find-file-name-handler dir 'directory-files))) |
29870 | 607 (if (not dfh) |
608 (directory-files-and-attributes dir full match nosort) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
609 (let ((files (funcall dfh 'directory-files dir full match nosort)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
610 (fah (find-file-name-handler dir 'file-attributes))) |
29870 | 611 (mapcar |
612 (function | |
613 (lambda (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
|
614 (cons file (if fah |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
615 (eshell-file-attributes |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
616 (expand-file-name file dir)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
617 (file-attributes (expand-file-name file dir)))))) |
29870 | 618 files))))) |
619 | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
620 (defun eshell-current-ange-uids () |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
621 (if (string-match "/\\([^@]+\\)@\\([^:]+\\):" default-directory) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
622 (let* ((host (match-string 2 default-directory)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
623 (user (match-string 1 default-directory)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
624 (host-users (assoc host eshell-ange-ls-uids))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
625 (when host-users |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
626 (setq host-users (cdr host-users)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
627 (cdr (assoc user host-users)))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
628 |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
629 ;; Add an autoload for parse-time-string |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
630 (if (and (not (fboundp 'parse-time-string)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
631 (locate-library "parse-time")) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
632 (autoload 'parse-time-string "parse-time")) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
633 |
32470
b338a85bdffc
Added a missing `require' form.
John Wiegley <johnw@newartisans.com>
parents:
32446
diff
changeset
|
634 (eval-when-compile |
86533
59b6ce989ba4
(top-level): Use require rather than load for ange-ftp.
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
635 (require 'ange-ftp nil t)) |
32470
b338a85bdffc
Added a missing `require' form.
John Wiegley <johnw@newartisans.com>
parents:
32446
diff
changeset
|
636 |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
637 (defun eshell-parse-ange-ls (dir) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
638 (let (entry) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
639 (with-temp-buffer |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
640 (insert (ange-ftp-ls dir "-la" nil)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
641 (goto-char (point-min)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
642 (if (looking-at "^total [0-9]+$") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
643 (forward-line 1)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
644 ;; Some systems put in a blank line here. |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
645 (if (eolp) (forward-line 1)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
646 (while (looking-at |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
647 `,(concat "\\([dlscb-][rwxst-]+\\)" |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
648 "\\s-*" "\\([0-9]+\\)" "\\s-+" |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
649 "\\(\\S-+\\)" "\\s-+" |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
650 "\\(\\S-+\\)" "\\s-+" |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
651 "\\([0-9]+\\)" "\\s-+" "\\(.*\\)")) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
652 (let* ((perms (match-string 1)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
653 (links (string-to-number (match-string 2))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
654 (user (match-string 3)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
655 (group (match-string 4)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
656 (size (string-to-number (match-string 5))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
657 (mtime |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
658 (if (fboundp 'parse-time-string) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
659 (let ((moment (parse-time-string |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
660 (match-string 6)))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
661 (if (nth 0 moment) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
662 (setcar (nthcdr 5 moment) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
663 (nth 5 (decode-time (current-time)))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
664 (setcar (nthcdr 0 moment) 0) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
665 (setcar (nthcdr 1 moment) 0) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
666 (setcar (nthcdr 2 moment) 0)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
667 (apply 'encode-time moment)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
668 (ange-ftp-file-modtime (expand-file-name name dir)))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
669 (name (ange-ftp-parse-filename)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
670 symlink) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
671 (if (string-match "\\(.+\\) -> \\(.+\\)" name) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
672 (setq symlink (match-string 2 name) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
673 name (match-string 1 name))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
674 (setq entry |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
675 (cons |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
676 (cons name |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
677 (list (if (eq (aref perms 0) ?d) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
678 t |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
679 symlink) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
680 links user group |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
681 nil mtime nil |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
682 size perms nil nil)) entry))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
683 (forward-line))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
684 entry)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
685 |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
686 (defun eshell-file-attributes (file) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
687 "Return the attributes of FILE, playing tricks if it's over ange-ftp." |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
688 (let* ((file (expand-file-name file)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
689 (handler (find-file-name-handler file 'file-attributes)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
690 entry) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
691 (if (not handler) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
692 (file-attributes file) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
693 (if (eq (find-file-name-handler (file-name-directory file) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
694 'directory-files) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
695 'ange-ftp-hook-function) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
696 (let ((base (file-name-nondirectory file)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
697 (dir (file-name-directory file))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
698 (if (boundp 'ange-cache) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
699 (setq entry (cdr (assoc base (cdr (assoc dir ange-cache)))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
700 (unless entry |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
701 (setq entry (eshell-parse-ange-ls dir)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
702 (if (boundp 'ange-cache) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
703 (setq ange-cache |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
704 (cons (cons dir entry) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
705 ange-cache))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
706 (if entry |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
707 (let ((fentry (assoc base (cdr entry)))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
708 (if fentry |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
709 (setq entry (cdr fentry)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
710 (setq entry nil))))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
711 (or entry (funcall handler 'file-attributes file))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
712 |
45741
b2a7c08cddcf
(eshell-copy-tree): Make it an alias for copy-tree.
Richard M. Stallman <rms@gnu.org>
parents:
45736
diff
changeset
|
713 (defalias 'eshell-copy-tree 'copy-tree) |
29870 | 714 |
31240 | 715 (defsubst eshell-processp (proc) |
716 "If the `processp' function does not exist, PROC is not a process." | |
717 (and (fboundp 'processp) (processp proc))) | |
718 | |
29870 | 719 ; (defun eshell-copy-file |
720 ; (file newname &optional ok-if-already-exists keep-date) | |
721 ; "Copy FILE to NEWNAME. See docs for `copy-file'." | |
722 ; (let (copied) | |
723 ; (if (string-match "\\`\\([^:]+\\):\\(.*\\)" file) | |
724 ; (let ((front (match-string 1 file)) | |
725 ; (back (match-string 2 file)) | |
726 ; buffer) | |
727 ; (if (and front (string-match eshell-tar-regexp front) | |
728 ; (setq buffer (find-file-noselect front))) | |
729 ; (with-current-buffer buffer | |
730 ; (goto-char (point-min)) | |
731 ; (if (re-search-forward (concat " " (regexp-quote back) | |
732 ; "$") nil t) | |
733 ; (progn | |
734 ; (tar-copy (if (file-directory-p newname) | |
735 ; (expand-file-name | |
736 ; (file-name-nondirectory back) newname) | |
737 ; newname)) | |
738 ; (setq copied t)) | |
739 ; (error "%s not found in tar file %s" back front)))))) | |
740 ; (unless copied | |
741 ; (copy-file file newname ok-if-already-exists keep-date)))) | |
742 | |
743 ; (defun eshell-file-attributes (filename) | |
744 ; "Return a list of attributes of file FILENAME. | |
745 ; See the documentation for `file-attributes'." | |
746 ; (let (result) | |
747 ; (when (string-match "\\`\\([^:]+\\):\\(.*\\)\\'" filename) | |
748 ; (let ((front (match-string 1 filename)) | |
749 ; (back (match-string 2 filename)) | |
750 ; buffer) | |
751 ; (when (and front (string-match eshell-tar-regexp front) | |
752 ; (setq buffer (find-file-noselect front))) | |
753 ; (with-current-buffer buffer | |
754 ; (goto-char (point-min)) | |
755 ; (when (re-search-forward (concat " " (regexp-quote back) | |
756 ; "\\s-*$") nil t) | |
757 ; (let* ((descrip (tar-current-descriptor)) | |
758 ; (tokens (tar-desc-tokens descrip))) | |
759 ; (setq result | |
760 ; (list | |
761 ; (cond | |
762 ; ((eq (tar-header-link-type tokens) 5) | |
763 ; t) | |
764 ; ((eq (tar-header-link-type tokens) t) | |
765 ; (tar-header-link-name tokens))) | |
766 ; 1 | |
767 ; (tar-header-uid tokens) | |
768 ; (tar-header-gid tokens) | |
769 ; (tar-header-date tokens) | |
770 ; (tar-header-date tokens) | |
771 ; (tar-header-date tokens) | |
772 ; (tar-header-size tokens) | |
773 ; (concat | |
774 ; (cond | |
775 ; ((eq (tar-header-link-type tokens) 5) "d") | |
776 ; ((eq (tar-header-link-type tokens) t) "l") | |
777 ; (t "-")) | |
778 ; (tar-grind-file-mode (tar-header-mode tokens) | |
779 ; (make-string 9 ? ) 0)) | |
780 ; nil nil nil)))))))) | |
781 ; (or result | |
782 ; (file-attributes filename)))) | |
783 | |
784 ;;; Code: | |
785 | |
52401 | 786 ;;; arch-tag: 70159778-5c7a-480a-bae4-3ad332fca19d |
29870 | 787 ;;; esh-util.el ends here |