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