Mercurial > emacs
annotate lisp/eshell/esh-util.el @ 95948:d55ec23f052d
*** empty log message ***
| author | Glenn Morris <rgm@gnu.org> |
|---|---|
| date | Sun, 15 Jun 2008 02:53:17 +0000 |
| parents | 45dbb3c749a6 |
| children | a9dc0e7c3f2b |
| 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, |
|
45dbb3c749a6
Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
| 29870 | 5 |
| 32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
| 7 | |
| 29870 | 8 ;; This file is part of GNU Emacs. |
| 9 | |
|
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 | |
| 240 (defun eshell-split-path (path) | |
| 241 "Split a path into multiple subparts." | |
| 242 (let ((len (length path)) | |
| 243 (i 0) (li 0) | |
| 244 parts) | |
| 245 (if (and (eshell-under-windows-p) | |
| 246 (> 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
|
247 (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
|
248 (eq (aref path 1) ?/)) |
| 29870 | 249 (setq i 2)) |
| 250 (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
|
251 (if (and (eq (aref path i) ?/) |
| 29870 | 252 (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
|
253 (setq parts (cons (if (= li i) "/" |
| 29870 | 254 (substring path li (1+ i))) parts) |
| 255 li (1+ i))) | |
| 256 (setq i (1+ i))) | |
| 257 (if (< li i) | |
| 258 (setq parts (cons (substring path li i) parts))) | |
| 259 (if (and (eshell-under-windows-p) | |
| 260 (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
|
261 (setcar (last parts) (concat (car (last parts)) "/"))) |
| 29870 | 262 (nreverse parts))) |
| 263 | |
| 264 (defun eshell-to-flat-string (value) | |
| 265 "Make value a string. If separated by newlines change them to spaces." | |
| 266 (let ((text (eshell-stringify value))) | |
| 267 (if (string-match "\n+\\'" text) | |
| 268 (setq text (replace-match "" t t text))) | |
| 269 (while (string-match "\n+" text) | |
| 270 (setq text (replace-match " " t t text))) | |
| 271 text)) | |
| 272 | |
| 273 (defmacro eshell-for (for-var for-list &rest forms) | |
| 274 "Iterate through a list" | |
| 275 `(let ((list-iter ,for-list)) | |
| 276 (while list-iter | |
| 277 (let ((,for-var (car list-iter))) | |
| 278 ,@forms) | |
| 279 (setq list-iter (cdr list-iter))))) | |
| 280 | |
| 281 (put 'eshell-for 'lisp-indent-function 2) | |
| 282 | |
| 31241 | 283 (defun eshell-flatten-list (args) |
| 29870 | 284 "Flatten any lists within ARGS, so that there are no sublists." |
| 285 (let ((new-list (list t))) | |
| 286 (eshell-for a args | |
|
65168
b93526432c17
*** empty log message ***
John Wiegley <johnw@newartisans.com>
parents:
65164
diff
changeset
|
287 (if (and (listp a) |
| 29870 | 288 (listp (cdr a))) |
| 289 (nconc new-list (eshell-flatten-list a)) | |
| 290 (nconc new-list (list a)))) | |
| 291 (cdr new-list))) | |
| 292 | |
| 293 (defun eshell-uniqify-list (l) | |
| 294 "Remove occurring multiples in L. You probably want to sort first." | |
| 295 (let ((m l)) | |
| 296 (while m | |
| 297 (while (and (cdr m) | |
| 298 (string= (car m) | |
| 299 (cadr m))) | |
| 300 (setcdr m (cddr m))) | |
| 301 (setq m (cdr m)))) | |
| 302 l) | |
| 303 | |
| 304 (defun eshell-stringify (object) | |
| 305 "Convert OBJECT into a string value." | |
| 306 (cond | |
| 307 ((stringp object) object) | |
| 308 ((and (listp object) | |
| 309 (not (eq object nil))) | |
| 310 (let ((string (pp-to-string object))) | |
| 311 (substring string 0 (1- (length string))))) | |
| 312 ((numberp object) | |
| 313 (number-to-string object)) | |
| 314 (t | |
| 33020 | 315 (unless (and (eq object t) |
| 316 (not eshell-stringify-t)) | |
| 317 (pp-to-string object))))) | |
| 29870 | 318 |
| 319 (defsubst eshell-stringify-list (args) | |
| 320 "Convert each element of ARGS into a string value." | |
| 321 (mapcar 'eshell-stringify args)) | |
| 322 | |
| 323 (defsubst eshell-flatten-and-stringify (&rest args) | |
| 324 "Flatten and stringify all of the ARGS into a single string." | |
| 325 (mapconcat 'eshell-stringify (eshell-flatten-list args) " ")) | |
| 326 | |
| 327 ;; the next two are from GNUS, and really should be made part of Emacs | |
| 328 ;; some day | |
| 329 (defsubst eshell-time-less-p (t1 t2) | |
| 330 "Say whether time T1 is less than time T2." | |
| 331 (or (< (car t1) (car t2)) | |
| 332 (and (= (car t1) (car t2)) | |
| 333 (< (nth 1 t1) (nth 1 t2))))) | |
| 334 | |
| 335 (defsubst eshell-time-to-seconds (time) | |
| 336 "Convert TIME to a floating point number." | |
| 337 (+ (* (car time) 65536.0) | |
| 338 (cadr time) | |
| 339 (/ (or (car (cdr (cdr time))) 0) 1000000.0))) | |
| 340 | |
| 341 (defsubst eshell-directory-files (regexp &optional directory) | |
| 342 "Return a list of files in the given DIRECTORY matching REGEXP." | |
| 343 (directory-files (or directory default-directory) | |
| 344 directory regexp)) | |
| 345 | |
| 346 (defun eshell-regexp-arg (prompt) | |
| 347 "Return list of regexp and prefix arg using PROMPT." | |
| 348 (let* (;; Don't clobber this. | |
| 349 (last-command last-command) | |
| 350 (regexp (read-from-minibuffer prompt nil nil nil | |
| 351 'minibuffer-history-search-history))) | |
| 352 (list (if (string-equal regexp "") | |
| 353 (setcar minibuffer-history-search-history | |
| 354 (nth 1 minibuffer-history-search-history)) | |
| 355 regexp) | |
| 356 (prefix-numeric-value current-prefix-arg)))) | |
| 357 | |
| 358 (defun eshell-printable-size (filesize &optional human-readable | |
| 359 block-size use-colors) | |
| 360 "Return a printable FILESIZE." | |
| 361 (let ((size (float (or filesize 0)))) | |
| 362 (if human-readable | |
| 363 (if (< size human-readable) | |
| 364 (if (= (round size) 0) | |
| 365 "0" | |
| 366 (if block-size | |
| 367 "1.0k" | |
| 368 (format "%.0f" size))) | |
| 369 (setq size (/ size human-readable)) | |
| 370 (if (< size human-readable) | |
| 371 (if (<= size 9.94) | |
| 372 (format "%.1fk" size) | |
| 373 (format "%.0fk" size)) | |
| 374 (setq size (/ size human-readable)) | |
| 375 (if (< size human-readable) | |
| 376 (let ((str (if (<= size 9.94) | |
| 377 (format "%.1fM" size) | |
| 378 (format "%.0fM" size)))) | |
| 379 (if use-colors | |
| 380 (put-text-property 0 (length str) | |
| 381 'face 'bold str)) | |
| 382 str) | |
| 383 (setq size (/ size human-readable)) | |
| 384 (if (< size human-readable) | |
| 385 (let ((str (if (<= size 9.94) | |
| 386 (format "%.1fG" size) | |
| 387 (format "%.0fG" size)))) | |
| 388 (if use-colors | |
| 389 (put-text-property 0 (length str) | |
| 390 'face 'bold-italic str)) | |
| 391 str))))) | |
| 392 (if block-size | |
| 393 (setq size (/ size block-size))) | |
| 394 (format "%.0f" size)))) | |
| 395 | |
| 396 (defun eshell-winnow-list (entries exclude &optional predicates) | |
| 397 "Pare down the ENTRIES list using the EXCLUDE regexp, and PREDICATES. | |
| 398 The original list is not affected. If the result is only one element | |
| 399 long, it will be returned itself, rather than returning a one-element | |
| 400 list." | |
| 401 (let ((flist (list t)) | |
| 402 valid p listified) | |
| 403 (unless (listp entries) | |
| 404 (setq entries (list entries) | |
| 405 listified t)) | |
| 406 (eshell-for entry entries | |
| 407 (unless (and exclude (string-match exclude entry)) | |
| 408 (setq p predicates valid (null p)) | |
| 409 (while p | |
| 410 (if (funcall (car p) entry) | |
| 411 (setq valid t) | |
| 412 (setq p nil valid nil)) | |
| 413 (setq p (cdr p))) | |
| 414 (when valid | |
| 415 (nconc flist (list entry))))) | |
| 416 (if listified | |
| 417 (cadr flist) | |
| 418 (cdr flist)))) | |
| 419 | |
| 420 (defsubst eshell-redisplay () | |
| 421 "Allow Emacs to redisplay buffers." | |
| 422 ;; for some strange reason, Emacs 21 is prone to trigger an | |
| 423 ;; "args out of range" error in `sit-for', if this function | |
| 424 ;; runs while point is in the minibuffer and the users attempt | |
| 425 ;; to use completion. Don't ask me. | |
|
87082
7a4a3f1c72ee
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86533
diff
changeset
|
426 (condition-case nil |
|
7a4a3f1c72ee
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86533
diff
changeset
|
427 (sit-for 0 0) |
|
7a4a3f1c72ee
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86533
diff
changeset
|
428 (error nil))) |
| 29870 | 429 |
| 430 (defun eshell-read-passwd-file (file) | |
| 431 "Return an alist correlating gids to group names in FILE." | |
| 432 (let (names) | |
| 433 (when (file-readable-p file) | |
| 434 (with-temp-buffer | |
| 435 (insert-file-contents file) | |
| 436 (goto-char (point-min)) | |
| 437 (while (not (eobp)) | |
| 438 (let* ((fields | |
| 439 (split-string (buffer-substring | |
| 440 (point) (progn (end-of-line) | |
| 441 (point))) ":"))) | |
| 31240 | 442 (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
|
443 (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
|
444 (setq names (cons (cons (string-to-number (nth 2 fields)) |
| 29870 | 445 (nth 0 fields)) |
| 446 names)))) | |
| 447 (forward-line)))) | |
| 448 names)) | |
| 449 | |
| 450 (defun eshell-read-passwd (file result-var timestamp-var) | |
| 451 "Read the contents of /etc/passwd for user names." | |
| 452 (if (or (not (symbol-value result-var)) | |
| 453 (not (symbol-value timestamp-var)) | |
| 454 (eshell-time-less-p | |
| 455 (symbol-value timestamp-var) | |
| 456 (nth 5 (file-attributes file)))) | |
| 457 (progn | |
| 458 (set result-var (eshell-read-passwd-file file)) | |
| 459 (set timestamp-var (current-time)))) | |
| 460 (symbol-value result-var)) | |
| 461 | |
| 462 (defun eshell-read-group-names () | |
| 463 "Read the contents of /etc/group for group names." | |
| 464 (if eshell-group-file | |
| 465 (eshell-read-passwd eshell-group-file 'eshell-group-names | |
| 466 'eshell-group-timestamp))) | |
| 467 | |
| 468 (defsubst eshell-group-id (name) | |
| 469 "Return the user id for user NAME." | |
| 470 (car (rassoc name (eshell-read-group-names)))) | |
| 471 | |
| 472 (defsubst eshell-group-name (gid) | |
| 473 "Return the group name for the given GID." | |
| 474 (cdr (assoc gid (eshell-read-group-names)))) | |
| 475 | |
| 476 (defun eshell-read-user-names () | |
| 477 "Read the contents of /etc/passwd for user names." | |
| 478 (if eshell-passwd-file | |
| 479 (eshell-read-passwd eshell-passwd-file 'eshell-user-names | |
| 480 'eshell-user-timestamp))) | |
| 481 | |
| 482 (defsubst eshell-user-id (name) | |
| 483 "Return the user id for user NAME." | |
| 484 (car (rassoc name (eshell-read-user-names)))) | |
| 485 | |
| 486 (defalias 'eshell-user-name 'user-login-name) | |
| 487 | |
| 488 (defun eshell-read-hosts-file (filename) | |
| 489 "Read in the hosts from the /etc/hosts file." | |
| 490 (let (hosts) | |
| 491 (with-temp-buffer | |
| 492 (insert-file-contents eshell-hosts-file) | |
| 493 (goto-char (point-min)) | |
| 494 (while (re-search-forward | |
| 495 "^\\(\\S-+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t) | |
| 496 (if (match-string 1) | |
| 497 (add-to-list 'hosts (match-string 1))) | |
| 498 (if (match-string 2) | |
| 499 (add-to-list 'hosts (match-string 2))) | |
| 500 (if (match-string 4) | |
| 501 (add-to-list 'hosts (match-string 4))))) | |
| 502 (sort hosts 'string-lessp))) | |
| 503 | |
| 504 (defun eshell-read-hosts (file result-var timestamp-var) | |
| 505 "Read the contents of /etc/passwd for user names." | |
| 506 (if (or (not (symbol-value result-var)) | |
| 507 (not (symbol-value timestamp-var)) | |
| 508 (eshell-time-less-p | |
| 509 (symbol-value timestamp-var) | |
| 510 (nth 5 (file-attributes file)))) | |
| 511 (progn | |
| 512 (set result-var (eshell-read-hosts-file file)) | |
| 513 (set timestamp-var (current-time)))) | |
| 514 (symbol-value result-var)) | |
| 515 | |
| 516 (defun eshell-read-host-names () | |
| 517 "Read the contents of /etc/hosts for host names." | |
| 518 (if eshell-hosts-file | |
| 519 (eshell-read-hosts eshell-hosts-file 'eshell-host-names | |
| 520 'eshell-host-timestamp))) | |
| 521 | |
| 522 (unless (fboundp 'line-end-position) | |
| 523 (defsubst line-end-position (&optional N) | |
| 524 (save-excursion (end-of-line N) (point)))) | |
| 525 | |
| 526 (unless (fboundp 'line-beginning-position) | |
| 527 (defsubst line-beginning-position (&optional N) | |
| 528 (save-excursion (beginning-of-line N) (point)))) | |
| 529 | |
| 530 (unless (fboundp 'subst-char-in-string) | |
| 531 (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
| 532 "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
| 533 Unless optional argument INPLACE is non-nil, return a new string." | |
| 534 (let ((i (length string)) | |
| 535 (newstr (if inplace string (copy-sequence string)))) | |
| 536 (while (> i 0) | |
| 537 (setq i (1- i)) | |
| 538 (if (eq (aref newstr i) fromchar) | |
| 539 (aset newstr i tochar))) | |
| 540 newstr))) | |
| 541 | |
| 542 (defsubst eshell-copy-environment () | |
| 543 "Return an unrelated copy of `process-environment'." | |
| 544 (mapcar 'concat process-environment)) | |
| 545 | |
| 546 (defun eshell-subgroups (groupsym) | |
| 547 "Return all of the subgroups of GROUPSYM." | |
| 548 (let ((subgroups (get groupsym 'custom-group)) | |
| 549 (subg (list t))) | |
| 550 (while subgroups | |
| 551 (if (eq (cadr (car subgroups)) 'custom-group) | |
| 552 (nconc subg (list (caar subgroups)))) | |
| 553 (setq subgroups (cdr subgroups))) | |
| 554 (cdr subg))) | |
| 555 | |
| 556 (defmacro eshell-with-file-modes (modes &rest forms) | |
| 557 "Evaluate, with file-modes set to MODES, the given FORMS." | |
| 558 `(let ((modes (default-file-modes))) | |
| 559 (set-default-file-modes ,modes) | |
| 560 (unwind-protect | |
| 561 (progn ,@forms) | |
| 562 (set-default-file-modes modes)))) | |
| 563 | |
| 564 (defmacro eshell-with-private-file-modes (&rest forms) | |
| 565 "Evaluate FORMS with private file modes set." | |
| 566 `(eshell-with-file-modes ,eshell-private-file-modes ,@forms)) | |
| 567 | |
| 568 (defsubst eshell-make-private-directory (dir &optional parents) | |
| 569 "Make DIR with file-modes set to `eshell-private-directory-modes'." | |
| 570 (eshell-with-file-modes eshell-private-directory-modes | |
| 571 (make-directory dir parents))) | |
| 572 | |
| 573 (defsubst eshell-substring (string sublen) | |
| 574 "Return the beginning of STRING, up to SUBLEN bytes." | |
| 575 (if string | |
| 576 (if (> (length string) sublen) | |
| 577 (substring string 0 sublen) | |
| 578 string))) | |
| 579 | |
| 580 (unless (fboundp 'directory-files-and-attributes) | |
|
47963
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
581 (defun directory-files-and-attributes (directory &optional full match nosort) |
|
39dffdbc6892
(directory-files-and-attributes): Copy docstring from Emacs 21. Arg DIR renamed
Juanma Barranquero <lekktu@gmail.com>
parents:
46852
diff
changeset
|
582 "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
|
583 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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 (let ((directory (expand-file-name directory)) ange-cache) |
| 29870 | 590 (mapcar |
| 591 (function | |
| 592 (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
|
593 (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
|
594 (directory-files directory full match nosort))))) |
| 29870 | 595 |
|
95619
45dbb3c749a6
Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
596 (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
|
597 |
| 29870 | 598 (defun eshell-directory-files-and-attributes (dir &optional full match nosort) |
| 599 "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
|
600 (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
|
601 (dfh (find-file-name-handler dir 'directory-files))) |
| 29870 | 602 (if (not dfh) |
| 603 (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
|
604 (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
|
605 (fah (find-file-name-handler dir 'file-attributes))) |
| 29870 | 606 (mapcar |
| 607 (function | |
| 608 (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
|
609 (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
|
610 (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
|
611 (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
|
612 (file-attributes (expand-file-name file dir)))))) |
| 29870 | 613 files))))) |
| 614 | |
|
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
615 (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
|
616 (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
|
617 (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
|
618 (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
|
619 (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
|
620 (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
|
621 (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
|
622 (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
|
623 |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
624 ;; 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
|
625 (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
|
626 (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
|
627 (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
|
628 |
|
32470
b338a85bdffc
Added a missing `require' form.
John Wiegley <johnw@newartisans.com>
parents:
32446
diff
changeset
|
629 (eval-when-compile |
|
86533
59b6ce989ba4
(top-level): Use require rather than load for ange-ftp.
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
630 (require 'ange-ftp nil t)) |
|
32470
b338a85bdffc
Added a missing `require' form.
John Wiegley <johnw@newartisans.com>
parents:
32446
diff
changeset
|
631 |
|
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
632 (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
|
633 (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
|
634 (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
|
635 (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
|
636 (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
|
637 (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
|
638 (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
|
639 ;; 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
|
640 (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
|
641 (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
|
642 `,(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
|
643 "\\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
|
644 "\\(\\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
|
645 "\\(\\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
|
646 "\\([0-9]+\\)" "\\s-+" "\\(.*\\)")) |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
647 (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
|
648 (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
|
649 (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
|
650 (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
|
651 (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
|
652 (mtime |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
653 (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
|
654 (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
|
655 (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
|
656 (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
|
657 (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
|
658 (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
|
659 (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
|
660 (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
|
661 (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
|
662 (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
|
663 (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
|
664 (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
|
665 symlink) |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
666 (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
|
667 (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
|
668 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
|
669 (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
|
670 (cons |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
671 (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
|
672 (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
|
673 t |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
674 symlink) |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 (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
|
679 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 |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
681 (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
|
682 "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
|
683 (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
|
684 (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
|
685 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 (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
|
687 (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
|
688 (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
|
689 '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
|
690 '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
|
691 (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
|
692 (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
|
693 (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
|
694 (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
|
695 (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
|
696 (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
|
697 (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
|
698 (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
|
699 (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
|
700 ange-cache))) |
|
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
701 (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
|
702 (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
|
703 (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
|
704 (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
|
705 (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
|
706 (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
|
707 |
|
45741
b2a7c08cddcf
(eshell-copy-tree): Make it an alias for copy-tree.
Richard M. Stallman <rms@gnu.org>
parents:
45736
diff
changeset
|
708 (defalias 'eshell-copy-tree 'copy-tree) |
| 29870 | 709 |
| 31240 | 710 (defsubst eshell-processp (proc) |
| 711 "If the `processp' function does not exist, PROC is not a process." | |
| 712 (and (fboundp 'processp) (processp proc))) | |
| 713 | |
| 29870 | 714 ; (defun eshell-copy-file |
| 715 ; (file newname &optional ok-if-already-exists keep-date) | |
| 716 ; "Copy FILE to NEWNAME. See docs for `copy-file'." | |
| 717 ; (let (copied) | |
| 718 ; (if (string-match "\\`\\([^:]+\\):\\(.*\\)" file) | |
| 719 ; (let ((front (match-string 1 file)) | |
| 720 ; (back (match-string 2 file)) | |
| 721 ; buffer) | |
| 722 ; (if (and front (string-match eshell-tar-regexp front) | |
| 723 ; (setq buffer (find-file-noselect front))) | |
| 724 ; (with-current-buffer buffer | |
| 725 ; (goto-char (point-min)) | |
| 726 ; (if (re-search-forward (concat " " (regexp-quote back) | |
| 727 ; "$") nil t) | |
| 728 ; (progn | |
| 729 ; (tar-copy (if (file-directory-p newname) | |
| 730 ; (expand-file-name | |
| 731 ; (file-name-nondirectory back) newname) | |
| 732 ; newname)) | |
| 733 ; (setq copied t)) | |
| 734 ; (error "%s not found in tar file %s" back front)))))) | |
| 735 ; (unless copied | |
| 736 ; (copy-file file newname ok-if-already-exists keep-date)))) | |
| 737 | |
| 738 ; (defun eshell-file-attributes (filename) | |
| 739 ; "Return a list of attributes of file FILENAME. | |
| 740 ; See the documentation for `file-attributes'." | |
| 741 ; (let (result) | |
| 742 ; (when (string-match "\\`\\([^:]+\\):\\(.*\\)\\'" filename) | |
| 743 ; (let ((front (match-string 1 filename)) | |
| 744 ; (back (match-string 2 filename)) | |
| 745 ; buffer) | |
| 746 ; (when (and front (string-match eshell-tar-regexp front) | |
| 747 ; (setq buffer (find-file-noselect front))) | |
| 748 ; (with-current-buffer buffer | |
| 749 ; (goto-char (point-min)) | |
| 750 ; (when (re-search-forward (concat " " (regexp-quote back) | |
| 751 ; "\\s-*$") nil t) | |
| 752 ; (let* ((descrip (tar-current-descriptor)) | |
| 753 ; (tokens (tar-desc-tokens descrip))) | |
| 754 ; (setq result | |
| 755 ; (list | |
| 756 ; (cond | |
| 757 ; ((eq (tar-header-link-type tokens) 5) | |
| 758 ; t) | |
| 759 ; ((eq (tar-header-link-type tokens) t) | |
| 760 ; (tar-header-link-name tokens))) | |
| 761 ; 1 | |
| 762 ; (tar-header-uid tokens) | |
| 763 ; (tar-header-gid tokens) | |
| 764 ; (tar-header-date tokens) | |
| 765 ; (tar-header-date tokens) | |
| 766 ; (tar-header-date tokens) | |
| 767 ; (tar-header-size tokens) | |
| 768 ; (concat | |
| 769 ; (cond | |
| 770 ; ((eq (tar-header-link-type tokens) 5) "d") | |
| 771 ; ((eq (tar-header-link-type tokens) t) "l") | |
| 772 ; (t "-")) | |
| 773 ; (tar-grind-file-mode (tar-header-mode tokens) | |
| 774 ; (make-string 9 ? ) 0)) | |
| 775 ; nil nil nil)))))))) | |
| 776 ; (or result | |
| 777 ; (file-attributes filename)))) | |
| 778 | |
|
87082
7a4a3f1c72ee
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86533
diff
changeset
|
779 (provide 'esh-util) |
| 29870 | 780 |
|
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
781 ;; arch-tag: 70159778-5c7a-480a-bae4-3ad332fca19d |
| 29870 | 782 ;;; esh-util.el ends here |
