annotate lisp/eshell/esh-util.el @ 31881:c9d93e8e8cbd

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