Mercurial > emacs
annotate lisp/eshell/esh-cmd.el @ 63280:69ae2aff114c
Fixes for changes of 2005-06-09.
(thumbs-thumbsdir): Force `thumbs-thumbsdir' to be interpretable as a directory.
(thumbs-thumbname): Remove directory separator from format string;
`thumbs-thumbsdir' now returns a valid directory name.
(thumbs-temp-dir): New defsubst.
(thumbs-temp-file, thumbs-resize-image, thumbs-modify-image): Use it.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 10 Jun 2005 14:59:59 +0000 |
parents | 74e26c83386f |
children | 18a818a2ee7c 01137c1fdbe9 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38007
diff
changeset
|
1 ;;; esh-cmd.el --- command invocation |
29873 | 2 |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29875
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation |
29873 | 4 |
32526 | 5 ;; Author: John Wiegley <johnw@gnu.org> |
6 | |
29873 | 7 ;; This file is part of GNU Emacs. |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 (provide 'esh-cmd) | |
25 | |
26 (eval-when-compile (require 'esh-maint)) | |
27 | |
28 (defgroup eshell-cmd nil | |
29 "Executing an Eshell command is as simple as typing it in and | |
30 pressing <RET>. There are several different kinds of commands, | |
31 however." | |
32 :tag "Command invocation" | |
54568
90583f4cef75
* eshell/esh-cmd.el (eshell-cmd):
Juri Linkov <juri@jurta.org>
parents:
53051
diff
changeset
|
33 ;; :link '(info-link "(eshell)Command invocation") |
29873 | 34 :group 'eshell) |
35 | |
36 ;;; Commentary: | |
37 | |
38 ;;;_* Invoking external commands | |
39 ;; | |
40 ;; External commands cause processes to be created, by loading | |
41 ;; external executables into memory. This is what most normal shells | |
42 ;; do, most of the time. For more information, see [External commands]. | |
43 ;; | |
44 ;;;_* Invoking Lisp functions | |
45 ;; | |
46 ;; A Lisp function can be invoked using Lisp syntax, or command shell | |
47 ;; syntax. For example, to run `dired' to edit the current directory: | |
48 ;; | |
49 ;; /tmp $ (dired ".") | |
50 ;; | |
51 ;; Or: | |
52 ;; | |
53 ;; /tmp $ dired . | |
54 ;; | |
55 ;; The latter form is preferable, but the former is more precise, | |
56 ;; since it involves no translations. See [Argument parsing], to | |
57 ;; learn more about how arguments are transformed before passing them | |
58 ;; to commands. | |
59 ;; | |
60 ;; Ordinarily, if 'dired' were also available as an external command, | |
61 ;; the external version would be called in preference to any Lisp | |
62 ;; function of the same name. To change this behavior so that Lisp | |
63 ;; functions always take precedence, set | |
64 ;; `eshell-prefer-lisp-functions' to t. | |
65 | |
66 (defcustom eshell-prefer-lisp-functions nil | |
67 "*If non-nil, prefer Lisp functions to external commands." | |
68 :type 'boolean | |
69 :group 'eshell-cmd) | |
70 | |
71 ;;;_* Alias functions | |
72 ;; | |
73 ;; Whenever a command is specified using a simple name, such as 'ls', | |
74 ;; Eshell will first look for a Lisp function of the name `eshell/ls'. | |
75 ;; If it exists, it will be called in preference to any other command | |
76 ;; which might have matched the name 'ls' (such as command aliases, | |
77 ;; external commands, Lisp functions of that name, etc). | |
78 ;; | |
79 ;; This is the most flexible mechanism for creating new commands, | |
80 ;; since it does not pollute the global namespace, yet allows you to | |
81 ;; use all of Lisp's facilities to define that piece of functionality. | |
82 ;; Most of Eshell's "builtin" commands are defined as alias functions. | |
83 ;; | |
84 ;;;_* Lisp arguments | |
85 ;; | |
86 ;; It is possible to invoke a Lisp form as an argument. This can be | |
87 ;; done either by specifying the form as you might in Lisp, or by | |
88 ;; using the '$' character to introduce a value-interpolation: | |
89 ;; | |
90 ;; echo (+ 1 2) | |
91 ;; | |
92 ;; Or | |
93 ;; | |
94 ;; echo $(+ 1 2) | |
95 ;; | |
96 ;; The two forms are equivalent. The second is required only if the | |
97 ;; form being interpolated is within a string, or is a subexpression | |
98 ;; of a larger argument: | |
99 ;; | |
100 ;; echo x$(+ 1 2) "String $(+ 1 2)" | |
101 ;; | |
102 ;; To pass a Lisp symbol as a argument, use the alternate quoting | |
103 ;; syntax, since the single quote character is far too overused in | |
104 ;; shell syntax: | |
105 ;; | |
106 ;; echo #'lisp-symbol | |
107 ;; | |
108 ;; Backquote can also be used: | |
109 ;; | |
110 ;; echo `(list ,lisp-symbol) | |
111 ;; | |
112 ;; Lisp arguments are identified using the following regexp: | |
113 | |
114 (defcustom eshell-lisp-regexp "\\([(`]\\|#'\\)" | |
115 "*A regexp which, if matched at beginning of an argument, means Lisp. | |
116 Such arguments will be passed to `read', and then evaluated." | |
117 :type 'regexp | |
118 :group 'eshell-cmd) | |
119 | |
120 ;;;_* Command hooks | |
121 ;; | |
122 ;; There are several hooks involved with command execution, which can | |
123 ;; be used either to change or augment Eshell's behavior. | |
124 | |
125 (defcustom eshell-pre-command-hook nil | |
126 "*A hook run before each interactive command is invoked." | |
127 :type 'hook | |
128 :group 'eshell-cmd) | |
129 | |
130 (defcustom eshell-post-command-hook nil | |
131 "*A hook run after each interactive command is invoked." | |
132 :type 'hook | |
133 :group 'eshell-cmd) | |
134 | |
135 (defcustom eshell-prepare-command-hook nil | |
136 "*A set of functions called to prepare a named command. | |
137 The command name and its argument are in `eshell-last-command-name' | |
138 and `eshell-last-arguments'. The functions on this hook can change | |
139 the value of these symbols if necessary. | |
140 | |
141 To prevent a command from executing at all, set | |
142 `eshell-last-command-name' to nil." | |
143 :type 'hook | |
144 :group 'eshell-cmd) | |
145 | |
146 (defcustom eshell-named-command-hook nil | |
147 "*A set of functions called before a named command is invoked. | |
148 Each function will be passed the command name and arguments that were | |
149 passed to `eshell-named-command'. | |
150 | |
151 If any of the functions returns a non-nil value, the named command | |
152 will not be invoked, and that value will be returned from | |
153 `eshell-named-command'. | |
154 | |
155 In order to substitute an alternate command form for execution, the | |
156 hook function should throw it using the tag `eshell-replace-command'. | |
157 For example: | |
158 | |
159 (add-hook 'eshell-named-command-hook 'subst-with-cd) | |
160 (defun subst-with-cd (command args) | |
161 (throw 'eshell-replace-command | |
162 (eshell-parse-command \"cd\" args))) | |
163 | |
164 Although useless, the above code will cause any non-glob, non-Lisp | |
165 command (i.e., 'ls' as opposed to '*ls' or '(ls)') to be replaced by a | |
166 call to `cd' using the arguments that were passed to the function." | |
167 :type 'hook | |
168 :group 'eshell-cmd) | |
169 | |
170 (defcustom eshell-pre-rewrite-command-hook | |
171 '(eshell-no-command-conversion | |
172 eshell-subcommand-arg-values) | |
173 "*A hook run before command rewriting begins. | |
174 The terms of the command to be rewritten is passed as arguments, and | |
175 may be modified in place. Any return value is ignored." | |
176 :type 'hook | |
177 :group 'eshell-cmd) | |
178 | |
179 (defcustom eshell-rewrite-command-hook | |
180 '(eshell-rewrite-for-command | |
181 eshell-rewrite-while-command | |
182 eshell-rewrite-if-command | |
183 eshell-rewrite-sexp-command | |
184 eshell-rewrite-initial-subcommand | |
185 eshell-rewrite-named-command) | |
186 "*A set of functions used to rewrite the command argument. | |
187 Once parsing of a command line is completed, the next step is to | |
188 rewrite the initial argument into something runnable. | |
189 | |
190 A module may wish to associate special behavior with certain argument | |
191 syntaxes at the beginning of a command line. They are welcome to do | |
192 so by adding a function to this hook. The first function to return a | |
193 substitute command form is the one used. Each function is passed the | |
194 command's full argument list, which is a list of sexps (typically | |
195 forms or strings)." | |
196 :type 'hook | |
197 :group 'eshell-cmd) | |
198 | |
199 (defcustom eshell-post-rewrite-command-hook nil | |
200 "*A hook run after command rewriting is finished. | |
201 Each function is passed the symbol containing the rewritten command, | |
202 which may be modified directly. Any return value is ignored." | |
203 :type 'hook | |
204 :group 'eshell-cmd) | |
205 | |
33020 | 206 (defcustom eshell-complex-commands nil |
207 "*A list of commands names or functions, that determine complexity. | |
208 That is, if a command is defined by a function named eshell/NAME, | |
209 and NAME is part of this list, it is invoked as a complex command. | |
210 Complex commands are always correct, but run much slower. If a | |
211 command works fine without being part of this list, then it doesn't | |
212 need to be. | |
213 | |
214 If an entry is a function, it will be called with the name, and should | |
215 return non-nil if the command is complex." | |
216 :type '(repeat :tag "Commands" | |
217 (choice (string :tag "Name") | |
218 (function :tag "Predicate"))) | |
219 :group 'eshell-cmd) | |
220 | |
29873 | 221 ;;; Code: |
222 | |
223 (require 'esh-util) | |
224 (unless (eshell-under-xemacs-p) | |
225 (require 'eldoc)) | |
226 (require 'esh-arg) | |
227 (require 'esh-proc) | |
228 (require 'esh-ext) | |
229 | |
230 ;;; User Variables: | |
231 | |
232 (defcustom eshell-cmd-load-hook '(eshell-cmd-initialize) | |
233 "*A hook that gets run when `eshell-cmd' is loaded." | |
234 :type 'hook | |
235 :group 'eshell-cmd) | |
236 | |
237 (defcustom eshell-debug-command nil | |
238 "*If non-nil, enable debugging code. SSLLOOWW. | |
239 This option is only useful for reporting bugs. If you enable it, you | |
240 will have to visit the file 'eshell-cmd.el' and run the command | |
241 \\[eval-buffer]." | |
242 :type 'boolean | |
243 :group 'eshell-cmd) | |
244 | |
245 (defcustom eshell-deferrable-commands | |
246 '(eshell-named-command | |
247 eshell-lisp-command | |
248 eshell-process-identity) | |
249 "*A list of functions which might return an ansychronous process. | |
250 If they return a process object, execution of the calling Eshell | |
251 command will wait for completion (in the background) before finishing | |
252 the command." | |
253 :type '(repeat function) | |
254 :group 'eshell-cmd) | |
255 | |
256 (defcustom eshell-subcommand-bindings | |
257 '((eshell-in-subcommand-p t) | |
258 (default-directory default-directory) | |
259 (process-environment (eshell-copy-environment))) | |
260 "*A list of `let' bindings for subcommand environments." | |
261 :type 'sexp | |
262 :group 'eshell-cmd) | |
263 | |
264 (put 'risky-local-variable 'eshell-subcommand-bindings t) | |
265 | |
266 (defvar eshell-ensure-newline-p nil | |
267 "If non-nil, ensure that a newline is emitted after a Lisp form. | |
268 This can be changed by Lisp forms that are evaluated from the Eshell | |
269 command line.") | |
270 | |
271 ;;; Internal Variables: | |
272 | |
273 (defvar eshell-current-command nil) | |
274 (defvar eshell-command-name nil) | |
275 (defvar eshell-command-arguments nil) | |
276 (defvar eshell-in-pipeline-p nil) | |
277 (defvar eshell-in-subcommand-p nil) | |
278 (defvar eshell-last-arguments nil) | |
279 (defvar eshell-last-command-name nil) | |
280 (defvar eshell-last-async-proc nil | |
281 "When this foreground process completes, resume command evaluation.") | |
282 | |
283 ;;; Functions: | |
284 | |
285 (defsubst eshell-interactive-process () | |
286 "Return currently running command process, if non-Lisp." | |
287 eshell-last-async-proc) | |
288 | |
289 (defun eshell-cmd-initialize () | |
290 "Initialize the Eshell command processing module." | |
291 (set (make-local-variable 'eshell-current-command) nil) | |
292 (set (make-local-variable 'eshell-command-name) nil) | |
293 (set (make-local-variable 'eshell-command-arguments) nil) | |
294 (set (make-local-variable 'eshell-last-arguments) nil) | |
295 (set (make-local-variable 'eshell-last-command-name) nil) | |
296 (set (make-local-variable 'eshell-last-async-proc) nil) | |
297 | |
298 (add-hook 'eshell-kill-hook 'eshell-resume-command nil t) | |
299 | |
300 ;; make sure that if a command is over, and no process is being | |
301 ;; waited for, that `eshell-current-command' is set to nil. This | |
302 ;; situation can occur, for example, if a Lisp function results in | |
303 ;; `debug' being called, and the user then types \\[top-level] | |
304 (add-hook 'eshell-post-command-hook | |
305 (function | |
306 (lambda () | |
307 (setq eshell-current-command nil | |
308 eshell-last-async-proc nil))) nil t) | |
309 | |
310 (add-hook 'eshell-parse-argument-hook | |
311 'eshell-parse-subcommand-argument nil t) | |
312 (add-hook 'eshell-parse-argument-hook | |
313 'eshell-parse-lisp-argument nil t) | |
314 | |
315 (when (eshell-using-module 'eshell-cmpl) | |
316 (add-hook 'pcomplete-try-first-hook | |
317 'eshell-complete-lisp-symbols nil t))) | |
318 | |
319 (eshell-deftest var last-result-var | |
320 "\"last result\" variable" | |
321 (eshell-command-result-p "+ 1 2; + $$ 2" "3\n5\n")) | |
322 | |
323 (eshell-deftest var last-result-var2 | |
324 "\"last result\" variable" | |
325 (eshell-command-result-p "+ 1 2; + $$ $$" "3\n6\n")) | |
326 | |
327 (eshell-deftest var last-arg-var | |
328 "\"last arg\" variable" | |
329 (eshell-command-result-p "+ 1 2; + $_ 4" "3\n6\n")) | |
330 | |
331 (defun eshell-complete-lisp-symbols () | |
332 "If there is a user reference, complete it." | |
333 (let ((arg (pcomplete-actual-arg))) | |
334 (when (string-match (concat "\\`" eshell-lisp-regexp) arg) | |
335 (setq pcomplete-stub (substring arg (match-end 0)) | |
336 pcomplete-last-completion-raw t) | |
337 (throw 'pcomplete-completions | |
338 (all-completions pcomplete-stub obarray 'boundp))))) | |
339 | |
340 ;; Command parsing | |
341 | |
342 (defun eshell-parse-command (command &optional args top-level) | |
343 "Parse the COMMAND, adding ARGS if given. | |
344 COMMAND can either be a string, or a cons cell demarcating a buffer | |
345 region. TOP-LEVEL, if non-nil, means that the outermost command (the | |
346 user's input command) is being parsed, and that pre and post command | |
347 hooks should be run before and after the command." | |
348 (let* (sep-terms | |
349 (terms | |
350 (append | |
351 (if (consp command) | |
352 (eshell-parse-arguments (car command) (cdr command)) | |
353 (let ((here (point)) | |
354 (inhibit-point-motion-hooks t) | |
355 after-change-functions) | |
356 (insert command) | |
357 (prog1 | |
358 (eshell-parse-arguments here (point)) | |
359 (delete-region here (point))))) | |
360 args)) | |
361 (commands | |
362 (mapcar | |
363 (function | |
364 (lambda (cmd) | |
365 (if (or (not (car sep-terms)) | |
366 (string= (car sep-terms) ";")) | |
367 (setq cmd | |
368 (eshell-parse-pipeline cmd (not (car sep-terms)))) | |
369 (setq cmd | |
370 (list 'eshell-do-subjob | |
371 (list 'list (eshell-parse-pipeline cmd))))) | |
372 (setq sep-terms (cdr sep-terms)) | |
373 (if eshell-in-pipeline-p | |
374 cmd | |
375 (list 'eshell-trap-errors cmd)))) | |
376 (eshell-separate-commands terms "[&;]" nil 'sep-terms)))) | |
377 (let ((cmd commands)) | |
378 (while cmd | |
379 (if (cdr cmd) | |
380 (setcar cmd (list 'eshell-commands (car cmd)))) | |
381 (setq cmd (cdr cmd)))) | |
382 (setq commands | |
383 (append (list 'progn) | |
384 (if top-level | |
385 (list '(run-hooks 'eshell-pre-command-hook))) | |
386 (if (not top-level) | |
387 commands | |
388 (list | |
389 (list 'catch (quote 'top-level) | |
390 (append (list 'progn) commands)) | |
391 '(run-hooks 'eshell-post-command-hook))))) | |
392 (if top-level | |
393 (list 'eshell-commands commands) | |
394 commands))) | |
395 | |
396 (defun eshell-debug-show-parsed-args (terms) | |
397 "Display parsed arguments in the debug buffer." | |
398 (ignore | |
399 (if eshell-debug-command | |
400 (eshell-debug-command "parsed arguments" terms)))) | |
401 | |
402 (defun eshell-no-command-conversion (terms) | |
403 "Don't convert the command argument." | |
404 (ignore | |
405 (if (and (listp (car terms)) | |
406 (eq (caar terms) 'eshell-convert)) | |
407 (setcar terms (cadr (car terms)))))) | |
408 | |
409 (defun eshell-subcommand-arg-values (terms) | |
410 "Convert subcommand arguments {x} to ${x}, in order to take their values." | |
411 (setq terms (cdr terms)) ; skip command argument | |
412 (while terms | |
413 (if (and (listp (car terms)) | |
414 (eq (caar terms) 'eshell-as-subcommand)) | |
415 (setcar terms (list 'eshell-convert | |
416 (list 'eshell-command-to-value | |
417 (car terms))))) | |
418 (setq terms (cdr terms)))) | |
419 | |
420 (defun eshell-rewrite-sexp-command (terms) | |
421 "Rewrite a sexp in initial position, such as '(+ 1 2)'." | |
422 ;; this occurs when a Lisp expression is in first position | |
423 (if (and (listp (car terms)) | |
424 (eq (caar terms) 'eshell-command-to-value)) | |
425 (car (cdar terms)))) | |
426 | |
427 (eshell-deftest cmd lisp-command | |
428 "Evaluate Lisp command" | |
429 (eshell-command-result-p "(+ 1 2)" "3")) | |
430 | |
431 (eshell-deftest cmd lisp-command-args | |
432 "Evaluate Lisp command (ignore args)" | |
433 (eshell-command-result-p "(+ 1 2) 3" "3")) | |
434 | |
435 (defun eshell-rewrite-initial-subcommand (terms) | |
436 "Rewrite a subcommand in initial position, such as '{+ 1 2}'." | |
437 (if (and (listp (car terms)) | |
438 (eq (caar terms) 'eshell-as-subcommand)) | |
439 (car terms))) | |
440 | |
441 (eshell-deftest cmd subcommand | |
442 "Run subcommand" | |
443 (eshell-command-result-p "{+ 1 2}" "3\n")) | |
444 | |
445 (eshell-deftest cmd subcommand-args | |
446 "Run subcommand (ignore args)" | |
447 (eshell-command-result-p "{+ 1 2} 3" "3\n")) | |
448 | |
449 (eshell-deftest cmd subcommand-lisp | |
450 "Run subcommand + Lisp form" | |
451 (eshell-command-result-p "{(+ 1 2)}" "3\n")) | |
452 | |
453 (defun eshell-rewrite-named-command (terms) | |
454 "If no other rewriting rule transforms TERMS, assume a named command." | |
455 (list (if eshell-in-pipeline-p | |
456 'eshell-named-command* | |
457 'eshell-named-command) | |
458 (car terms) | |
459 (and (cdr terms) | |
460 (append (list 'list) (cdr terms))))) | |
461 | |
462 (eshell-deftest cmd named-command | |
463 "Execute named command" | |
464 (eshell-command-result-p "+ 1 2" "3\n")) | |
465 | |
466 (eval-when-compile | |
467 (defvar eshell-command-body) | |
468 (defvar eshell-test-body)) | |
469 | |
470 (defsubst eshell-invokify-arg (arg &optional share-output silent) | |
471 "Change ARG so it can be invoked from a structured command. | |
472 | |
473 SHARE-OUTPUT, if non-nil, means this invocation should share the | |
474 current output stream, which is separately redirectable. SILENT | |
475 means the user and/or any redirections shouldn't see any output | |
476 from this command. If both SHARE-OUTPUT and SILENT are non-nil, | |
477 the second is ignored." | |
478 ;; something that begins with `eshell-convert' means that it | |
479 ;; intends to return a Lisp value. We want to get past this, | |
480 ;; but if it's not _actually_ a value interpolation -- in which | |
481 ;; we leave it alone. In fact, the only time we muck with it | |
482 ;; is in the case of a {subcommand} that has been turned into | |
483 ;; the interpolation, ${subcommand}, by the parser because it | |
484 ;; didn't know better. | |
485 (if (and (listp arg) | |
486 (eq (car arg) 'eshell-convert) | |
487 (eq (car (cadr arg)) 'eshell-command-to-value)) | |
488 (if share-output | |
489 (cadr (cadr arg)) | |
490 (list 'eshell-commands (cadr (cadr arg)) | |
491 silent)) | |
492 arg)) | |
493 | |
494 (defun eshell-rewrite-for-command (terms) | |
495 "Rewrite a `for' command into its equivalent Eshell command form. | |
496 Because the implementation of `for' relies upon conditional evaluation | |
497 of its argumbent (i.e., use of a Lisp special form), it must be | |
498 implemented via rewriting, rather than as a function." | |
499 (if (and (stringp (car terms)) | |
500 (string= (car terms) "for") | |
501 (stringp (nth 2 terms)) | |
502 (string= (nth 2 terms) "in")) | |
503 (let ((body (car (last terms)))) | |
504 (setcdr (last terms 2) nil) | |
505 (list | |
506 'let (list (list 'for-items | |
507 (append | |
508 (list 'append) | |
509 (mapcar | |
510 (function | |
511 (lambda (elem) | |
512 (if (listp elem) | |
513 elem | |
514 (list 'list elem)))) | |
29875
19baeeb660f1
(eshell-rewrite-for-command): Use cdr and
Gerd Moellmann <gerd@gnu.org>
parents:
29873
diff
changeset
|
515 (cdr (cddr terms))))) |
29873 | 516 (list 'eshell-command-body |
517 (list 'quote (list nil))) | |
518 (list 'eshell-test-body | |
519 (list 'quote (list nil)))) | |
520 (list | |
521 'progn | |
522 (list | |
523 'while (list 'car (list 'symbol-value | |
524 (list 'quote 'for-items))) | |
525 (list | |
526 'progn | |
527 (list 'let | |
528 (list (list (intern (cadr terms)) | |
529 (list 'car | |
530 (list 'symbol-value | |
531 (list 'quote 'for-items))))) | |
33020 | 532 (list 'eshell-protect |
533 (eshell-invokify-arg body t))) | |
29873 | 534 (list 'setcar 'for-items |
535 (list 'cadr | |
536 (list 'symbol-value | |
537 (list 'quote 'for-items)))) | |
538 (list 'setcdr 'for-items | |
539 (list 'cddr | |
540 (list 'symbol-value | |
541 (list 'quote 'for-items)))))) | |
542 (list 'eshell-close-handles | |
543 'eshell-last-command-status | |
544 (list 'list (quote 'quote) | |
545 'eshell-last-command-result))))))) | |
546 | |
547 (defun eshell-structure-basic-command (func names keyword test body | |
548 &optional else vocal-test) | |
549 "With TERMS, KEYWORD, and two NAMES, structure a basic command. | |
550 The first of NAMES should be the positive form, and the second the | |
551 negative. It's not likely that users should ever need to call this | |
552 function. | |
553 | |
554 If VOCAL-TEST is non-nil, it means output from the test should be | |
555 shown, as well as output from the body." | |
556 ;; If the test form begins with `eshell-convert', it means | |
557 ;; something data-wise will be returned, and we should let | |
558 ;; that determine the truth of the statement. | |
559 (unless (eq (car test) 'eshell-convert) | |
560 (setq test | |
561 (list 'progn test | |
562 (list 'eshell-exit-success-p)))) | |
563 | |
564 ;; should we reverse the sense of the test? This depends | |
565 ;; on the `names' parameter. If it's the symbol nil, yes. | |
566 ;; Otherwise, it can be a pair of strings; if the keyword | |
567 ;; we're using matches the second member of that pair (a | |
568 ;; list), we should reverse it. | |
569 (if (or (eq names nil) | |
570 (and (listp names) | |
571 (string= keyword (cadr names)))) | |
572 (setq test (list 'not test))) | |
573 | |
574 ;; finally, create the form that represents this structured | |
575 ;; command | |
576 (list | |
577 'let (list (list 'eshell-command-body | |
578 (list 'quote (list nil))) | |
579 (list 'eshell-test-body | |
580 (list 'quote (list nil)))) | |
581 (list func test body else) | |
582 (list 'eshell-close-handles | |
583 'eshell-last-command-status | |
584 (list 'list (quote 'quote) | |
585 'eshell-last-command-result)))) | |
586 | |
587 (defun eshell-rewrite-while-command (terms) | |
588 "Rewrite a `while' command into its equivalent Eshell command form. | |
589 Because the implementation of `while' relies upon conditional | |
590 evaluation of its argument (i.e., use of a Lisp special form), it | |
591 must be implemented via rewriting, rather than as a function." | |
592 (if (and (stringp (car terms)) | |
593 (member (car terms) '("while" "until"))) | |
594 (eshell-structure-basic-command | |
595 'while '("while" "until") (car terms) | |
596 (eshell-invokify-arg (cadr terms) nil t) | |
33020 | 597 (list 'eshell-protect |
29873 | 598 (eshell-invokify-arg (car (last terms)) t))))) |
599 | |
600 (defun eshell-rewrite-if-command (terms) | |
601 "Rewrite an `if' command into its equivalent Eshell command form. | |
602 Because the implementation of `if' relies upon conditional | |
603 evaluation of its argument (i.e., use of a Lisp special form), it | |
604 must be implemented via rewriting, rather than as a function." | |
605 (if (and (stringp (car terms)) | |
606 (member (car terms) '("if" "unless"))) | |
607 (eshell-structure-basic-command | |
608 'if '("if" "unless") (car terms) | |
609 (eshell-invokify-arg (cadr terms) nil t) | |
33020 | 610 (list 'eshell-protect |
611 (eshell-invokify-arg | |
38007
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
612 (if (= (length terms) 4) |
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
613 (car (last terms 2)) |
33020 | 614 (car (last terms))) t)) |
38007
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
615 (if (= (length terms) 4) |
33020 | 616 (list 'eshell-protect |
617 (eshell-invokify-arg | |
618 (car (last terms)))) t)))) | |
29873 | 619 |
620 (defun eshell-exit-success-p () | |
621 "Return non-nil if the last command was \"successful\". | |
622 For a bit of Lisp code, this means a return value of non-nil. | |
623 For an external command, it means an exit code of 0." | |
38007
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
624 (if (save-match-data |
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
625 (string-match "#<\\(Lisp object\\|function .*\\)>" |
fa54203d014a
(eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents:
37817
diff
changeset
|
626 eshell-last-command-name)) |
29873 | 627 eshell-last-command-result |
628 (= eshell-last-command-status 0))) | |
629 | |
630 (defun eshell-parse-pipeline (terms &optional final-p) | |
631 "Parse a pipeline from TERMS, return the appropriate Lisp forms." | |
632 (let* (sep-terms | |
633 (bigpieces (eshell-separate-commands terms "\\(&&\\|||\\)" | |
634 nil 'sep-terms)) | |
635 (bp bigpieces) | |
636 (results (list t)) | |
637 final) | |
638 (while bp | |
639 (let ((subterms (car bp))) | |
640 (let* ((pieces (eshell-separate-commands subterms "|")) | |
641 (p pieces)) | |
642 (while p | |
643 (let ((cmd (car p))) | |
644 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd) | |
645 (setq cmd (run-hook-with-args-until-success | |
646 'eshell-rewrite-command-hook cmd)) | |
647 (run-hook-with-args 'eshell-post-rewrite-command-hook 'cmd) | |
648 (setcar p cmd)) | |
649 (setq p (cdr p))) | |
650 (nconc results | |
651 (list | |
652 (if (<= (length pieces) 1) | |
653 (car pieces) | |
654 (assert (not eshell-in-pipeline-p)) | |
655 (list 'eshell-execute-pipeline | |
656 (list 'quote pieces)))))) | |
657 (setq bp (cdr bp)))) | |
658 ;; `results' might be empty; this happens in the case of | |
659 ;; multi-line input | |
660 (setq results (cdr results) | |
661 results (nreverse results) | |
662 final (car results) | |
663 results (cdr results) | |
664 sep-terms (nreverse sep-terms)) | |
665 (while results | |
666 (assert (car sep-terms)) | |
667 (setq final (eshell-structure-basic-command | |
668 'if (string= (car sep-terms) "&&") "if" | |
33020 | 669 (list 'eshell-protect (car results)) |
670 (list 'eshell-protect final) | |
29873 | 671 nil t) |
672 results (cdr results) | |
673 sep-terms (cdr sep-terms))) | |
674 final)) | |
675 | |
676 (defun eshell-parse-subcommand-argument () | |
677 "Parse a subcommand argument of the form '{command}'." | |
678 (if (and (not eshell-current-argument) | |
679 (not eshell-current-quoted) | |
680 (eq (char-after) ?\{) | |
681 (or (= (point-max) (1+ (point))) | |
682 (not (eq (char-after (1+ (point))) ?\})))) | |
683 (let ((end (eshell-find-delimiter ?\{ ?\}))) | |
684 (if (not end) | |
685 (throw 'eshell-incomplete ?\{) | |
686 (when (eshell-arg-delimiter (1+ end)) | |
687 (prog1 | |
688 (list 'eshell-as-subcommand | |
689 (eshell-parse-command (cons (1+ (point)) end))) | |
690 (goto-char (1+ end)))))))) | |
691 | |
692 (defun eshell-parse-lisp-argument () | |
693 "Parse a Lisp expression which is specified as an argument." | |
694 (if (and (not eshell-current-argument) | |
695 (not eshell-current-quoted) | |
696 (looking-at eshell-lisp-regexp)) | |
697 (let* ((here (point)) | |
698 (obj | |
699 (condition-case err | |
700 (read (current-buffer)) | |
701 (end-of-file | |
702 (throw 'eshell-incomplete ?\())))) | |
703 (if (eshell-arg-delimiter) | |
704 (list 'eshell-command-to-value | |
705 (list 'eshell-lisp-command (list 'quote obj))) | |
706 (ignore (goto-char here)))))) | |
707 | |
33020 | 708 (defun eshell-separate-commands (terms separator &optional |
709 reversed last-terms-sym) | |
29873 | 710 "Separate TERMS using SEPARATOR. |
711 If REVERSED is non-nil, the list of separated term groups will be | |
49477
ea69593b3b09
(eshell-separate-commands): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
48211
diff
changeset
|
712 returned in reverse order. If LAST-TERMS-SYM is a symbol, its value |
29873 | 713 will be set to a list of all the separator operators found (or '(list |
714 nil)' if none)." | |
715 (let ((sub-terms (list t)) | |
716 (eshell-sep-terms (list t)) | |
717 subchains) | |
718 (while terms | |
719 (if (and (consp (car terms)) | |
720 (eq (caar terms) 'eshell-operator) | |
721 (string-match (concat "^" separator "$") | |
722 (nth 1 (car terms)))) | |
723 (progn | |
724 (nconc eshell-sep-terms (list (nth 1 (car terms)))) | |
725 (setq subchains (cons (cdr sub-terms) subchains) | |
726 sub-terms (list t))) | |
727 (nconc sub-terms (list (car terms)))) | |
728 (setq terms (cdr terms))) | |
729 (if (> (length sub-terms) 1) | |
730 (setq subchains (cons (cdr sub-terms) subchains))) | |
731 (if reversed | |
732 (progn | |
733 (if last-terms-sym | |
734 (set last-terms-sym (reverse (cdr eshell-sep-terms)))) | |
735 subchains) ; already reversed | |
736 (if last-terms-sym | |
737 (set last-terms-sym (cdr eshell-sep-terms))) | |
738 (nreverse subchains)))) | |
739 | |
740 ;;_* Command evaluation macros | |
741 ;; | |
742 ;; The structure of the following macros is very important to | |
743 ;; `eshell-do-eval' [Iterative evaluation]: | |
744 ;; | |
745 ;; @ Don't use forms that conditionally evaluate their arguments, such | |
746 ;; as `setq', `if', `while', `let*', etc. The only special forms | |
747 ;; that can be used are `let', `condition-case' and | |
748 ;; `unwind-protect'. | |
749 ;; | |
750 ;; @ The main body of a `let' can contain only one form. Use `progn' | |
751 ;; if necessary. | |
752 ;; | |
753 ;; @ The two `special' variables are `eshell-current-handles' and | |
754 ;; `eshell-current-subjob-p'. Bind them locally with a `let' if you | |
755 ;; need to change them. Change them directly only if your intention | |
756 ;; is to change the calling environment. | |
757 | |
758 (defmacro eshell-do-subjob (object) | |
759 "Evaluate a command OBJECT as a subjob. | |
62789
74e26c83386f
(eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents:
59121
diff
changeset
|
760 We indicate that the process was run in the background by returning it |
29873 | 761 ensconced in a list." |
762 `(let ((eshell-current-subjob-p t)) | |
763 ,object)) | |
764 | |
765 (defmacro eshell-commands (object &optional silent) | |
766 "Place a valid set of handles, and context, around command OBJECT." | |
767 `(let ((eshell-current-handles | |
768 (eshell-create-handles ,(not silent) 'append)) | |
769 eshell-current-subjob-p) | |
770 ,object)) | |
771 | |
772 (defmacro eshell-trap-errors (object) | |
773 "Trap any errors that occur, so they are not entirely fatal. | |
774 Also, the variable `eshell-this-command-hook' is available for the | |
775 duration of OBJECT's evaluation. Note that functions should be added | |
776 to this hook using `nconc', and *not* `add-hook'. | |
777 | |
778 Someday, when Scheme will become the dominant Emacs language, all of | |
779 this grossness will be made to disappear by using `call/cc'..." | |
780 `(let ((eshell-this-command-hook (list 'ignore))) | |
781 (eshell-condition-case err | |
782 (prog1 | |
783 ,object | |
784 (run-hooks 'eshell-this-command-hook)) | |
785 (error | |
786 (run-hooks 'eshell-this-command-hook) | |
787 (eshell-errorn (error-message-string err)) | |
788 (eshell-close-handles 1))))) | |
789 | |
31241 | 790 (defmacro eshell-copy-handles (object) |
791 "Duplicate current I/O handles, so OBJECT works with its own copy." | |
792 `(let ((eshell-current-handles | |
793 (eshell-create-handles | |
794 (car (aref eshell-current-handles | |
795 eshell-output-handle)) nil | |
796 (car (aref eshell-current-handles | |
797 eshell-error-handle)) nil))) | |
798 ,object)) | |
799 | |
29873 | 800 (defmacro eshell-protect (object) |
801 "Protect I/O handles, so they aren't get closed after eval'ing OBJECT." | |
802 `(progn | |
803 (eshell-protect-handles eshell-current-handles) | |
804 ,object)) | |
805 | |
806 (defmacro eshell-do-pipelines (pipeline) | |
807 "Execute the commands in PIPELINE, connecting each to one another." | |
808 (when (setq pipeline (cadr pipeline)) | |
31241 | 809 `(eshell-copy-handles |
810 (progn | |
811 ,(when (cdr pipeline) | |
812 `(let (nextproc) | |
813 (progn | |
814 (set 'nextproc | |
815 (eshell-do-pipelines (quote ,(cdr pipeline)))) | |
816 (eshell-set-output-handle ,eshell-output-handle | |
817 'append nextproc) | |
818 (eshell-set-output-handle ,eshell-error-handle | |
819 'append nextproc) | |
820 (set 'tailproc (or tailproc nextproc))))) | |
821 ,(let ((head (car pipeline))) | |
822 (if (memq (car head) '(let progn)) | |
823 (setq head (car (last head)))) | |
824 (when (memq (car head) eshell-deferrable-commands) | |
825 (ignore | |
826 (setcar head | |
827 (intern-soft | |
828 (concat (symbol-name (car head)) "*")))))) | |
829 ,(car pipeline))))) | |
830 | |
831 (defmacro eshell-do-pipelines-synchronously (pipeline) | |
832 "Execute the commands in PIPELINE in sequence synchronously. | |
833 Output of each command is passed as input to the next one in the pipeline. | |
834 This is used on systems where `start-process' is not supported." | |
835 (when (setq pipeline (cadr pipeline)) | |
836 `(let (result) | |
29873 | 837 (progn |
838 ,(when (cdr pipeline) | |
31241 | 839 `(let (output-marker) |
29873 | 840 (progn |
31241 | 841 (set 'output-marker ,(point-marker)) |
29873 | 842 (eshell-set-output-handle ,eshell-output-handle |
31241 | 843 'append output-marker) |
29873 | 844 (eshell-set-output-handle ,eshell-error-handle |
31241 | 845 'append output-marker)))) |
29873 | 846 ,(let ((head (car pipeline))) |
847 (if (memq (car head) '(let progn)) | |
848 (setq head (car (last head)))) | |
31241 | 849 ;;; FIXME: is deferrable significant here? |
29873 | 850 (when (memq (car head) eshell-deferrable-commands) |
851 (ignore | |
852 (setcar head | |
853 (intern-soft | |
854 (concat (symbol-name (car head)) "*")))))) | |
31241 | 855 ;; The last process in the pipe should get its handles |
856 ;; redirected as we found them before running the pipe. | |
857 ,(if (null (cdr pipeline)) | |
858 `(progn | |
859 (set 'eshell-current-handles tail-handles) | |
860 (set 'eshell-in-pipeline-p nil))) | |
861 (set 'result ,(car pipeline)) | |
862 ;; tailproc gets the result of the last successful process in | |
863 ;; the pipeline. | |
864 (set 'tailproc (or result tailproc)) | |
865 ,(if (cdr pipeline) | |
866 `(eshell-do-pipelines-synchronously (quote ,(cdr pipeline)))) | |
867 result)))) | |
29873 | 868 |
869 (defalias 'eshell-process-identity 'identity) | |
870 | |
871 (defmacro eshell-execute-pipeline (pipeline) | |
872 "Execute the commands in PIPELINE, connecting each to one another." | |
873 `(let ((eshell-in-pipeline-p t) tailproc) | |
874 (progn | |
31241 | 875 ,(if (fboundp 'start-process) |
876 `(eshell-do-pipelines ,pipeline) | |
877 `(let ((tail-handles (eshell-create-handles | |
878 (car (aref eshell-current-handles | |
879 ,eshell-output-handle)) nil | |
880 (car (aref eshell-current-handles | |
881 ,eshell-error-handle)) nil))) | |
882 (eshell-do-pipelines-synchronously ,pipeline))) | |
29873 | 883 (eshell-process-identity tailproc)))) |
884 | |
885 (defmacro eshell-as-subcommand (command) | |
886 "Execute COMMAND using a temp buffer. | |
887 This is used so that certain Lisp commands, such as `cd', when | |
888 executed in a subshell, do not disturb the environment of the main | |
889 Eshell buffer." | |
890 `(let ,eshell-subcommand-bindings | |
891 ,command)) | |
892 | |
893 (defmacro eshell-do-command-to-value (object) | |
894 "Run a subcommand prepared by `eshell-command-to-value'. | |
895 This avoids the need to use `let*'." | |
896 `(let ((eshell-current-handles | |
897 (eshell-create-handles value 'overwrite))) | |
898 (progn | |
899 ,object | |
900 (symbol-value value)))) | |
901 | |
902 (defmacro eshell-command-to-value (object) | |
903 "Run OBJECT synchronously, returning its result as a string. | |
904 Returns a string comprising the output from the command." | |
905 `(let ((value (make-symbol "eshell-temp"))) | |
906 (eshell-do-command-to-value ,object))) | |
907 | |
908 ;;;_* Iterative evaluation | |
909 ;; | |
910 ;; Eshell runs all of its external commands asynchronously, so that | |
911 ;; Emacs is not blocked while the operation is being performed. | |
912 ;; However, this introduces certain synchronization difficulties, | |
913 ;; since the Lisp code, once it returns, will not "go back" to finish | |
914 ;; executing the commands which haven't yet been started. | |
915 ;; | |
916 ;; What Eshell does to work around this problem (basically, the lack | |
917 ;; of threads in Lisp), is that it evaluates the command sequence | |
918 ;; iteratively. Whenever an asynchronous process is begun, evaluation | |
919 ;; terminates and control is given back to Emacs. When that process | |
920 ;; finishes, it will resume the evaluation using the remainder of the | |
921 ;; command tree. | |
922 | |
923 (defun eshell/eshell-debug (&rest args) | |
924 "A command for toggling certain debug variables." | |
925 (ignore | |
926 (cond | |
927 ((not args) | |
928 (if eshell-handle-errors | |
929 (eshell-print "errors\n")) | |
930 (if eshell-debug-command | |
931 (eshell-print "commands\n"))) | |
932 ((or (string= (car args) "-h") | |
933 (string= (car args) "--help")) | |
934 (eshell-print "usage: eshell-debug [kinds] | |
935 | |
936 This command is used to aid in debugging problems related to Eshell | |
937 itself. It is not useful for anything else. The recognized `kinds' | |
938 at the moment are: | |
939 | |
940 errors stops Eshell from trapping errors | |
941 commands shows command execution progress in `*eshell last cmd*' | |
942 ")) | |
943 (t | |
944 (while args | |
945 (cond | |
946 ((string= (car args) "errors") | |
947 (setq eshell-handle-errors (not eshell-handle-errors))) | |
948 ((string= (car args) "commands") | |
949 (setq eshell-debug-command (not eshell-debug-command)))) | |
950 (setq args (cdr args))))))) | |
951 | |
952 (defun pcomplete/eshell-mode/eshell-debug () | |
953 "Completion for the `debug' command." | |
954 (while (pcomplete-here '("errors" "commands")))) | |
955 | |
956 (defun eshell-debug-command (tag subform) | |
957 "Output a debugging message to '*eshell last cmd*'." | |
958 (let ((buf (get-buffer-create "*eshell last cmd*")) | |
959 (text (eshell-stringify eshell-current-command))) | |
960 (save-excursion | |
961 (set-buffer buf) | |
962 (if (not tag) | |
963 (erase-buffer) | |
964 (insert "\n\C-l\n" tag "\n\n" text | |
965 (if subform | |
966 (concat "\n\n" (eshell-stringify subform)) "")))))) | |
967 | |
33020 | 968 (defun eshell-invoke-directly (command input) |
969 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name) | |
970 (if (and (eq (car base) 'eshell-trap-errors) | |
971 (eq (car (cadr base)) 'eshell-named-command)) | |
972 (setq name (cadr (cadr base)))) | |
973 (and name (stringp name) | |
974 (not (member name eshell-complex-commands)) | |
975 (catch 'simple | |
976 (progn | |
977 (eshell-for pred eshell-complex-commands | |
978 (if (and (functionp pred) | |
979 (funcall pred name)) | |
980 (throw 'simple nil))) | |
981 t)) | |
982 (fboundp (intern-soft (concat "eshell/" name)))))) | |
983 | |
29873 | 984 (defun eshell-eval-command (command &optional input) |
985 "Evaluate the given COMMAND iteratively." | |
986 (if eshell-current-command | |
987 ;; we can just stick the new command at the end of the current | |
988 ;; one, and everything will happen as it should | |
989 (setcdr (last (cdr eshell-current-command)) | |
990 (list (list 'let '((here (and (eobp) (point)))) | |
991 (and input | |
992 (list 'insert-and-inherit | |
993 (concat input "\n"))) | |
994 '(if here | |
995 (eshell-update-markers here)) | |
996 (list 'eshell-do-eval | |
997 (list 'quote command))))) | |
998 (and eshell-debug-command | |
999 (save-excursion | |
1000 (let ((buf (get-buffer-create "*eshell last cmd*"))) | |
1001 (set-buffer buf) | |
1002 (erase-buffer) | |
1003 (insert "command: \"" input "\"\n")))) | |
1004 (setq eshell-current-command command) | |
31241 | 1005 (let ((delim (catch 'eshell-incomplete |
1006 (eshell-resume-eval)))) | |
42971
a4e7fd8ad209
(eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents:
38414
diff
changeset
|
1007 ;; On systems that don't support async subprocesses, eshell-resume |
a4e7fd8ad209
(eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents:
38414
diff
changeset
|
1008 ;; can return t. Don't treat that as an error. |
62789
74e26c83386f
(eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents:
59121
diff
changeset
|
1009 (if (listp delim) |
74e26c83386f
(eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents:
59121
diff
changeset
|
1010 (setq delim (car delim))) |
42971
a4e7fd8ad209
(eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents:
38414
diff
changeset
|
1011 (if (and delim (not (eq delim t))) |
62789
74e26c83386f
(eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents:
59121
diff
changeset
|
1012 (error "Unmatched delimiter: %c" delim))))) |
29873 | 1013 |
1014 (defun eshell-resume-command (proc status) | |
1015 "Resume the current command when a process ends." | |
1016 (when proc | |
31241 | 1017 (unless (or (not (stringp status)) |
1018 (string= "stopped" status) | |
29873 | 1019 (string-match eshell-reset-signals status)) |
1020 (if (eq proc (eshell-interactive-process)) | |
1021 (eshell-resume-eval))))) | |
1022 | |
1023 (defun eshell-resume-eval () | |
1024 "Destructively evaluate a form which may need to be deferred." | |
1025 (eshell-condition-case err | |
1026 (progn | |
1027 (setq eshell-last-async-proc nil) | |
1028 (when eshell-current-command | |
1029 (let* (retval | |
1030 (proc (catch 'eshell-defer | |
1031 (ignore | |
1032 (setq retval | |
1033 (eshell-do-eval | |
1034 eshell-current-command)))))) | |
31241 | 1035 (if (eshell-processp proc) |
29873 | 1036 (ignore (setq eshell-last-async-proc proc)) |
1037 (cadr retval))))) | |
1038 (error | |
1039 (error (error-message-string err))))) | |
1040 | |
1041 (defmacro eshell-manipulate (tag &rest commands) | |
1042 "Manipulate a COMMAND form, with TAG as a debug identifier." | |
1043 (if (not eshell-debug-command) | |
1044 `(progn ,@commands) | |
1045 `(progn | |
1046 (eshell-debug-command ,(eval tag) form) | |
1047 ,@commands | |
1048 (eshell-debug-command ,(concat "done " (eval tag)) form)))) | |
1049 | |
1050 (put 'eshell-manipulate 'lisp-indent-function 1) | |
1051 | |
1052 ;; eshell-lookup-function, eshell-functionp, and eshell-macrop taken | |
1053 ;; from edebug | |
1054 | |
1055 (defsubst eshell-lookup-function (object) | |
1056 "Return the ultimate function definition of OBJECT." | |
1057 (while (and (symbolp object) (fboundp object)) | |
1058 (setq object (symbol-function object))) | |
1059 object) | |
1060 | |
1061 (defconst function-p-func | |
48211
e23f9344f37d
(function-p-func): Avoid `xemacs-p'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43335
diff
changeset
|
1062 (if (fboundp 'compiled-function-p) |
29873 | 1063 'compiled-function-p |
1064 'byte-code-function-p)) | |
1065 | |
1066 (defsubst eshell-functionp (object) | |
1067 "Returns the function named by OBJECT, or nil if it is not a function." | |
1068 (setq object (eshell-lookup-function object)) | |
1069 (if (or (subrp object) | |
1070 (funcall function-p-func object) | |
1071 (and (listp object) | |
1072 (eq (car object) 'lambda) | |
1073 (listp (car (cdr object))))) | |
1074 object)) | |
1075 | |
1076 (defsubst eshell-macrop (object) | |
1077 "Return t if OBJECT is a macro or nil otherwise." | |
1078 (setq object (eshell-lookup-function object)) | |
1079 (if (and (listp object) | |
1080 (eq 'macro (car object)) | |
1081 (eshell-functionp (cdr object))) | |
1082 t)) | |
1083 | |
1084 (defun eshell-do-eval (form &optional synchronous-p) | |
1085 "Evaluate form, simplifying it as we go. | |
1086 Unless SYNCHRONOUS-P is non-nil, throws `eshell-defer' if it needs to | |
1087 be finished later after the completion of an asynchronous subprocess." | |
1088 (cond | |
1089 ((not (listp form)) | |
1090 (list 'quote (eval form))) | |
1091 ((memq (car form) '(quote function)) | |
1092 form) | |
1093 (t | |
1094 ;; skip past the call to `eshell-do-eval' | |
1095 (when (eq (car form) 'eshell-do-eval) | |
1096 (setq form (cadr (cadr form)))) | |
1097 ;; expand any macros directly into the form. This is done so that | |
1098 ;; we can modify any `let' forms to evaluate only once. | |
1099 (if (eshell-macrop (car form)) | |
1100 (let ((exp (eshell-copy-tree (macroexpand form)))) | |
1101 (eshell-manipulate (format "expanding macro `%s'" | |
1102 (symbol-name (car form))) | |
1103 (setcar form (car exp)) | |
1104 (setcdr form (cdr exp))))) | |
1105 (let ((args (cdr form))) | |
1106 (cond | |
1107 ((eq (car form) 'while) | |
1108 ;; `eshell-copy-tree' is needed here so that the test argument | |
1109 ;; doesn't get modified and thus always yield the same result. | |
1110 (when (car eshell-command-body) | |
1111 (assert (not synchronous-p)) | |
1112 (eshell-do-eval (car eshell-command-body)) | |
31241 | 1113 (setcar eshell-command-body nil) |
1114 (setcar eshell-test-body nil)) | |
29873 | 1115 (unless (car eshell-test-body) |
1116 (setcar eshell-test-body (eshell-copy-tree (car args)))) | |
31241 | 1117 (while (cadr (eshell-do-eval (car eshell-test-body))) |
1118 (setcar eshell-command-body (eshell-copy-tree (cadr args))) | |
1119 (eshell-do-eval (car eshell-command-body) synchronous-p) | |
1120 (setcar eshell-command-body nil) | |
1121 (setcar eshell-test-body (eshell-copy-tree (car args)))) | |
29873 | 1122 (setcar eshell-command-body nil)) |
1123 ((eq (car form) 'if) | |
1124 ;; `eshell-copy-tree' is needed here so that the test argument | |
1125 ;; doesn't get modified and thus always yield the same result. | |
31241 | 1126 (if (car eshell-command-body) |
1127 (progn | |
1128 (assert (not synchronous-p)) | |
1129 (eshell-do-eval (car eshell-command-body))) | |
1130 (unless (car eshell-test-body) | |
1131 (setcar eshell-test-body (eshell-copy-tree (car args)))) | |
1132 (if (cadr (eshell-do-eval (car eshell-test-body))) | |
1133 (setcar eshell-command-body (eshell-copy-tree (cadr args))) | |
1134 (setcar eshell-command-body (eshell-copy-tree (car (cddr args))))) | |
1135 (eshell-do-eval (car eshell-command-body) synchronous-p)) | |
1136 (setcar eshell-command-body nil) | |
1137 (setcar eshell-test-body nil)) | |
29873 | 1138 ((eq (car form) 'setcar) |
1139 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p)) | |
1140 (eval form)) | |
1141 ((eq (car form) 'setcdr) | |
1142 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p)) | |
1143 (eval form)) | |
1144 ((memq (car form) '(let catch condition-case unwind-protect)) | |
1145 ;; `let', `condition-case' and `unwind-protect' have to be | |
1146 ;; handled specially, because we only want to call | |
1147 ;; `eshell-do-eval' on their first form. | |
1148 ;; | |
1149 ;; NOTE: This requires obedience by all forms which this | |
1150 ;; function might encounter, that they do not contain | |
1151 ;; other special forms. | |
1152 (if (and (eq (car form) 'let) | |
1153 (not (eq (car (cadr args)) 'eshell-do-eval))) | |
1154 (eshell-manipulate "evaluating let args" | |
1155 (eshell-for letarg (car args) | |
1156 (if (and (listp letarg) | |
1157 (not (eq (cadr letarg) 'quote))) | |
1158 (setcdr letarg | |
1159 (list (eshell-do-eval | |
1160 (cadr letarg) synchronous-p))))))) | |
1161 (unless (eq (car form) 'unwind-protect) | |
1162 (setq args (cdr args))) | |
1163 (unless (eq (caar args) 'eshell-do-eval) | |
1164 (eshell-manipulate "handling special form" | |
1165 (setcar args (list 'eshell-do-eval | |
1166 (list 'quote (car args)) | |
1167 synchronous-p)))) | |
1168 (eval form)) | |
1169 (t | |
1170 (if (and args (not (memq (car form) '(run-hooks)))) | |
1171 (eshell-manipulate | |
1172 (format "evaluating arguments to `%s'" | |
1173 (symbol-name (car form))) | |
1174 (while args | |
1175 (setcar args (eshell-do-eval (car args) synchronous-p)) | |
1176 (setq args (cdr args))))) | |
1177 (cond | |
1178 ((eq (car form) 'progn) | |
1179 (car (last form))) | |
1180 ((eq (car form) 'prog1) | |
1181 (cadr form)) | |
1182 (t | |
33020 | 1183 ;; If a command desire to replace its execution form with |
1184 ;; another command form, all it needs to do is throw the new | |
1185 ;; form using the exception tag `eshell-replace-command'. | |
1186 ;; For example, let's say that the form currently being | |
1187 ;; eval'd is: | |
1188 ;; | |
1189 ;; (eshell-named-command "hello") | |
1190 ;; | |
1191 ;; Now, let's assume the 'hello' command is an Eshell alias, | |
1192 ;; the definition of which yields the command: | |
1193 ;; | |
1194 ;; (eshell-named-command "echo" (list "Hello" "world")) | |
1195 ;; | |
1196 ;; What the alias code would like to do is simply substitute | |
1197 ;; the alias form for the original form. To accomplish | |
1198 ;; this, all it needs to do is to throw the substitution | |
1199 ;; form with the `eshell-replace-command' tag, and the form | |
1200 ;; will be replaced within the current command, and | |
1201 ;; execution will then resume (iteratively) as before. | |
1202 ;; Thus, aliases can even contain references to asynchronous | |
1203 ;; sub-commands, and things will still work out as they | |
1204 ;; should. | |
29873 | 1205 (let (result new-form) |
1206 (if (setq new-form | |
1207 (catch 'eshell-replace-command | |
1208 (ignore | |
1209 (setq result (eval form))))) | |
1210 (progn | |
1211 (eshell-manipulate "substituting replacement form" | |
1212 (setcar form (car new-form)) | |
1213 (setcdr form (cdr new-form))) | |
1214 (eshell-do-eval form synchronous-p)) | |
1215 (if (and (memq (car form) eshell-deferrable-commands) | |
1216 (not eshell-current-subjob-p) | |
1217 result | |
31241 | 1218 (eshell-processp result)) |
29873 | 1219 (if synchronous-p |
1220 (eshell/wait result) | |
1221 (eshell-manipulate "inserting ignore form" | |
1222 (setcar form 'ignore) | |
1223 (setcdr form nil)) | |
1224 (throw 'eshell-defer result)) | |
1225 (list 'quote result)))))))))))) | |
1226 | |
1227 ;; command invocation | |
1228 | |
1229 (defun eshell/which (command &rest names) | |
1230 "Identify the COMMAND, and where it is located." | |
1231 (eshell-for name (cons command names) | |
1232 (let (program alias direct) | |
37817
431f430082e9
(eshell/which): Use `eshell-explicit-command-char' instead of ?*.
John Wiegley <johnw@newartisans.com>
parents:
37665
diff
changeset
|
1233 (if (eq (aref name 0) eshell-explicit-command-char) |
29873 | 1234 (setq name (substring name 1) |
1235 direct t)) | |
1236 (if (and (not direct) | |
1237 (eshell-using-module 'eshell-alias) | |
1238 (setq alias | |
1239 (funcall (symbol-function 'eshell-lookup-alias) | |
1240 name))) | |
1241 (setq program | |
1242 (concat name " is an alias, defined as \"" | |
1243 (cadr alias) "\""))) | |
1244 (unless program | |
1245 (setq program (eshell-search-path name)) | |
1246 (let* ((esym (eshell-find-alias-function name)) | |
1247 (sym (or esym (intern-soft name)))) | |
55968
db23082093f5
2004-06-06 Emilio C. Lopes <eclig@gmx.net>
John Wiegley <johnw@newartisans.com>
parents:
54568
diff
changeset
|
1248 (if (and (or esym (and sym (fboundp sym))) |
db23082093f5
2004-06-06 Emilio C. Lopes <eclig@gmx.net>
John Wiegley <johnw@newartisans.com>
parents:
54568
diff
changeset
|
1249 (or eshell-prefer-lisp-functions (not direct))) |
29873 | 1250 (let ((desc (let ((inhibit-redisplay t)) |
1251 (save-window-excursion | |
1252 (prog1 | |
1253 (describe-function sym) | |
1254 (message nil)))))) | |
1255 (setq desc (substring desc 0 | |
1256 (1- (or (string-match "\n" desc) | |
1257 (length desc))))) | |
31241 | 1258 (if (buffer-live-p (get-buffer "*Help*")) |
1259 (kill-buffer "*Help*")) | |
29873 | 1260 (setq program (or desc name)))))) |
1261 (if (not program) | |
1262 (eshell-error (format "which: no %s in (%s)\n" | |
1263 name (getenv "PATH"))) | |
1264 (eshell-printn program))))) | |
1265 | |
37662
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1266 (put 'eshell/which 'eshell-no-numeric-conversions t) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1267 |
29873 | 1268 (defun eshell-named-command (command &optional args) |
1269 "Insert output from a plain COMMAND, using ARGS. | |
1270 COMMAND may result in an alias being executed, or a plain command." | |
1271 (setq eshell-last-arguments args | |
1272 eshell-last-command-name (eshell-stringify command)) | |
1273 (run-hook-with-args 'eshell-prepare-command-hook) | |
1274 (assert (stringp eshell-last-command-name)) | |
1275 (if eshell-last-command-name | |
1276 (or (run-hook-with-args-until-success | |
1277 'eshell-named-command-hook eshell-last-command-name | |
1278 eshell-last-arguments) | |
1279 (eshell-plain-command eshell-last-command-name | |
1280 eshell-last-arguments)))) | |
1281 | |
1282 (defalias 'eshell-named-command* 'eshell-named-command) | |
1283 | |
1284 (defun eshell-find-alias-function (name) | |
1285 "Check whether a function called `eshell/NAME' exists." | |
1286 (let* ((sym (intern-soft (concat "eshell/" name))) | |
59121
7b2031432b63
(eshell-find-alias-function): Call symbol-file with `defun'.
Richard M. Stallman <rms@gnu.org>
parents:
55968
diff
changeset
|
1287 (file (symbol-file sym 'defun))) |
37442
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1288 ;; If the function exists, but is defined in an eshell module |
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1289 ;; that's not currently enabled, don't report it as found |
29873 | 1290 (if (and file |
1291 (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file)) | |
37442
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1292 (let ((module-sym |
29873 | 1293 (intern (file-name-sans-extension |
37442
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1294 (file-name-nondirectory |
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1295 (concat "eshell-" (match-string 2 file))))))) |
37450
b1c5785dbec5
(eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents:
37442
diff
changeset
|
1296 (if (and (functionp sym) |
b1c5785dbec5
(eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents:
37442
diff
changeset
|
1297 (or (null module-sym) |
b1c5785dbec5
(eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents:
37442
diff
changeset
|
1298 (eshell-using-module module-sym) |
b1c5785dbec5
(eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents:
37442
diff
changeset
|
1299 (memq module-sym (eshell-subgroups 'eshell)))) |
37442
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1300 sym)) |
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1301 ;; Otherwise, if it's bound, return it. |
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1302 (if (functionp sym) |
f4b209194d8c
(eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
1303 sym)))) |
29873 | 1304 |
1305 (defun eshell-plain-command (command args) | |
1306 "Insert output from a plain COMMAND, using ARGS. | |
1307 COMMAND may result in either a Lisp function being executed by name, | |
1308 or an external command." | |
1309 (let* ((esym (eshell-find-alias-function command)) | |
1310 (sym (or esym (intern-soft command)))) | |
1311 (if (and sym (fboundp sym) | |
1312 (or esym eshell-prefer-lisp-functions | |
1313 (not (eshell-search-path command)))) | |
1314 (eshell-lisp-command sym args) | |
1315 (eshell-external-command command args)))) | |
1316 | |
1317 (defun eshell-exec-lisp (printer errprint func-or-form args form-p) | |
1318 "Execute a lisp FUNC-OR-FORM, maybe passing ARGS. | |
1319 PRINTER and ERRPRINT are functions to use for printing regular | |
1320 messages, and errors. FORM-P should be non-nil if FUNC-OR-FORM | |
1321 represent a lisp form; ARGS will be ignored in that case." | |
1322 (let (result) | |
1323 (eshell-condition-case err | |
1324 (progn | |
1325 (setq result | |
1326 (save-current-buffer | |
1327 (if form-p | |
1328 (eval func-or-form) | |
1329 (apply func-or-form args)))) | |
1330 (and result (funcall printer result)) | |
1331 result) | |
1332 (error | |
1333 (let ((msg (error-message-string err))) | |
1334 (if (and (not form-p) | |
1335 (string-match "^Wrong number of arguments" msg) | |
1336 (fboundp 'eldoc-get-fnsym-args-string)) | |
1337 (let ((func-doc (eldoc-get-fnsym-args-string func-or-form))) | |
1338 (setq msg (format "usage: %s" func-doc)))) | |
1339 (funcall errprint msg)) | |
1340 nil)))) | |
1341 | |
1342 (defsubst eshell-apply* (printer errprint func args) | |
1343 "Call FUNC, with ARGS, trapping errors and return them as output. | |
1344 PRINTER and ERRPRINT are functions to use for printing regular | |
1345 messages, and errors." | |
1346 (eshell-exec-lisp printer errprint func args nil)) | |
1347 | |
1348 (defsubst eshell-funcall* (printer errprint func &rest args) | |
1349 "Call FUNC, with ARGS, trapping errors and return them as output." | |
1350 (eshell-apply* printer errprint func args)) | |
1351 | |
1352 (defsubst eshell-eval* (printer errprint form) | |
1353 "Evaluate FORM, trapping errors and returning them." | |
1354 (eshell-exec-lisp printer errprint form nil t)) | |
1355 | |
1356 (defsubst eshell-apply (func args) | |
1357 "Call FUNC, with ARGS, trapping errors and return them as output. | |
1358 PRINTER and ERRPRINT are functions to use for printing regular | |
1359 messages, and errors." | |
1360 (eshell-apply* 'eshell-print 'eshell-error func args)) | |
1361 | |
1362 (defsubst eshell-funcall (func &rest args) | |
1363 "Call FUNC, with ARGS, trapping errors and return them as output." | |
1364 (eshell-apply func args)) | |
1365 | |
1366 (defsubst eshell-eval (form) | |
1367 "Evaluate FORM, trapping errors and returning them." | |
1368 (eshell-eval* 'eshell-print 'eshell-error form)) | |
1369 | |
1370 (defsubst eshell-applyn (func args) | |
1371 "Call FUNC, with ARGS, trapping errors and return them as output. | |
1372 PRINTER and ERRPRINT are functions to use for printing regular | |
1373 messages, and errors." | |
1374 (eshell-apply* 'eshell-printn 'eshell-errorn func args)) | |
1375 | |
1376 (defsubst eshell-funcalln (func &rest args) | |
1377 "Call FUNC, with ARGS, trapping errors and return them as output." | |
1378 (eshell-applyn func args)) | |
1379 | |
1380 (defsubst eshell-evaln (form) | |
1381 "Evaluate FORM, trapping errors and returning them." | |
1382 (eshell-eval* 'eshell-printn 'eshell-errorn form)) | |
1383 | |
1384 (defun eshell-lisp-command (object &optional args) | |
1385 "Insert Lisp OBJECT, using ARGS if a function." | |
1386 (catch 'eshell-external ; deferred to an external command | |
1387 (let* ((eshell-ensure-newline-p (eshell-interactive-output-p)) | |
1388 (result | |
1389 (if (functionp object) | |
37662
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1390 (progn |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1391 (setq eshell-last-arguments args |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1392 eshell-last-command-name |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1393 (concat "#<function " (symbol-name object) ">")) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1394 ;; if any of the arguments are flagged as numbers |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1395 ;; waiting for conversion, convert them now |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1396 (unless (get object 'eshell-no-numeric-conversions) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1397 (while args |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1398 (let ((arg (car args))) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1399 (if (and (stringp arg) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1400 (> (length arg) 0) |
53051
bf3ee9e2ceda
(eshell-lisp-command): Do not late-convert string arguments to numbers
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
1401 (not (text-property-not-all |
bf3ee9e2ceda
(eshell-lisp-command): Do not late-convert string arguments to numbers
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
1402 0 (length arg) 'number t arg))) |
37665
ebd292552bfe
Fixed reference to free variable.
John Wiegley <johnw@newartisans.com>
parents:
37662
diff
changeset
|
1403 (setcar args (string-to-number arg)))) |
37662
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1404 (setq args (cdr args)))) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1405 (eshell-apply object eshell-last-arguments)) |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1406 (setq eshell-last-arguments args |
cb20d33bef50
(eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents:
37657
diff
changeset
|
1407 eshell-last-command-name "#<Lisp object>") |
29873 | 1408 (eshell-eval object)))) |
1409 (if (and eshell-ensure-newline-p | |
1410 (save-excursion | |
1411 (goto-char eshell-last-output-end) | |
1412 (not (bolp)))) | |
1413 (eshell-print "\n")) | |
1414 (eshell-close-handles 0 (list 'quote result))))) | |
1415 | |
1416 (defalias 'eshell-lisp-command* 'eshell-lisp-command) | |
1417 | |
52401 | 1418 ;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366 |
29873 | 1419 ;;; esh-cmd.el ends here |