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