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