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