Mercurial > emacs
annotate lisp/eshell/em-unix.el @ 94790:fa41f74280f5
Switch to recommended form of GPLv3 permissions notice.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 09 May 2008 04:44:29 +0000 |
parents | b5b0801a7637 |
children | ad5d26b1d5d1 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37661
diff
changeset
|
1 ;;; em-unix.el --- UNIX command aliases |
29876 | 2 |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
79707 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 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 |
29876 | 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. |
29876 | 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/>. |
29876 | 22 |
87076
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
23 ;;; Commentary: |
29876 | 24 |
87076
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
25 ;; This file contains implementations of several UNIX command in Emacs |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
26 ;; Lisp, for several reasons: |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
27 ;; |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
28 ;; 1) it makes them available on all platforms where the Lisp |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
29 ;; functions used are available |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
30 ;; |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
31 ;; 2) it makes their functionality accessible and modified by the |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
32 ;; Lisp programmer. |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
33 ;; |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
34 ;; 3) it allows Eshell to refrain from having to invoke external |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
35 ;; processes for common operations. |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
36 |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
37 ;;; Code: |
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
38 |
55195
f243dc772a99
Add "(require 'eshell)", to get necessary features
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
39 (require 'eshell) |
29876 | 40 |
41 (defgroup eshell-unix nil | |
42 "This module defines many of the more common UNIX utilities as | |
43 aliases implemented in Lisp. These include mv, ln, cp, rm, etc. If | |
44 the user passes arguments which are too complex, or are unrecognized | |
45 by the Lisp variant, the external version will be called (if | |
46 available). The only reason not to use them would be because they are | |
47 usually much slower. But in several cases their tight integration | |
48 with Eshell makes them more versatile than their traditional cousins | |
49 \(such as being able to use `kill' to kill Eshell background processes | |
50 by name)." | |
51 :tag "UNIX commands in Lisp" | |
52 :group 'eshell-module) | |
53 | |
54 (defcustom eshell-unix-load-hook '(eshell-unix-initialize) | |
55 "*A list of functions to run when `eshell-unix' is loaded." | |
56 :type 'hook | |
57 :group 'eshell-unix) | |
58 | |
59 (defcustom eshell-plain-grep-behavior nil | |
60 "*If non-nil, standalone \"grep\" commands will behave normally. | |
61 Standalone in this context means not redirected, and not on the | |
62 receiving side of a command pipeline." | |
63 :type 'boolean | |
64 :group 'eshell-unix) | |
65 | |
66 (defcustom eshell-no-grep-available (not (eshell-search-path "grep")) | |
67 "*If non-nil, no grep is available on the current machine." | |
68 :type 'boolean | |
69 :group 'eshell-unix) | |
70 | |
71 (defcustom eshell-plain-diff-behavior nil | |
72 "*If non-nil, standalone \"diff\" commands will behave normally. | |
73 Standalone in this context means not redirected, and not on the | |
74 receiving side of a command pipeline." | |
75 :type 'boolean | |
76 :group 'eshell-unix) | |
77 | |
86202
794e428cd497
* eshell/esh-util.el (eshell-under-xemacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86106
diff
changeset
|
78 (defcustom eshell-plain-locate-behavior (featurep 'xemacs) |
29876 | 79 "*If non-nil, standalone \"locate\" commands will behave normally. |
80 Standalone in this context means not redirected, and not on the | |
81 receiving side of a command pipeline." | |
82 :type 'boolean | |
83 :group 'eshell-unix) | |
84 | |
85 (defcustom eshell-rm-removes-directories nil | |
86 "*If non-nil, `rm' will remove directory entries. | |
87 Otherwise, `rmdir' is required." | |
88 :type 'boolean | |
89 :group 'eshell-unix) | |
90 | |
91 (defcustom eshell-rm-interactive-query (= (user-uid) 0) | |
92 "*If non-nil, `rm' will query before removing anything." | |
93 :type 'boolean | |
94 :group 'eshell-unix) | |
95 | |
96 (defcustom eshell-mv-interactive-query (= (user-uid) 0) | |
97 "*If non-nil, `mv' will query before overwriting anything." | |
98 :type 'boolean | |
99 :group 'eshell-unix) | |
100 | |
101 (defcustom eshell-mv-overwrite-files t | |
102 "*If non-nil, `mv' will overwrite files without warning." | |
103 :type 'boolean | |
104 :group 'eshell-unix) | |
105 | |
106 (defcustom eshell-cp-interactive-query (= (user-uid) 0) | |
107 "*If non-nil, `cp' will query before overwriting anything." | |
108 :type 'boolean | |
109 :group 'eshell-unix) | |
110 | |
111 (defcustom eshell-cp-overwrite-files t | |
112 "*If non-nil, `cp' will overwrite files without warning." | |
113 :type 'boolean | |
114 :group 'eshell-unix) | |
115 | |
116 (defcustom eshell-ln-interactive-query (= (user-uid) 0) | |
117 "*If non-nil, `ln' will query before overwriting anything." | |
118 :type 'boolean | |
119 :group 'eshell-unix) | |
120 | |
31241 | 121 (defcustom eshell-ln-overwrite-files nil |
29876 | 122 "*If non-nil, `ln' will overwrite files without warning." |
123 :type 'boolean | |
124 :group 'eshell-unix) | |
125 | |
33020 | 126 (defcustom eshell-default-target-is-dot nil |
127 "*If non-nil, the default destination for cp, mv or ln is `.'." | |
128 :type 'boolean | |
129 :group 'eshell-unix) | |
130 | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
131 (defcustom eshell-du-prefer-over-ange nil |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
132 "*Use Eshell's du in ange-ftp remote directories. |
32493
34d5d8707722
(eshell-du-prefer-over-ange): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
32446
diff
changeset
|
133 Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine." |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
134 :type 'boolean |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
135 :group 'eshell-unix) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
136 |
29876 | 137 ;;; Functions: |
138 | |
139 (defun eshell-unix-initialize () | |
140 "Initialize the UNIX support/emulation code." | |
141 (when (eshell-using-module 'eshell-cmpl) | |
142 (add-hook 'pcomplete-try-first-hook | |
33020 | 143 'eshell-complete-host-reference nil t)) |
144 (make-local-variable 'eshell-complex-commands) | |
145 (setq eshell-complex-commands | |
146 (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate" | |
147 "cat" "time" "cp" "mv" "make" "du" "diff") | |
148 eshell-complex-commands))) | |
29876 | 149 |
150 (defalias 'eshell/date 'current-time-string) | |
151 (defalias 'eshell/basename 'file-name-nondirectory) | |
152 (defalias 'eshell/dirname 'file-name-directory) | |
153 | |
154 (eval-when-compile | |
155 (defvar interactive) | |
156 (defvar preview) | |
157 (defvar recursive) | |
158 (defvar verbose)) | |
159 | |
160 (defun eshell/man (&rest args) | |
161 "Invoke man, flattening the arguments appropriately." | |
162 (funcall 'man (apply 'eshell-flatten-and-stringify args))) | |
163 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
164 (put 'eshell/man 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
165 |
83810
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
166 (defun eshell/info (&rest args) |
86106
29738c3df361
(eshell/info): Fix typos in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
85660
diff
changeset
|
167 "Run the info command in-frame with the same behavior as command-line `info', ie: |
83810
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
168 'info' => goes to top info window |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
169 'info arg1' => IF arg1 is a file, then visits arg1 |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
170 'info arg1' => OTHERWISE goes to top info window and then menu item arg1 |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
171 'info arg1 arg2' => does action for arg1 (either visit-file or menu-item) and then menu item arg2 |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
172 etc." |
85503
59ee4068f60b
* progmodes/gud.el (gud-target-name): Move definition before use.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83839
diff
changeset
|
173 (eval-and-compile (require 'info)) |
83810
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
174 (let ((file (cond |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
175 ((not (stringp (car args))) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
176 nil) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
177 ((file-exists-p (expand-file-name (car args))) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
178 (expand-file-name (car args))) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
179 ((file-exists-p (concat (expand-file-name (car args)) ".info")) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
180 (concat (expand-file-name (car args)) ".info"))))) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
181 |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
182 ;; If the first arg is a file, then go to that file's Top node |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
183 ;; Otherwise, go to the global directory |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
184 (if file |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
185 (progn |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
186 (setq args (cdr args)) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
187 (Info-find-node file "Top")) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
188 (Info-directory)) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
189 |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
190 ;; Treat all remaining args as menu references |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
191 (while args |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
192 (Info-menu (car args)) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
193 (setq args (cdr args))))) |
5ad1e235d4fa
James Wright <james at chumsley.org>
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
194 |
29876 | 195 (defun eshell-remove-entries (path files &optional top-level) |
33020 | 196 "From PATH, remove all of the given FILES, perhaps interactively." |
29876 | 197 (while files |
198 (if (string-match "\\`\\.\\.?\\'" | |
199 (file-name-nondirectory (car files))) | |
200 (if top-level | |
201 (eshell-error "rm: cannot remove `.' or `..'\n")) | |
202 (if (and (file-directory-p (car files)) | |
203 (not (file-symlink-p (car files)))) | |
204 (let ((dir (file-name-as-directory (car files)))) | |
205 (eshell-remove-entries dir | |
206 (mapcar | |
207 (function | |
208 (lambda (file) | |
209 (concat dir file))) | |
210 (directory-files dir))) | |
211 (if verbose | |
212 (eshell-printn (format "rm: removing directory `%s'" | |
213 (car files)))) | |
214 (unless | |
215 (or preview | |
216 (and interactive | |
217 (not (y-or-n-p | |
218 (format "rm: remove directory `%s'? " | |
219 (car files)))))) | |
220 (eshell-funcalln 'delete-directory (car files)))) | |
221 (if verbose | |
222 (eshell-printn (format "rm: removing file `%s'" | |
223 (car files)))) | |
224 (unless (or preview | |
225 (and interactive | |
226 (not (y-or-n-p | |
227 (format "rm: remove `%s'? " | |
228 (car files)))))) | |
229 (eshell-funcalln 'delete-file (car files))))) | |
230 (setq files (cdr files)))) | |
231 | |
232 (defun eshell/rm (&rest args) | |
233 "Implementation of rm in Lisp. | |
234 This is implemented to call either `delete-file', `kill-buffer', | |
235 `kill-process', or `unintern', depending on the nature of the | |
236 argument." | |
237 (setq args (eshell-flatten-list args)) | |
238 (eshell-eval-using-options | |
239 "rm" args | |
240 '((?h "help" nil nil "show this usage screen") | |
241 (?f "force" nil force-removal "force removal") | |
242 (?i "interactive" nil interactive "prompt before any removal") | |
243 (?n "preview" nil preview "don't change anything on disk") | |
244 (?r "recursive" nil recursive | |
245 "remove the contents of directories recursively") | |
246 (?R nil nil recursive "(same)") | |
247 (?v "verbose" nil verbose "explain what is being done") | |
248 :preserve-args | |
249 :external "rm" | |
250 :show-usage | |
251 :usage "[OPTION]... FILE... | |
252 Remove (unlink) the FILE(s).") | |
253 (unless interactive | |
254 (setq interactive eshell-rm-interactive-query)) | |
255 (if (and force-removal interactive) | |
256 (setq interactive nil)) | |
257 (while args | |
258 (let ((entry (if (stringp (car args)) | |
259 (directory-file-name (car args)) | |
260 (if (numberp (car args)) | |
261 (number-to-string (car args)) | |
262 (car args))))) | |
263 (cond | |
264 ((bufferp entry) | |
265 (if verbose | |
266 (eshell-printn (format "rm: removing buffer `%s'" entry))) | |
267 (unless (or preview | |
268 (and interactive | |
269 (not (y-or-n-p (format "rm: delete buffer `%s'? " | |
270 entry))))) | |
271 (eshell-funcalln 'kill-buffer entry))) | |
31241 | 272 ((eshell-processp entry) |
29876 | 273 (if verbose |
274 (eshell-printn (format "rm: killing process `%s'" entry))) | |
275 (unless (or preview | |
276 (and interactive | |
277 (not (y-or-n-p (format "rm: kill process `%s'? " | |
278 entry))))) | |
279 (eshell-funcalln 'kill-process entry))) | |
280 ((symbolp entry) | |
281 (if verbose | |
282 (eshell-printn (format "rm: uninterning symbol `%s'" entry))) | |
283 (unless | |
284 (or preview | |
285 (and interactive | |
286 (not (y-or-n-p (format "rm: unintern symbol `%s'? " | |
287 entry))))) | |
288 (eshell-funcalln 'unintern entry))) | |
289 ((stringp entry) | |
290 (if (and (file-directory-p entry) | |
291 (not (file-symlink-p entry))) | |
292 (if (or recursive | |
293 eshell-rm-removes-directories) | |
294 (if (or preview | |
295 (not interactive) | |
296 (y-or-n-p | |
297 (format "rm: descend into directory `%s'? " | |
298 entry))) | |
299 (eshell-remove-entries nil (list entry) t)) | |
300 (eshell-error (format "rm: %s: is a directory\n" entry))) | |
301 (eshell-remove-entries nil (list entry) t))))) | |
302 (setq args (cdr args))) | |
303 nil)) | |
304 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
305 (put 'eshell/rm 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
306 |
29876 | 307 (defun eshell/mkdir (&rest args) |
308 "Implementation of mkdir in Lisp." | |
309 (eshell-eval-using-options | |
310 "mkdir" args | |
311 '((?h "help" nil nil "show this usage screen") | |
312 :external "mkdir" | |
313 :show-usage | |
314 :usage "[OPTION] DIRECTORY... | |
315 Create the DIRECTORY(ies), if they do not already exist.") | |
316 (while args | |
317 (eshell-funcalln 'make-directory (car args)) | |
318 (setq args (cdr args))) | |
319 nil)) | |
320 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
321 (put 'eshell/mkdir 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
322 |
29876 | 323 (defun eshell/rmdir (&rest args) |
324 "Implementation of rmdir in Lisp." | |
325 (eshell-eval-using-options | |
326 "rmdir" args | |
327 '((?h "help" nil nil "show this usage screen") | |
328 :external "rmdir" | |
329 :show-usage | |
330 :usage "[OPTION] DIRECTORY... | |
331 Remove the DIRECTORY(ies), if they are empty.") | |
332 (while args | |
333 (eshell-funcalln 'delete-directory (car args)) | |
334 (setq args (cdr args))) | |
335 nil)) | |
336 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
337 (put 'eshell/rmdir 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
338 |
29876 | 339 (eval-when-compile |
340 (defvar no-dereference) | |
341 (defvar preview) | |
342 (defvar verbose)) | |
343 | |
344 (defvar eshell-warn-dot-directories t) | |
345 | |
346 (defun eshell-shuffle-files (command action files target func deep &rest args) | |
347 "Shuffle around some filesystem entries, using FUNC to do the work." | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
348 (let ((attr-target (eshell-file-attributes target)) |
29876 | 349 (is-dir (or (file-directory-p target) |
350 (and preview (not eshell-warn-dot-directories)))) | |
351 attr) | |
352 (if (and (not preview) (not is-dir) | |
353 (> (length files) 1)) | |
354 (error "%s: when %s multiple files, last argument must be a directory" | |
355 command action)) | |
356 (while files | |
357 (setcar files (directory-file-name (car files))) | |
358 (cond | |
359 ((string-match "\\`\\.\\.?\\'" | |
360 (file-name-nondirectory (car files))) | |
361 (if eshell-warn-dot-directories | |
362 (eshell-error (format "%s: %s: omitting directory\n" | |
363 command (car files))))) | |
364 ((and attr-target | |
30269
30829e002c1b
(eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
365 (or (not (eshell-under-windows-p)) |
30829e002c1b
(eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
366 (eq system-type 'ms-dos)) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
367 (setq attr (eshell-file-attributes (car files))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
368 (nth 10 attr-target) (nth 10 attr) |
39293
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
369 ;; Use equal, not -, since the inode and the device could |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
370 ;; cons cells. |
39235
f3a553d88ab7
(eshell-shuffle-files): Compare inodes with
Eli Zaretskii <eliz@gnu.org>
parents:
38414
diff
changeset
|
371 (equal (nth 10 attr-target) (nth 10 attr)) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
372 (nth 11 attr-target) (nth 11 attr) |
39293
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
373 (equal (nth 11 attr-target) (nth 11 attr))) |
29876 | 374 (eshell-error (format "%s: `%s' and `%s' are the same file\n" |
375 command (car files) target))) | |
376 (t | |
377 (let ((source (car files)) | |
378 (target (if is-dir | |
379 (expand-file-name | |
380 (file-name-nondirectory (car files)) target) | |
381 target)) | |
382 link) | |
383 (if (and (file-directory-p source) | |
384 (or (not no-dereference) | |
385 (not (file-symlink-p source))) | |
386 (not (memq func '(make-symbolic-link | |
387 add-name-to-file)))) | |
388 (if (and (eq func 'copy-file) | |
389 (not recursive)) | |
390 (eshell-error (format "%s: %s: omitting directory\n" | |
391 command (car files))) | |
392 (let (eshell-warn-dot-directories) | |
393 (if (and (not deep) | |
394 (eq func 'rename-file) | |
39293
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
395 ;; Use equal, since the device might be a |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
396 ;; cons cell. |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
397 (equal (nth 11 (eshell-file-attributes |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
398 (file-name-directory |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
399 (directory-file-name |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
400 (expand-file-name source))))) |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
401 (nth 11 (eshell-file-attributes |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
402 (file-name-directory |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
403 (directory-file-name |
1e91a5f60ae6
(eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents:
39235
diff
changeset
|
404 (expand-file-name target))))))) |
29876 | 405 (apply 'eshell-funcalln func source target args) |
406 (unless (file-directory-p target) | |
407 (if verbose | |
408 (eshell-printn | |
409 (format "%s: making directory %s" | |
410 command target))) | |
411 (unless preview | |
412 (eshell-funcalln 'make-directory target))) | |
31241 | 413 (apply 'eshell-shuffle-files |
414 command action | |
415 (mapcar | |
416 (function | |
417 (lambda (file) | |
418 (concat source "/" file))) | |
419 (directory-files source)) | |
420 target func t args) | |
29876 | 421 (when (eq func 'rename-file) |
422 (if verbose | |
423 (eshell-printn | |
424 (format "%s: deleting directory %s" | |
425 command source))) | |
426 (unless preview | |
427 (eshell-funcalln 'delete-directory source)))))) | |
428 (if verbose | |
429 (eshell-printn (format "%s: %s -> %s" command | |
430 source target))) | |
431 (unless preview | |
432 (if (and no-dereference | |
433 (setq link (file-symlink-p source))) | |
434 (progn | |
435 (apply 'eshell-funcalln 'make-symbolic-link | |
436 link target args) | |
437 (if (eq func 'rename-file) | |
438 (if (and (file-directory-p source) | |
439 (not (file-symlink-p source))) | |
440 (eshell-funcalln 'delete-directory source) | |
441 (eshell-funcalln 'delete-file source)))) | |
442 (apply 'eshell-funcalln func source target args))))))) | |
443 (setq files (cdr files))))) | |
444 | |
445 (defun eshell-shorthand-tar-command (command args) | |
446 "Rewrite `cp -v dir a.tar.gz' to `tar cvzf a.tar.gz dir'." | |
447 (let* ((archive (car (last args))) | |
448 (tar-args | |
449 (cond ((string-match "z2" archive) "If") | |
450 ((string-match "gz" archive) "zf") | |
451 ((string-match "\\(az\\|Z\\)" archive) "Zf") | |
452 (t "f")))) | |
453 (if (file-exists-p archive) | |
454 (setq tar-args (concat "u" tar-args)) | |
455 (setq tar-args (concat "c" tar-args))) | |
456 (if verbose | |
457 (setq tar-args (concat "v" tar-args))) | |
458 (if (equal command "mv") | |
459 (setq tar-args (concat "--remove-files -" tar-args))) | |
460 ;; truncate the archive name from the arguments | |
461 (setcdr (last args 2) nil) | |
462 (throw 'eshell-replace-command | |
463 (eshell-parse-command | |
464 (format "tar %s %s" tar-args archive) args)))) | |
465 | |
466 ;; this is to avoid duplicating code... | |
33020 | 467 (defmacro eshell-mvcpln-template (command action func query-var |
468 force-var &optional preserve) | |
469 `(let ((len (length args))) | |
470 (if (or (= len 0) | |
471 (and (= len 1) (null eshell-default-target-is-dot))) | |
472 (error "%s: missing destination file or directory" ,command)) | |
473 (if (= len 1) | |
474 (nconc args '("."))) | |
475 (setq args (eshell-stringify-list (eshell-flatten-list args))) | |
476 (if (and ,(not (equal command "ln")) | |
477 (string-match eshell-tar-regexp (car (last args))) | |
478 (or (> (length args) 2) | |
479 (and (file-directory-p (car args)) | |
480 (or (not no-dereference) | |
481 (not (file-symlink-p (car args))))))) | |
482 (eshell-shorthand-tar-command ,command args) | |
483 (let ((target (car (last args))) | |
484 ange-cache) | |
485 (setcdr (last args 2) nil) | |
486 (eshell-shuffle-files | |
487 ,command ,action args target ,func nil | |
488 ,@(append | |
489 `((if (and (or interactive | |
490 ,query-var) | |
491 (not force)) | |
492 1 (or force ,force-var))) | |
493 (if preserve | |
494 (list preserve))))) | |
495 nil))) | |
29876 | 496 |
497 (defun eshell/mv (&rest args) | |
498 "Implementation of mv in Lisp." | |
499 (eshell-eval-using-options | |
500 "mv" args | |
501 '((?f "force" nil force | |
502 "remove existing destinations, never prompt") | |
503 (?i "interactive" nil interactive | |
504 "request confirmation if target already exists") | |
505 (?n "preview" nil preview | |
506 "don't change anything on disk") | |
507 (?v "verbose" nil verbose | |
508 "explain what is being done") | |
509 (nil "help" nil nil "show this usage screen") | |
33020 | 510 :preserve-args |
29876 | 511 :external "mv" |
512 :show-usage | |
513 :usage "[OPTION]... SOURCE DEST | |
514 or: mv [OPTION]... SOURCE... DIRECTORY | |
515 Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. | |
516 \[OPTION] DIRECTORY...") | |
517 (let ((no-dereference t)) | |
33020 | 518 (eshell-mvcpln-template "mv" "moving" 'rename-file |
519 eshell-mv-interactive-query | |
520 eshell-mv-overwrite-files)))) | |
29876 | 521 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
522 (put 'eshell/mv 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
523 |
29876 | 524 (defun eshell/cp (&rest args) |
525 "Implementation of cp in Lisp." | |
526 (eshell-eval-using-options | |
527 "cp" args | |
528 '((?a "archive" nil archive | |
529 "same as -dpR") | |
530 (?d "no-dereference" nil no-dereference | |
531 "preserve links") | |
532 (?f "force" nil force | |
533 "remove existing destinations, never prompt") | |
534 (?i "interactive" nil interactive | |
535 "request confirmation if target already exists") | |
536 (?n "preview" nil preview | |
537 "don't change anything on disk") | |
538 (?p "preserve" nil preserve | |
539 "preserve file attributes if possible") | |
540 (?R "recursive" nil recursive | |
541 "copy directories recursively") | |
542 (?v "verbose" nil verbose | |
543 "explain what is being done") | |
544 (nil "help" nil nil "show this usage screen") | |
33020 | 545 :preserve-args |
29876 | 546 :external "cp" |
547 :show-usage | |
548 :usage "[OPTION]... SOURCE DEST | |
549 or: cp [OPTION]... SOURCE... DIRECTORY | |
550 Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.") | |
551 (if archive | |
552 (setq preserve t no-dereference t recursive t)) | |
33020 | 553 (eshell-mvcpln-template "cp" "copying" 'copy-file |
554 eshell-cp-interactive-query | |
555 eshell-cp-overwrite-files preserve))) | |
29876 | 556 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
557 (put 'eshell/cp 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
558 |
29876 | 559 (defun eshell/ln (&rest args) |
560 "Implementation of ln in Lisp." | |
561 (eshell-eval-using-options | |
562 "ln" args | |
563 '((?h "help" nil nil "show this usage screen") | |
564 (?s "symbolic" nil symbolic | |
565 "make symbolic links instead of hard links") | |
33020 | 566 (?i "interactive" nil interactive |
567 "request confirmation if target already exists") | |
29876 | 568 (?f "force" nil force "remove existing destinations, never prompt") |
569 (?n "preview" nil preview | |
570 "don't change anything on disk") | |
571 (?v "verbose" nil verbose "explain what is being done") | |
33020 | 572 :preserve-args |
29876 | 573 :external "ln" |
574 :show-usage | |
575 :usage "[OPTION]... TARGET [LINK_NAME] | |
576 or: ln [OPTION]... TARGET... DIRECTORY | |
577 Create a link to the specified TARGET with optional LINK_NAME. If there is | |
578 more than one TARGET, the last argument must be a directory; create links | |
579 in DIRECTORY to each TARGET. Create hard links by default, symbolic links | |
580 with '--symbolic'. When creating hard links, each TARGET must exist.") | |
33020 | 581 (let ((no-dereference t)) |
582 (eshell-mvcpln-template "ln" "linking" | |
583 (if symbolic | |
584 'make-symbolic-link | |
585 'add-name-to-file) | |
586 eshell-ln-interactive-query | |
587 eshell-ln-overwrite-files)))) | |
29876 | 588 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
589 (put 'eshell/ln 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
590 |
29876 | 591 (defun eshell/cat (&rest args) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
592 "Implementation of cat in Lisp. |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
593 If in a pipeline, or the file is not a regular file, directory or |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
594 symlink, then revert to the system's definition of cat." |
33020 | 595 (setq args (eshell-stringify-list (eshell-flatten-list args))) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
596 (if (or eshell-in-pipeline-p |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
597 (catch 'special |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
598 (eshell-for arg args |
39985
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
599 (unless (or (and (stringp arg) |
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
600 (> (length arg) 0) |
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
601 (eq (aref arg 0) ?-)) |
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
602 (let ((attrs (eshell-file-attributes arg))) |
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
603 (and attrs (memq (aref (nth 8 attrs) 0) |
3a906538d254
(eshell/cat): Do a quick test if something is a regular file, before
John Wiegley <johnw@newartisans.com>
parents:
39293
diff
changeset
|
604 '(?d ?l ?-))))) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
605 (throw 'special t))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
606 (let ((ext-cat (eshell-search-path "cat"))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
607 (if ext-cat |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
608 (throw 'eshell-replace-command |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
609 (eshell-parse-command ext-cat args)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
610 (if eshell-in-pipeline-p |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
611 (error "Eshell's `cat' does not work in pipelines") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
612 (error "Eshell's `cat' cannot display one of the files given")))) |
29876 | 613 (eshell-init-print-buffer) |
614 (eshell-eval-using-options | |
615 "cat" args | |
616 '((?h "help" nil nil "show this usage screen") | |
617 :external "cat" | |
618 :show-usage | |
619 :usage "[OPTION] FILE... | |
620 Concatenate FILE(s), or standard input, to standard output.") | |
621 (eshell-for file args | |
622 (if (string= file "-") | |
623 (throw 'eshell-external | |
624 (eshell-external-command "cat" args)))) | |
625 (let ((curbuf (current-buffer))) | |
626 (eshell-for file args | |
627 (with-temp-buffer | |
628 (insert-file-contents file) | |
629 (goto-char (point-min)) | |
630 (while (not (eobp)) | |
631 (let ((str (buffer-substring | |
632 (point) (min (1+ (line-end-position)) | |
633 (point-max))))) | |
634 (with-current-buffer curbuf | |
635 (eshell-buffered-print str))) | |
636 (forward-line))))) | |
637 (eshell-flush) | |
638 ;; if the file does not end in a newline, do not emit one | |
639 (setq eshell-ensure-newline-p nil)))) | |
640 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
641 (put 'eshell/cat 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
642 |
29876 | 643 ;; special front-end functions for compilation-mode buffers |
644 | |
645 (defun eshell/make (&rest args) | |
646 "Use `compile' to do background makes." | |
647 (if (and eshell-current-subjob-p | |
648 (eshell-interactive-output-p)) | |
649 (let ((compilation-process-setup-function | |
650 (list 'lambda nil | |
651 (list 'setq 'process-environment | |
652 (list 'quote (eshell-copy-environment)))))) | |
653 (compile (concat "make " (eshell-flatten-and-stringify args)))) | |
654 (throw 'eshell-replace-command | |
33020 | 655 (eshell-parse-command "*make" (eshell-stringify-list |
656 (eshell-flatten-list args)))))) | |
29876 | 657 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
658 (put 'eshell/make 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
659 |
29876 | 660 (defun eshell-occur-mode-goto-occurrence () |
661 "Go to the occurrence the current line describes." | |
662 (interactive) | |
663 (let ((pos (occur-mode-find-occurrence))) | |
664 (pop-to-buffer (marker-buffer pos)) | |
665 (goto-char (marker-position pos)))) | |
666 | |
667 (defun eshell-occur-mode-mouse-goto (event) | |
668 "In Occur mode, go to the occurrence whose line you click on." | |
669 (interactive "e") | |
47597
8094bb2ffe5b
(eshell-occur-mode-mouse-goto, eshell-poor-mans-grep): Remove references to
Juanma Barranquero <lekktu@gmail.com>
parents:
45734
diff
changeset
|
670 (let (pos) |
29876 | 671 (save-excursion |
672 (set-buffer (window-buffer (posn-window (event-end event)))) | |
673 (save-excursion | |
674 (goto-char (posn-point (event-end event))) | |
47597
8094bb2ffe5b
(eshell-occur-mode-mouse-goto, eshell-poor-mans-grep): Remove references to
Juanma Barranquero <lekktu@gmail.com>
parents:
45734
diff
changeset
|
675 (setq pos (occur-mode-find-occurrence)))) |
29876 | 676 (pop-to-buffer (marker-buffer pos)) |
677 (goto-char (marker-position pos)))) | |
678 | |
679 (defun eshell-poor-mans-grep (args) | |
680 "A poor version of grep that opens every file and uses `occur'. | |
681 This eats up memory, since it leaves the buffers open (to speed future | |
682 searches), and it's very slow. But, if your system has no grep | |
683 available..." | |
684 (save-selected-window | |
685 (let ((default-dir default-directory)) | |
686 (with-current-buffer (get-buffer-create "*grep*") | |
687 (let ((inhibit-read-only t) | |
688 (default-directory default-dir)) | |
689 (erase-buffer) | |
690 (occur-mode) | |
33020 | 691 (let ((files (eshell-stringify-list |
692 (eshell-flatten-list (cdr args)))) | |
29876 | 693 (inhibit-redisplay t) |
694 string) | |
695 (when (car args) | |
696 (if (get-buffer "*Occur*") | |
697 (kill-buffer (get-buffer "*Occur*"))) | |
698 (setq string nil) | |
699 (while files | |
700 (with-current-buffer (find-file-noselect (car files)) | |
701 (save-excursion | |
702 (ignore-errors | |
703 (occur (car args)))) | |
704 (if (get-buffer "*Occur*") | |
705 (with-current-buffer (get-buffer "*Occur*") | |
706 (setq string (buffer-string)) | |
707 (kill-buffer (current-buffer))))) | |
708 (if string (insert string)) | |
709 (setq string nil | |
710 files (cdr files))))) | |
711 (local-set-key [mouse-2] 'eshell-occur-mode-mouse-goto) | |
712 (local-set-key [(control ?c) (control ?c)] | |
713 'eshell-occur-mode-goto-occurrence) | |
714 (local-set-key [(control ?m)] | |
715 'eshell-occur-mode-goto-occurrence) | |
716 (local-set-key [return] 'eshell-occur-mode-goto-occurrence) | |
717 (pop-to-buffer (current-buffer) t) | |
718 (goto-char (point-min)) | |
719 (resize-temp-buffer-window)))))) | |
720 | |
721 (defun eshell-grep (command args &optional maybe-use-occur) | |
722 "Generic service function for the various grep aliases. | |
723 It calls Emacs' grep utility if the command is not redirecting output, | |
724 and if it's not part of a command pipeline. Otherwise, it calls the | |
725 external command." | |
726 (if (and maybe-use-occur eshell-no-grep-available) | |
727 (eshell-poor-mans-grep args) | |
728 (if (or eshell-plain-grep-behavior | |
729 (not (and (eshell-interactive-output-p) | |
730 (not eshell-in-pipeline-p) | |
731 (not eshell-in-subcommand-p)))) | |
732 (throw 'eshell-replace-command | |
31241 | 733 (eshell-parse-command (concat "*" command) |
33020 | 734 (eshell-stringify-list |
735 (eshell-flatten-list args)))) | |
57604
c72da3dd9a8d
(eshell-grep): Don't bind compilation-process-setup-function.
Richard M. Stallman <rms@gnu.org>
parents:
55195
diff
changeset
|
736 (let* ((args (mapconcat 'identity |
29876 | 737 (mapcar 'shell-quote-argument |
33020 | 738 (eshell-stringify-list |
739 (eshell-flatten-list args))) | |
29876 | 740 " ")) |
741 (cmd (progn | |
742 (set-text-properties 0 (length args) | |
743 '(invisible t) args) | |
744 (format "%s -n %s" command args))) | |
745 compilation-scroll-output) | |
746 (grep cmd))))) | |
747 | |
748 (defun eshell/grep (&rest args) | |
749 "Use Emacs grep facility instead of calling external grep." | |
750 (eshell-grep "grep" args t)) | |
751 | |
752 (defun eshell/egrep (&rest args) | |
753 "Use Emacs grep facility instead of calling external egrep." | |
754 (eshell-grep "egrep" args t)) | |
755 | |
756 (defun eshell/fgrep (&rest args) | |
757 "Use Emacs grep facility instead of calling external fgrep." | |
758 (eshell-grep "fgrep" args t)) | |
759 | |
760 (defun eshell/agrep (&rest args) | |
761 "Use Emacs grep facility instead of calling external agrep." | |
762 (eshell-grep "agrep" args)) | |
763 | |
764 (defun eshell/glimpse (&rest args) | |
765 "Use Emacs grep facility instead of calling external glimpse." | |
766 (let (null-device) | |
767 (eshell-grep "glimpse" (append '("-z" "-y") args)))) | |
768 | |
769 ;; completions rules for some common UNIX commands | |
770 | |
771 (defsubst eshell-complete-hostname () | |
772 "Complete a command that wants a hostname for an argument." | |
773 (pcomplete-here (eshell-read-host-names))) | |
774 | |
775 (defun eshell-complete-host-reference () | |
776 "If there is a host reference, complete it." | |
777 (let ((arg (pcomplete-actual-arg)) | |
778 index) | |
779 (when (setq index (string-match "@[a-z.]*\\'" arg)) | |
780 (setq pcomplete-stub (substring arg (1+ index)) | |
781 pcomplete-last-completion-raw t) | |
782 (throw 'pcomplete-completions (eshell-read-host-names))))) | |
783 | |
784 (defalias 'pcomplete/ftp 'eshell-complete-hostname) | |
785 (defalias 'pcomplete/ncftp 'eshell-complete-hostname) | |
786 (defalias 'pcomplete/ping 'eshell-complete-hostname) | |
787 (defalias 'pcomplete/rlogin 'eshell-complete-hostname) | |
788 | |
789 (defun pcomplete/telnet () | |
790 (require 'pcmpl-unix) | |
791 (pcomplete-opt "xl(pcmpl-unix-user-names)") | |
792 (eshell-complete-hostname)) | |
793 | |
794 (defun pcomplete/rsh () | |
795 "Complete `rsh', which, after the user and hostname, is like xargs." | |
796 (require 'pcmpl-unix) | |
797 (pcomplete-opt "l(pcmpl-unix-user-names)") | |
798 (eshell-complete-hostname) | |
799 (pcomplete-here (funcall pcomplete-command-completion-function)) | |
800 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
801 pcomplete-default-completion-function))) | |
802 | |
803 (defalias 'pcomplete/ssh 'pcomplete/rsh) | |
804 | |
805 (eval-when-compile | |
806 (defvar block-size) | |
807 (defvar by-bytes) | |
808 (defvar dereference-links) | |
809 (defvar grand-total) | |
810 (defvar human-readable) | |
811 (defvar max-depth) | |
812 (defvar only-one-filesystem) | |
813 (defvar show-all)) | |
814 | |
815 (defsubst eshell-du-size-string (size) | |
816 (let* ((str (eshell-printable-size size human-readable block-size t)) | |
817 (len (length str))) | |
818 (concat str (if (< len 8) | |
819 (make-string (- 8 len) ? ))))) | |
820 | |
821 (defun eshell-du-sum-directory (path depth) | |
822 "Summarize PATH, and its member directories." | |
823 (let ((entries (eshell-directory-files-and-attributes path)) | |
824 (size 0.0)) | |
825 (while entries | |
826 (unless (string-match "\\`\\.\\.?\\'" (caar entries)) | |
57742
7e9025771254
(eshell-du-sum-directory): Don't use directory-sep-char.
Richard M. Stallman <rms@gnu.org>
parents:
57604
diff
changeset
|
827 (let* ((entry (concat path "/" |
29876 | 828 (caar entries))) |
829 (symlink (and (stringp (cadr (car entries))) | |
830 (cadr (car entries))))) | |
831 (unless (or (and symlink (not dereference-links)) | |
832 (and only-one-filesystem | |
31241 | 833 (/= only-one-filesystem |
834 (nth 12 (car entries))))) | |
29876 | 835 (if symlink |
836 (setq entry symlink)) | |
837 (setq size | |
838 (+ size | |
839 (if (eq t (cadr (car entries))) | |
840 (eshell-du-sum-directory entry (1+ depth)) | |
841 (let ((file-size (nth 8 (car entries)))) | |
842 (prog1 | |
843 file-size | |
844 (if show-all | |
845 (eshell-print | |
846 (concat (eshell-du-size-string file-size) | |
847 entry "\n"))))))))))) | |
848 (setq entries (cdr entries))) | |
849 (if (or (not max-depth) | |
850 (= depth max-depth) | |
851 (= depth 0)) | |
852 (eshell-print (concat (eshell-du-size-string size) | |
853 (directory-file-name path) "\n"))) | |
854 size)) | |
855 | |
856 (defun eshell/du (&rest args) | |
31241 | 857 "Implementation of \"du\" in Lisp, passing ARGS." |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
858 (setq args (if args |
33020 | 859 (eshell-stringify-list (eshell-flatten-list args)) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
860 '("."))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
861 (let ((ext-du (eshell-search-path "du"))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
862 (if (and ext-du |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
863 (not (catch 'have-ange-path |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
864 (eshell-for arg args |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
865 (if (eq (find-file-name-handler (expand-file-name arg) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
866 '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
|
867 '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
|
868 (throw 'have-ange-path t)))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
869 (throw 'eshell-replace-command |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
870 (eshell-parse-command ext-du args)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
871 (eshell-eval-using-options |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
872 "du" args |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
873 '((?a "all" nil show-all |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
874 "write counts for all files, not just directories") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
875 (nil "block-size" t block-size |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
876 "use SIZE-byte blocks (i.e., --block-size SIZE)") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
877 (?b "bytes" nil by-bytes |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
878 "print size in bytes") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
879 (?c "total" nil grand-total |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
880 "produce a grand total") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
881 (?d "max-depth" t max-depth |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
882 "display data only this many levels of data") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
883 (?h "human-readable" 1024 human-readable |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
884 "print sizes in human readable format") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
885 (?H "is" 1000 human-readable |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
886 "likewise, but use powers of 1000 not 1024") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
887 (?k "kilobytes" 1024 block-size |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
888 "like --block-size 1024") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
889 (?L "dereference" nil dereference-links |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
890 "dereference all symbolic links") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
891 (?m "megabytes" 1048576 block-size |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
892 "like --block-size 1048576") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
893 (?s "summarize" 0 max-depth |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
894 "display only a total for each argument") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
895 (?x "one-file-system" nil only-one-filesystem |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
896 "skip directories on different filesystems") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
897 (nil "help" nil nil |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
898 "show this usage screen") |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
899 :external "du" |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
900 :usage "[OPTION]... FILE... |
29876 | 901 Summarize disk usage of each FILE, recursively for directories.") |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
902 (unless by-bytes |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
903 (setq block-size (or block-size 1024))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
904 (if (and max-depth (stringp max-depth)) |
62915
b89e30bcd2bb
Changed all uses of `directory-sep-char' to ?/, and all uses of
John Wiegley <johnw@newartisans.com>
parents:
57742
diff
changeset
|
905 (setq max-depth (string-to-number max-depth))) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
906 ;; filesystem support means nothing under Windows |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
907 (if (eshell-under-windows-p) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
908 (setq only-one-filesystem nil)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
909 (let ((size 0.0) 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
|
910 (while args |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
911 (if only-one-filesystem |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
912 (setq only-one-filesystem |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
913 (nth 11 (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
|
914 (file-name-as-directory (car args)))))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
915 (setq size (+ size (eshell-du-sum-directory |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
916 (directory-file-name (car args)) 0))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
917 (setq args (cdr args))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
918 (if grand-total |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
919 (eshell-print (concat (eshell-du-size-string size) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
920 "total\n")))))))) |
29876 | 921 |
922 (defvar eshell-time-start nil) | |
923 | |
924 (defun eshell-show-elapsed-time () | |
925 (let ((elapsed (format "%.3f secs\n" | |
926 (- (eshell-time-to-seconds (current-time)) | |
927 eshell-time-start)))) | |
928 (set-text-properties 0 (length elapsed) '(face bold) elapsed) | |
929 (eshell-interactive-print elapsed)) | |
930 (remove-hook 'eshell-post-command-hook 'eshell-show-elapsed-time t)) | |
931 | |
932 (defun eshell/time (&rest args) | |
933 "Implementation of \"time\" in Lisp." | |
934 (let ((time-args (copy-alist args)) | |
935 (continue t) | |
936 last-arg) | |
937 (while (and continue args) | |
938 (if (not (string-match "^-" (car args))) | |
939 (progn | |
940 (if last-arg | |
941 (setcdr last-arg nil) | |
942 (setq args '(""))) | |
943 (setq continue nil)) | |
944 (setq last-arg args | |
945 args (cdr args)))) | |
946 (eshell-eval-using-options | |
947 "time" args | |
948 '((?h "help" nil nil "show this usage screen") | |
949 :external "time" | |
950 :show-usage | |
951 :usage "COMMAND... | |
952 Show wall-clock time elapsed during execution of COMMAND.") | |
953 (setq eshell-time-start (eshell-time-to-seconds (current-time))) | |
954 (add-hook 'eshell-post-command-hook 'eshell-show-elapsed-time nil t) | |
955 ;; after setting | |
956 (throw 'eshell-replace-command | |
78715
eae42b4923bd
(eshell/time): Stringify and flatten the non-command arguments.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
957 (eshell-parse-command (car time-args) |
eae42b4923bd
(eshell/time): Stringify and flatten the non-command arguments.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
958 ;;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-08/msg00205.html |
eae42b4923bd
(eshell/time): Stringify and flatten the non-command arguments.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
959 (eshell-stringify-list |
eae42b4923bd
(eshell/time): Stringify and flatten the non-command arguments.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
960 (eshell-flatten-list (cdr time-args)))))))) |
29876 | 961 |
962 (defalias 'eshell/whoami 'user-login-name) | |
963 | |
964 (defvar eshell-diff-window-config nil) | |
965 | |
966 (defun eshell-diff-quit () | |
967 "Restore the window configuration previous to diff'ing." | |
968 (interactive) | |
969 (if eshell-diff-window-config | |
970 (set-window-configuration eshell-diff-window-config))) | |
971 | |
85660
7dd9ef0af1e0
(nil-blank-string): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
85659
diff
changeset
|
972 (defun nil-blank-string (string) |
7dd9ef0af1e0
(nil-blank-string): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
85659
diff
changeset
|
973 "Return STRING, or nil if STRING contains only non-blank characters." |
85659
be317780de60
2007-10-26 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
85503
diff
changeset
|
974 (cond |
85660
7dd9ef0af1e0
(nil-blank-string): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
85659
diff
changeset
|
975 ((string-match "[^[:blank:]]" string) string) |
7dd9ef0af1e0
(nil-blank-string): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
85659
diff
changeset
|
976 (nil))) |
85659
be317780de60
2007-10-26 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
85503
diff
changeset
|
977 |
29876 | 978 (defun eshell/diff (&rest args) |
979 "Alias \"diff\" to call Emacs `diff' function." | |
33020 | 980 (let ((orig-args (eshell-stringify-list (eshell-flatten-list args)))) |
31241 | 981 (if (or eshell-plain-diff-behavior |
982 (not (and (eshell-interactive-output-p) | |
983 (not eshell-in-pipeline-p) | |
984 (not eshell-in-subcommand-p)))) | |
985 (throw 'eshell-replace-command | |
986 (eshell-parse-command "*diff" orig-args)) | |
45734
72f226ee8247
(eshell/diff): Use copy-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
43334
diff
changeset
|
987 (setq args (copy-sequence orig-args)) |
31241 | 988 (if (< (length args) 2) |
989 (throw 'eshell-replace-command | |
990 (eshell-parse-command "*diff" orig-args))) | |
991 (let ((old (car (last args 2))) | |
992 (new (car (last args))) | |
993 (config (current-window-configuration))) | |
994 (if (= (length args) 2) | |
995 (setq args nil) | |
996 (setcdr (last args 3) nil)) | |
997 (with-current-buffer | |
998 (condition-case err | |
85659
be317780de60
2007-10-26 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
85503
diff
changeset
|
999 (diff old new |
be317780de60
2007-10-26 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
85503
diff
changeset
|
1000 (nil-blank-string (eshell-flatten-and-stringify args))) |
31241 | 1001 (error |
1002 (throw 'eshell-replace-command | |
1003 (eshell-parse-command "*diff" orig-args)))) | |
1004 (when (fboundp 'diff-mode) | |
37441
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1005 (make-local-variable 'compilation-finish-functions) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1006 (add-hook |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1007 'compilation-finish-functions |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1008 `(lambda (buff msg) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1009 (with-current-buffer buff |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1010 (diff-mode) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1011 (set (make-local-variable 'eshell-diff-window-config) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1012 ,config) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1013 (local-set-key [?q] 'eshell-diff-quit) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1014 (if (fboundp 'turn-on-font-lock-if-enabled) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1015 (turn-on-font-lock-if-enabled)) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1016 (goto-char (point-min)))))) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1017 (pop-to-buffer (current-buffer)))))) |
565e55bc8630
(eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents:
35588
diff
changeset
|
1018 nil) |
29876 | 1019 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1020 (put 'eshell/diff 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1021 |
29876 | 1022 (defun eshell/locate (&rest args) |
1023 "Alias \"locate\" to call Emacs `locate' function." | |
1024 (if (or eshell-plain-locate-behavior | |
1025 (not (and (eshell-interactive-output-p) | |
1026 (not eshell-in-pipeline-p) | |
1027 (not eshell-in-subcommand-p))) | |
1028 (and (stringp (car args)) | |
1029 (string-match "^-" (car args)))) | |
1030 (throw 'eshell-replace-command | |
33020 | 1031 (eshell-parse-command "*locate" (eshell-stringify-list |
1032 (eshell-flatten-list args)))) | |
29876 | 1033 (save-selected-window |
1034 (let ((locate-history-list (list (car args)))) | |
1035 (locate-with-filter (car args) (cadr args)))))) | |
1036 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1037 (put 'eshell/locate 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1038 |
29876 | 1039 (defun eshell/occur (&rest args) |
1040 "Alias \"occur\" to call Emacs `occur' function." | |
1041 (let ((inhibit-read-only t)) | |
35588 | 1042 (if (> (length args) 2) |
1043 (error "usage: occur: (REGEXP &optional NLINES)") | |
1044 (apply 'occur args)))) | |
29876 | 1045 |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1046 (put 'eshell/occur 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
37655
diff
changeset
|
1047 |
87076
9b97b187c7e2
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86202
diff
changeset
|
1048 (provide 'em-unix) |
29876 | 1049 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1050 ;; arch-tag: 2462edd2-a76a-4cf2-897d-92e9a82ac1c9 |
29876 | 1051 ;;; em-unix.el ends here |