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