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