1 ;;; esh-cmd.el --- command invocation
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;;;_* Invoking external commands
29 ;; External commands cause processes to be created, by loading
30 ;; external executables into memory. This is what most normal shells
31 ;; do, most of the time. For more information, see [External commands].
33 ;;;_* Invoking Lisp functions
35 ;; A Lisp function can be invoked using Lisp syntax, or command shell
36 ;; syntax. For example, to run `dired' to edit the current directory:
44 ;; The latter form is preferable, but the former is more precise,
45 ;; since it involves no translations. See [Argument parsing], to
46 ;; learn more about how arguments are transformed before passing them
49 ;; Ordinarily, if 'dired' were also available as an external command,
50 ;; the external version would be called in preference to any Lisp
51 ;; function of the same name. To change this behavior so that Lisp
52 ;; functions always take precedence, set
53 ;; `eshell-prefer-lisp-functions' to t.
57 ;; Whenever a command is specified using a simple name, such as 'ls',
58 ;; Eshell will first look for a Lisp function of the name `eshell/ls'.
59 ;; If it exists, it will be called in preference to any other command
60 ;; which might have matched the name 'ls' (such as command aliases,
61 ;; external commands, Lisp functions of that name, etc).
63 ;; This is the most flexible mechanism for creating new commands,
64 ;; since it does not pollute the global namespace, yet allows you to
65 ;; use all of Lisp's facilities to define that piece of functionality.
66 ;; Most of Eshell's "builtin" commands are defined as alias functions.
70 ;; It is possible to invoke a Lisp form as an argument. This can be
71 ;; done either by specifying the form as you might in Lisp, or by
72 ;; using the '$' character to introduce a value-interpolation:
80 ;; The two forms are equivalent. The second is required only if the
81 ;; form being interpolated is within a string, or is a subexpression
82 ;; of a larger argument:
84 ;; echo x$(+ 1 2) "String $(+ 1 2)"
86 ;; To pass a Lisp symbol as a argument, use the alternate quoting
87 ;; syntax, since the single quote character is far too overused in
92 ;; Backquote can also be used:
94 ;; echo `(list ,lisp-symbol)
96 ;; Lisp arguments are identified using the following regexp:
100 ;; There are several hooks involved with command execution, which can
101 ;; be used either to change or augment Eshell's behavior.
107 (unless (featurep 'xemacs
)
114 (require 'pcomplete
))
117 (defgroup eshell-cmd nil
118 "Executing an Eshell command is as simple as typing it in and
119 pressing <RET>. There are several different kinds of commands,
121 :tag
"Command invocation"
122 ;; :link '(info-link "(eshell)Command invocation")
125 (defcustom eshell-prefer-lisp-functions nil
126 "*If non-nil, prefer Lisp functions to external commands."
130 (defcustom eshell-lisp-regexp
"\\([(`]\\|#'\\)"
131 "*A regexp which, if matched at beginning of an argument, means Lisp.
132 Such arguments will be passed to `read', and then evaluated."
136 (defcustom eshell-pre-command-hook nil
137 "*A hook run before each interactive command is invoked."
141 (defcustom eshell-post-command-hook nil
142 "*A hook run after each interactive command is invoked."
146 (defcustom eshell-prepare-command-hook nil
147 "*A set of functions called to prepare a named command.
148 The command name and its argument are in `eshell-last-command-name'
149 and `eshell-last-arguments'. The functions on this hook can change
150 the value of these symbols if necessary.
152 To prevent a command from executing at all, set
153 `eshell-last-command-name' to nil."
157 (defcustom eshell-named-command-hook nil
158 "*A set of functions called before a named command is invoked.
159 Each function will be passed the command name and arguments that were
160 passed to `eshell-named-command'.
162 If any of the functions returns a non-nil value, the named command
163 will not be invoked, and that value will be returned from
164 `eshell-named-command'.
166 In order to substitute an alternate command form for execution, the
167 hook function should throw it using the tag `eshell-replace-command'.
170 (add-hook 'eshell-named-command-hook 'subst-with-cd)
171 (defun subst-with-cd (command args)
172 (throw 'eshell-replace-command
173 (eshell-parse-command \"cd\" args)))
175 Although useless, the above code will cause any non-glob, non-Lisp
176 command (i.e., 'ls' as opposed to '*ls' or '(ls)') to be replaced by a
177 call to `cd' using the arguments that were passed to the function."
181 (defcustom eshell-pre-rewrite-command-hook
182 '(eshell-no-command-conversion
183 eshell-subcommand-arg-values
)
184 "*A hook run before command rewriting begins.
185 The terms of the command to be rewritten is passed as arguments, and
186 may be modified in place. Any return value is ignored."
190 (defcustom eshell-rewrite-command-hook
191 '(eshell-rewrite-for-command
192 eshell-rewrite-while-command
193 eshell-rewrite-if-command
194 eshell-rewrite-sexp-command
195 eshell-rewrite-initial-subcommand
196 eshell-rewrite-named-command
)
197 "*A set of functions used to rewrite the command argument.
198 Once parsing of a command line is completed, the next step is to
199 rewrite the initial argument into something runnable.
201 A module may wish to associate special behavior with certain argument
202 syntaxes at the beginning of a command line. They are welcome to do
203 so by adding a function to this hook. The first function to return a
204 substitute command form is the one used. Each function is passed the
205 command's full argument list, which is a list of sexps (typically
210 (defcustom eshell-post-rewrite-command-hook nil
211 "*A hook run after command rewriting is finished.
212 Each function is passed the symbol containing the rewritten command,
213 which may be modified directly. Any return value is ignored."
217 (defcustom eshell-complex-commands
'("ls")
218 "*A list of commands names or functions, that determine complexity.
219 That is, if a command is defined by a function named eshell/NAME,
220 and NAME is part of this list, it is invoked as a complex command.
221 Complex commands are always correct, but run much slower. If a
222 command works fine without being part of this list, then it doesn't
225 If an entry is a function, it will be called with the name, and should
226 return non-nil if the command is complex."
227 :type
'(repeat :tag
"Commands"
228 (choice (string :tag
"Name")
229 (function :tag
"Predicate")))
234 (defcustom eshell-cmd-load-hook
'(eshell-cmd-initialize)
235 "*A hook that gets run when `eshell-cmd' is loaded."
239 (defcustom eshell-debug-command nil
240 "*If non-nil, enable debugging code. SSLLOOWW.
241 This option is only useful for reporting bugs. If you enable it, you
242 will have to visit the file 'eshell-cmd.el' and run the command
247 (defcustom eshell-deferrable-commands
248 '(eshell-named-command
250 eshell-process-identity
)
251 "*A list of functions which might return an ansychronous process.
252 If they return a process object, execution of the calling Eshell
253 command will wait for completion (in the background) before finishing
255 :type
'(repeat function
)
258 (defcustom eshell-subcommand-bindings
259 '((eshell-in-subcommand-p t
)
260 (default-directory default-directory
)
261 (process-environment (eshell-copy-environment)))
262 "*A list of `let' bindings for subcommand environments."
266 (put 'risky-local-variable
'eshell-subcommand-bindings t
)
268 (defvar eshell-ensure-newline-p nil
269 "If non-nil, ensure that a newline is emitted after a Lisp form.
270 This can be changed by Lisp forms that are evaluated from the Eshell
273 ;;; Internal Variables:
275 (defvar eshell-current-command nil
)
276 (defvar eshell-command-name nil
)
277 (defvar eshell-command-arguments nil
)
278 (defvar eshell-in-pipeline-p nil
)
279 (defvar eshell-in-subcommand-p nil
)
280 (defvar eshell-last-arguments nil
)
281 (defvar eshell-last-command-name nil
)
282 (defvar eshell-last-async-proc nil
283 "When this foreground process completes, resume command evaluation.")
287 (defsubst eshell-interactive-process
()
288 "Return currently running command process, if non-Lisp."
289 eshell-last-async-proc
)
291 (defun eshell-cmd-initialize ()
292 "Initialize the Eshell command processing module."
293 (set (make-local-variable 'eshell-current-command
) nil
)
294 (set (make-local-variable 'eshell-command-name
) nil
)
295 (set (make-local-variable 'eshell-command-arguments
) nil
)
296 (set (make-local-variable 'eshell-last-arguments
) nil
)
297 (set (make-local-variable 'eshell-last-command-name
) nil
)
298 (set (make-local-variable 'eshell-last-async-proc
) nil
)
300 (add-hook 'eshell-kill-hook
'eshell-resume-command nil t
)
302 ;; make sure that if a command is over, and no process is being
303 ;; waited for, that `eshell-current-command' is set to nil. This
304 ;; situation can occur, for example, if a Lisp function results in
305 ;; `debug' being called, and the user then types \\[top-level]
306 (add-hook 'eshell-post-command-hook
309 (setq eshell-current-command nil
310 eshell-last-async-proc nil
))) nil t
)
312 (add-hook 'eshell-parse-argument-hook
313 'eshell-parse-subcommand-argument nil t
)
314 (add-hook 'eshell-parse-argument-hook
315 'eshell-parse-lisp-argument nil t
)
317 (when (eshell-using-module 'eshell-cmpl
)
318 (add-hook 'pcomplete-try-first-hook
319 'eshell-complete-lisp-symbols nil t
)))
321 (eshell-deftest var last-result-var
322 "\"last result\" variable"
323 (eshell-command-result-p "+ 1 2; + $$ 2" "3\n5\n"))
325 (eshell-deftest var last-result-var2
326 "\"last result\" variable"
327 (eshell-command-result-p "+ 1 2; + $$ $$" "3\n6\n"))
329 (eshell-deftest var last-arg-var
330 "\"last arg\" variable"
331 (eshell-command-result-p "+ 1 2; + $_ 4" "3\n6\n"))
333 (defun eshell-complete-lisp-symbols ()
334 "If there is a user reference, complete it."
335 (let ((arg (pcomplete-actual-arg)))
336 (when (string-match (concat "\\`" eshell-lisp-regexp
) arg
)
337 (setq pcomplete-stub
(substring arg
(match-end 0))
338 pcomplete-last-completion-raw t
)
339 (throw 'pcomplete-completions
340 (all-completions pcomplete-stub obarray
'boundp
)))))
344 (defun eshell-parse-command (command &optional args top-level
)
345 "Parse the COMMAND, adding ARGS if given.
346 COMMAND can either be a string, or a cons cell demarcating a buffer
347 region. TOP-LEVEL, if non-nil, means that the outermost command (the
348 user's input command) is being parsed, and that pre and post command
349 hooks should be run before and after the command."
354 (eshell-parse-arguments (car command
) (cdr command
))
356 (inhibit-point-motion-hooks t
)
357 after-change-functions
)
360 (eshell-parse-arguments here
(point))
361 (delete-region here
(point)))))
367 (if (or (not (car sep-terms
))
368 (string= (car sep-terms
) ";"))
370 (eshell-parse-pipeline cmd
(not (car sep-terms
))))
372 (list 'eshell-do-subjob
373 (list 'list
(eshell-parse-pipeline cmd
)))))
374 (setq sep-terms
(cdr sep-terms
))
375 (if eshell-in-pipeline-p
377 (list 'eshell-trap-errors cmd
))))
378 (eshell-separate-commands terms
"[&;]" nil
'sep-terms
))))
379 (let ((cmd commands
))
382 (setcar cmd
(list 'eshell-commands
(car cmd
))))
383 (setq cmd
(cdr cmd
))))
385 (append (list 'progn
)
387 (list '(run-hooks 'eshell-pre-command-hook
)))
391 (list 'catch
(quote 'top-level
)
392 (append (list 'progn
) commands
))
393 '(run-hooks 'eshell-post-command-hook
)))))
395 (list 'eshell-commands commands
)
398 (defun eshell-debug-command (tag subform
)
399 "Output a debugging message to '*eshell last cmd*'."
400 (let ((buf (get-buffer-create "*eshell last cmd*"))
401 (text (eshell-stringify eshell-current-command
)))
406 (insert "\n\C-l\n" tag
"\n\n" text
408 (concat "\n\n" (eshell-stringify subform
)) ""))))))
410 (defun eshell-debug-show-parsed-args (terms)
411 "Display parsed arguments in the debug buffer."
413 (if eshell-debug-command
414 (eshell-debug-command "parsed arguments" terms
))))
416 (defun eshell-no-command-conversion (terms)
417 "Don't convert the command argument."
419 (if (and (listp (car terms
))
420 (eq (caar terms
) 'eshell-convert
))
421 (setcar terms
(cadr (car terms
))))))
423 (defun eshell-subcommand-arg-values (terms)
424 "Convert subcommand arguments {x} to ${x}, in order to take their values."
425 (setq terms
(cdr terms
)) ; skip command argument
427 (if (and (listp (car terms
))
428 (eq (caar terms
) 'eshell-as-subcommand
))
429 (setcar terms
(list 'eshell-convert
430 (list 'eshell-command-to-value
432 (setq terms
(cdr terms
))))
434 (defun eshell-rewrite-sexp-command (terms)
435 "Rewrite a sexp in initial position, such as '(+ 1 2)'."
436 ;; this occurs when a Lisp expression is in first position
437 (if (and (listp (car terms
))
438 (eq (caar terms
) 'eshell-command-to-value
))
441 (eshell-deftest cmd lisp-command
442 "Evaluate Lisp command"
443 (eshell-command-result-p "(+ 1 2)" "3"))
445 (eshell-deftest cmd lisp-command-args
446 "Evaluate Lisp command (ignore args)"
447 (eshell-command-result-p "(+ 1 2) 3" "3"))
449 (defun eshell-rewrite-initial-subcommand (terms)
450 "Rewrite a subcommand in initial position, such as '{+ 1 2}'."
451 (if (and (listp (car terms
))
452 (eq (caar terms
) 'eshell-as-subcommand
))
455 (eshell-deftest cmd subcommand
457 (eshell-command-result-p "{+ 1 2}" "3\n"))
459 (eshell-deftest cmd subcommand-args
460 "Run subcommand (ignore args)"
461 (eshell-command-result-p "{+ 1 2} 3" "3\n"))
463 (eshell-deftest cmd subcommand-lisp
464 "Run subcommand + Lisp form"
465 (eshell-command-result-p "{(+ 1 2)}" "3\n"))
467 (defun eshell-rewrite-named-command (terms)
468 "If no other rewriting rule transforms TERMS, assume a named command."
469 (let ((sym (if eshell-in-pipeline-p
470 'eshell-named-command
*
471 'eshell-named-command
))
475 (list sym cmd
(append (list 'list
) (cdr terms
)))
478 (eshell-deftest cmd named-command
479 "Execute named command"
480 (eshell-command-result-p "+ 1 2" "3\n"))
483 (defvar eshell-command-body
)
484 (defvar eshell-test-body
))
486 (defsubst eshell-invokify-arg
(arg &optional share-output silent
)
487 "Change ARG so it can be invoked from a structured command.
489 SHARE-OUTPUT, if non-nil, means this invocation should share the
490 current output stream, which is separately redirectable. SILENT
491 means the user and/or any redirections shouldn't see any output
492 from this command. If both SHARE-OUTPUT and SILENT are non-nil,
493 the second is ignored."
494 ;; something that begins with `eshell-convert' means that it
495 ;; intends to return a Lisp value. We want to get past this,
496 ;; but if it's not _actually_ a value interpolation -- in which
497 ;; we leave it alone. In fact, the only time we muck with it
498 ;; is in the case of a {subcommand} that has been turned into
499 ;; the interpolation, ${subcommand}, by the parser because it
500 ;; didn't know better.
502 (eq (car arg
) 'eshell-convert
)
503 (eq (car (cadr arg
)) 'eshell-command-to-value
))
506 (list 'eshell-commands
(cadr (cadr arg
))
510 (defun eshell-rewrite-for-command (terms)
511 "Rewrite a `for' command into its equivalent Eshell command form.
512 Because the implementation of `for' relies upon conditional evaluation
513 of its argument (i.e., use of a Lisp special form), it must be
514 implemented via rewriting, rather than as a function."
515 (if (and (stringp (car terms
))
516 (string= (car terms
) "for")
517 (stringp (nth 2 terms
))
518 (string= (nth 2 terms
) "in"))
519 (let ((body (car (last terms
))))
520 (setcdr (last terms
2) nil
)
522 'let
(list (list 'for-items
531 (cdr (cddr terms
)))))
532 (list 'eshell-command-body
533 (list 'quote
(list nil
)))
534 (list 'eshell-test-body
535 (list 'quote
(list nil
))))
539 'while
(list 'car
(list 'symbol-value
540 (list 'quote
'for-items
)))
544 (list (list (intern (cadr terms
))
547 (list 'quote
'for-items
)))))
548 (list 'eshell-protect
549 (eshell-invokify-arg body t
)))
550 (list 'setcar
'for-items
553 (list 'quote
'for-items
))))
554 (list 'setcdr
'for-items
557 (list 'quote
'for-items
))))))
558 (list 'eshell-close-handles
559 'eshell-last-command-status
560 (list 'list
(quote 'quote
)
561 'eshell-last-command-result
)))))))
563 (defun eshell-structure-basic-command (func names keyword test body
564 &optional else vocal-test
)
565 "With TERMS, KEYWORD, and two NAMES, structure a basic command.
566 The first of NAMES should be the positive form, and the second the
567 negative. It's not likely that users should ever need to call this
570 If VOCAL-TEST is non-nil, it means output from the test should be
571 shown, as well as output from the body."
572 ;; If the test form begins with `eshell-convert', it means
573 ;; something data-wise will be returned, and we should let
574 ;; that determine the truth of the statement.
575 (unless (eq (car test
) 'eshell-convert
)
578 (list 'eshell-exit-success-p
))))
580 ;; should we reverse the sense of the test? This depends
581 ;; on the `names' parameter. If it's the symbol nil, yes.
582 ;; Otherwise, it can be a pair of strings; if the keyword
583 ;; we're using matches the second member of that pair (a
584 ;; list), we should reverse it.
585 (if (or (eq names nil
)
587 (string= keyword
(cadr names
))))
588 (setq test
(list 'not test
)))
590 ;; finally, create the form that represents this structured
593 'let
(list (list 'eshell-command-body
594 (list 'quote
(list nil
)))
595 (list 'eshell-test-body
596 (list 'quote
(list nil
))))
597 (list func test body else
)
598 (list 'eshell-close-handles
599 'eshell-last-command-status
600 (list 'list
(quote 'quote
)
601 'eshell-last-command-result
))))
603 (defun eshell-rewrite-while-command (terms)
604 "Rewrite a `while' command into its equivalent Eshell command form.
605 Because the implementation of `while' relies upon conditional
606 evaluation of its argument (i.e., use of a Lisp special form), it
607 must be implemented via rewriting, rather than as a function."
608 (if (and (stringp (car terms
))
609 (member (car terms
) '("while" "until")))
610 (eshell-structure-basic-command
611 'while
'("while" "until") (car terms
)
612 (eshell-invokify-arg (cadr terms
) nil t
)
613 (list 'eshell-protect
614 (eshell-invokify-arg (car (last terms
)) t
)))))
616 (defun eshell-rewrite-if-command (terms)
617 "Rewrite an `if' command into its equivalent Eshell command form.
618 Because the implementation of `if' relies upon conditional
619 evaluation of its argument (i.e., use of a Lisp special form), it
620 must be implemented via rewriting, rather than as a function."
621 (if (and (stringp (car terms
))
622 (member (car terms
) '("if" "unless")))
623 (eshell-structure-basic-command
624 'if
'("if" "unless") (car terms
)
625 (eshell-invokify-arg (cadr terms
) nil t
)
626 (list 'eshell-protect
628 (if (= (length terms
) 4)
630 (car (last terms
))) t
))
631 (if (= (length terms
) 4)
632 (list 'eshell-protect
634 (car (last terms
)))) t
))))
636 (defun eshell-exit-success-p ()
637 "Return non-nil if the last command was \"successful\".
638 For a bit of Lisp code, this means a return value of non-nil.
639 For an external command, it means an exit code of 0."
641 (string-match "#<\\(Lisp object\\|function .*\\)>"
642 eshell-last-command-name
))
643 eshell-last-command-result
644 (= eshell-last-command-status
0)))
646 (defun eshell-parse-pipeline (terms &optional final-p
)
647 "Parse a pipeline from TERMS, return the appropriate Lisp forms."
649 (bigpieces (eshell-separate-commands terms
"\\(&&\\|||\\)"
655 (let ((subterms (car bp
)))
656 (let* ((pieces (eshell-separate-commands subterms
"|"))
660 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd
)
661 (setq cmd
(run-hook-with-args-until-success
662 'eshell-rewrite-command-hook cmd
))
663 (run-hook-with-args 'eshell-post-rewrite-command-hook
'cmd
)
668 (if (<= (length pieces
) 1)
670 (assert (not eshell-in-pipeline-p
))
671 (list 'eshell-execute-pipeline
672 (list 'quote pieces
))))))
674 ;; `results' might be empty; this happens in the case of
676 (setq results
(cdr results
)
677 results
(nreverse results
)
679 results
(cdr results
)
680 sep-terms
(nreverse sep-terms
))
682 (assert (car sep-terms
))
683 (setq final
(eshell-structure-basic-command
684 'if
(string= (car sep-terms
) "&&") "if"
685 (list 'eshell-protect
(car results
))
686 (list 'eshell-protect final
)
688 results
(cdr results
)
689 sep-terms
(cdr sep-terms
)))
692 (defun eshell-parse-subcommand-argument ()
693 "Parse a subcommand argument of the form '{command}'."
694 (if (and (not eshell-current-argument
)
695 (not eshell-current-quoted
)
696 (eq (char-after) ?\
{)
697 (or (= (point-max) (1+ (point)))
698 (not (eq (char-after (1+ (point))) ?\
}))))
699 (let ((end (eshell-find-delimiter ?\
{ ?\
})))
701 (throw 'eshell-incomplete ?\
{)
702 (when (eshell-arg-delimiter (1+ end
))
704 (list 'eshell-as-subcommand
705 (eshell-parse-command (cons (1+ (point)) end
)))
706 (goto-char (1+ end
))))))))
708 (defun eshell-parse-lisp-argument ()
709 "Parse a Lisp expression which is specified as an argument."
710 (if (and (not eshell-current-argument
)
711 (not eshell-current-quoted
)
712 (looking-at eshell-lisp-regexp
))
713 (let* ((here (point))
716 (read (current-buffer))
718 (throw 'eshell-incomplete ?\
()))))
719 (if (eshell-arg-delimiter)
720 (list 'eshell-command-to-value
721 (list 'eshell-lisp-command
(list 'quote obj
)))
722 (ignore (goto-char here
))))))
724 (defun eshell-separate-commands (terms separator
&optional
725 reversed last-terms-sym
)
726 "Separate TERMS using SEPARATOR.
727 If REVERSED is non-nil, the list of separated term groups will be
728 returned in reverse order. If LAST-TERMS-SYM is a symbol, its value
729 will be set to a list of all the separator operators found (or '(list
731 (let ((sub-terms (list t
))
732 (eshell-sep-terms (list t
))
735 (if (and (consp (car terms
))
736 (eq (caar terms
) 'eshell-operator
)
737 (string-match (concat "^" separator
"$")
738 (nth 1 (car terms
))))
740 (nconc eshell-sep-terms
(list (nth 1 (car terms
))))
741 (setq subchains
(cons (cdr sub-terms
) subchains
)
743 (nconc sub-terms
(list (car terms
))))
744 (setq terms
(cdr terms
)))
745 (if (> (length sub-terms
) 1)
746 (setq subchains
(cons (cdr sub-terms
) subchains
)))
750 (set last-terms-sym
(reverse (cdr eshell-sep-terms
))))
751 subchains
) ; already reversed
753 (set last-terms-sym
(cdr eshell-sep-terms
)))
754 (nreverse subchains
))))
756 ;;_* Command evaluation macros
758 ;; The structure of the following macros is very important to
759 ;; `eshell-do-eval' [Iterative evaluation]:
761 ;; @ Don't use forms that conditionally evaluate their arguments, such
762 ;; as `setq', `if', `while', `let*', etc. The only special forms
763 ;; that can be used are `let', `condition-case' and
766 ;; @ The main body of a `let' can contain only one form. Use `progn'
769 ;; @ The two `special' variables are `eshell-current-handles' and
770 ;; `eshell-current-subjob-p'. Bind them locally with a `let' if you
771 ;; need to change them. Change them directly only if your intention
772 ;; is to change the calling environment.
774 (defmacro eshell-do-subjob
(object)
775 "Evaluate a command OBJECT as a subjob.
776 We indicate that the process was run in the background by returning it
777 ensconced in a list."
778 `(let ((eshell-current-subjob-p t
))
781 (defmacro eshell-commands
(object &optional silent
)
782 "Place a valid set of handles, and context, around command OBJECT."
783 `(let ((eshell-current-handles
784 (eshell-create-handles ,(not silent
) 'append
))
785 eshell-current-subjob-p
)
788 (defmacro eshell-trap-errors
(object)
789 "Trap any errors that occur, so they are not entirely fatal.
790 Also, the variable `eshell-this-command-hook' is available for the
791 duration of OBJECT's evaluation. Note that functions should be added
792 to this hook using `nconc', and *not* `add-hook'.
794 Someday, when Scheme will become the dominant Emacs language, all of
795 this grossness will be made to disappear by using `call/cc'..."
796 `(let ((eshell-this-command-hook (list 'ignore
)))
797 (eshell-condition-case err
800 (run-hooks 'eshell-this-command-hook
))
802 (run-hooks 'eshell-this-command-hook
)
803 (eshell-errorn (error-message-string err
))
804 (eshell-close-handles 1)))))
806 (defmacro eshell-copy-handles
(object)
807 "Duplicate current I/O handles, so OBJECT works with its own copy."
808 `(let ((eshell-current-handles
809 (eshell-create-handles
810 (car (aref eshell-current-handles
811 eshell-output-handle
)) nil
812 (car (aref eshell-current-handles
813 eshell-error-handle
)) nil
)))
816 (defmacro eshell-protect
(object)
817 "Protect I/O handles, so they aren't get closed after eval'ing OBJECT."
819 (eshell-protect-handles eshell-current-handles
)
822 (defmacro eshell-do-pipelines
(pipeline)
823 "Execute the commands in PIPELINE, connecting each to one another."
824 (when (setq pipeline
(cadr pipeline
))
825 `(eshell-copy-handles
827 ,(when (cdr pipeline
)
831 (eshell-do-pipelines (quote ,(cdr pipeline
))))
832 (eshell-set-output-handle ,eshell-output-handle
834 (eshell-set-output-handle ,eshell-error-handle
836 (set 'tailproc
(or tailproc nextproc
)))))
837 ,(let ((head (car pipeline
)))
838 (if (memq (car head
) '(let progn
))
839 (setq head
(car (last head
))))
840 (when (memq (car head
) eshell-deferrable-commands
)
844 (concat (symbol-name (car head
)) "*"))))))
847 (defmacro eshell-do-pipelines-synchronously
(pipeline)
848 "Execute the commands in PIPELINE in sequence synchronously.
849 Output of each command is passed as input to the next one in the pipeline.
850 This is used on systems where `start-process' is not supported."
851 (when (setq pipeline
(cadr pipeline
))
854 ,(when (cdr pipeline
)
855 `(let (output-marker)
857 (set 'output-marker
,(point-marker))
858 (eshell-set-output-handle ,eshell-output-handle
859 'append output-marker
)
860 (eshell-set-output-handle ,eshell-error-handle
861 'append output-marker
))))
862 ,(let ((head (car pipeline
)))
863 (if (memq (car head
) '(let progn
))
864 (setq head
(car (last head
))))
865 ;;; FIXME: is deferrable significant here?
866 (when (memq (car head
) eshell-deferrable-commands
)
870 (concat (symbol-name (car head
)) "*"))))))
871 ;; The last process in the pipe should get its handles
872 ;; redirected as we found them before running the pipe.
873 ,(if (null (cdr pipeline
))
875 (set 'eshell-current-handles tail-handles
)
876 (set 'eshell-in-pipeline-p nil
)))
877 (set 'result
,(car pipeline
))
878 ;; tailproc gets the result of the last successful process in
880 (set 'tailproc
(or result tailproc
))
882 `(eshell-do-pipelines-synchronously (quote ,(cdr pipeline
))))
885 (defalias 'eshell-process-identity
'identity
)
887 (defmacro eshell-execute-pipeline
(pipeline)
888 "Execute the commands in PIPELINE, connecting each to one another."
889 `(let ((eshell-in-pipeline-p t
) tailproc
)
891 ,(if (fboundp 'start-process
)
892 `(eshell-do-pipelines ,pipeline
)
893 `(let ((tail-handles (eshell-create-handles
894 (car (aref eshell-current-handles
895 ,eshell-output-handle
)) nil
896 (car (aref eshell-current-handles
897 ,eshell-error-handle
)) nil
)))
898 (eshell-do-pipelines-synchronously ,pipeline
)))
899 (eshell-process-identity tailproc
))))
901 (defmacro eshell-as-subcommand
(command)
902 "Execute COMMAND using a temp buffer.
903 This is used so that certain Lisp commands, such as `cd', when
904 executed in a subshell, do not disturb the environment of the main
906 `(let ,eshell-subcommand-bindings
909 (defmacro eshell-do-command-to-value
(object)
910 "Run a subcommand prepared by `eshell-command-to-value'.
911 This avoids the need to use `let*'."
912 `(let ((eshell-current-handles
913 (eshell-create-handles value
'overwrite
)))
916 (symbol-value value
))))
918 (defmacro eshell-command-to-value
(object)
919 "Run OBJECT synchronously, returning its result as a string.
920 Returns a string comprising the output from the command."
921 `(let ((value (make-symbol "eshell-temp")))
922 (eshell-do-command-to-value ,object
)))
924 ;;;_* Iterative evaluation
926 ;; Eshell runs all of its external commands asynchronously, so that
927 ;; Emacs is not blocked while the operation is being performed.
928 ;; However, this introduces certain synchronization difficulties,
929 ;; since the Lisp code, once it returns, will not "go back" to finish
930 ;; executing the commands which haven't yet been started.
932 ;; What Eshell does to work around this problem (basically, the lack
933 ;; of threads in Lisp), is that it evaluates the command sequence
934 ;; iteratively. Whenever an asynchronous process is begun, evaluation
935 ;; terminates and control is given back to Emacs. When that process
936 ;; finishes, it will resume the evaluation using the remainder of the
939 (defun eshell/eshell-debug
(&rest args
)
940 "A command for toggling certain debug variables."
944 (if eshell-handle-errors
945 (eshell-print "errors\n"))
946 (if eshell-debug-command
947 (eshell-print "commands\n")))
948 ((or (string= (car args
) "-h")
949 (string= (car args
) "--help"))
950 (eshell-print "usage: eshell-debug [kinds]
952 This command is used to aid in debugging problems related to Eshell
953 itself. It is not useful for anything else. The recognized `kinds'
956 errors stops Eshell from trapping errors
957 commands shows command execution progress in `*eshell last cmd*'
962 ((string= (car args
) "errors")
963 (setq eshell-handle-errors
(not eshell-handle-errors
)))
964 ((string= (car args
) "commands")
965 (setq eshell-debug-command
(not eshell-debug-command
))))
966 (setq args
(cdr args
)))))))
968 (defun pcomplete/eshell-mode
/eshell-debug
()
969 "Completion for the `debug' command."
970 (while (pcomplete-here '("errors" "commands"))))
972 (defun eshell-invoke-directly (command input
)
973 (let ((base (cadr (nth 2 (nth 2 (cadr command
))))) name
)
974 (if (and (eq (car base
) 'eshell-trap-errors
)
975 (eq (car (cadr base
)) 'eshell-named-command
))
976 (setq name
(cadr (cadr base
))))
977 (and name
(stringp name
)
978 (not (member name eshell-complex-commands
))
981 (eshell-for pred eshell-complex-commands
982 (if (and (functionp pred
)
984 (throw 'simple nil
)))
986 (fboundp (intern-soft (concat "eshell/" name
))))))
988 (defun eshell-eval-command (command &optional input
)
989 "Evaluate the given COMMAND iteratively."
990 (if eshell-current-command
991 ;; we can just stick the new command at the end of the current
992 ;; one, and everything will happen as it should
993 (setcdr (last (cdr eshell-current-command
))
994 (list (list 'let
'((here (and (eobp) (point))))
996 (list 'insert-and-inherit
997 (concat input
"\n")))
999 (eshell-update-markers here
))
1000 (list 'eshell-do-eval
1001 (list 'quote command
)))))
1002 (and eshell-debug-command
1004 (let ((buf (get-buffer-create "*eshell last cmd*")))
1007 (insert "command: \"" input
"\"\n"))))
1008 (setq eshell-current-command command
)
1009 (let ((delim (catch 'eshell-incomplete
1010 (eshell-resume-eval))))
1011 ;; On systems that don't support async subprocesses, eshell-resume
1012 ;; can return t. Don't treat that as an error.
1014 (setq delim
(car delim
)))
1015 (if (and delim
(not (eq delim t
)))
1016 (error "Unmatched delimiter: %c" delim
)))))
1018 (defun eshell-resume-command (proc status
)
1019 "Resume the current command when a process ends."
1021 (unless (or (not (stringp status
))
1022 (string= "stopped" status
)
1023 (string-match eshell-reset-signals status
))
1024 (if (eq proc
(eshell-interactive-process))
1025 (eshell-resume-eval)))))
1027 (defun eshell-resume-eval ()
1028 "Destructively evaluate a form which may need to be deferred."
1029 (eshell-condition-case err
1031 (setq eshell-last-async-proc nil
)
1032 (when eshell-current-command
1034 (proc (catch 'eshell-defer
1038 eshell-current-command
))))))
1039 (if (eshell-processp proc
)
1040 (ignore (setq eshell-last-async-proc proc
))
1043 (error (error-message-string err
)))))
1045 (defmacro eshell-manipulate
(tag &rest commands
)
1046 "Manipulate a COMMAND form, with TAG as a debug identifier."
1047 (if (not eshell-debug-command
)
1050 (eshell-debug-command ,(eval tag
) form
)
1052 (eshell-debug-command ,(concat "done " (eval tag
)) form
))))
1054 (put 'eshell-manipulate
'lisp-indent-function
1)
1056 ;; eshell-lookup-function, eshell-functionp, and eshell-macrop taken
1059 (defsubst eshell-lookup-function
(object)
1060 "Return the ultimate function definition of OBJECT."
1061 (while (and (symbolp object
) (fboundp object
))
1062 (setq object
(symbol-function object
)))
1065 (defconst function-p-func
1066 (if (fboundp 'compiled-function-p
)
1067 'compiled-function-p
1068 'byte-code-function-p
))
1070 (defsubst eshell-functionp
(object)
1071 "Returns the function named by OBJECT, or nil if it is not a function."
1072 (setq object
(eshell-lookup-function object
))
1073 (if (or (subrp object
)
1074 (funcall function-p-func object
)
1076 (eq (car object
) 'lambda
)
1077 (listp (car (cdr object
)))))
1080 (defsubst eshell-macrop
(object)
1081 "Return t if OBJECT is a macro or nil otherwise."
1082 (setq object
(eshell-lookup-function object
))
1083 (if (and (listp object
)
1084 (eq 'macro
(car object
))
1085 (eshell-functionp (cdr object
)))
1088 (defun eshell-do-eval (form &optional synchronous-p
)
1089 "Evaluate form, simplifying it as we go.
1090 Unless SYNCHRONOUS-P is non-nil, throws `eshell-defer' if it needs to
1091 be finished later after the completion of an asynchronous subprocess."
1094 (list 'quote
(eval form
)))
1095 ((memq (car form
) '(quote function
))
1098 ;; skip past the call to `eshell-do-eval'
1099 (when (eq (car form
) 'eshell-do-eval
)
1100 (setq form
(cadr (cadr form
))))
1101 ;; expand any macros directly into the form. This is done so that
1102 ;; we can modify any `let' forms to evaluate only once.
1103 (if (eshell-macrop (car form
))
1104 (let ((exp (eshell-copy-tree (macroexpand form
))))
1105 (eshell-manipulate (format "expanding macro `%s'"
1106 (symbol-name (car form
)))
1107 (setcar form
(car exp
))
1108 (setcdr form
(cdr exp
)))))
1109 (let ((args (cdr form
)))
1111 ((eq (car form
) 'while
)
1112 ;; `eshell-copy-tree' is needed here so that the test argument
1113 ;; doesn't get modified and thus always yield the same result.
1114 (when (car eshell-command-body
)
1115 (assert (not synchronous-p
))
1116 (eshell-do-eval (car eshell-command-body
))
1117 (setcar eshell-command-body nil
)
1118 (setcar eshell-test-body nil
))
1119 (unless (car eshell-test-body
)
1120 (setcar eshell-test-body
(eshell-copy-tree (car args
))))
1121 (while (cadr (eshell-do-eval (car eshell-test-body
)))
1122 (setcar eshell-command-body
(eshell-copy-tree (cadr args
)))
1123 (eshell-do-eval (car eshell-command-body
) synchronous-p
)
1124 (setcar eshell-command-body nil
)
1125 (setcar eshell-test-body
(eshell-copy-tree (car args
))))
1126 (setcar eshell-command-body nil
))
1127 ((eq (car form
) 'if
)
1128 ;; `eshell-copy-tree' is needed here so that the test argument
1129 ;; doesn't get modified and thus always yield the same result.
1130 (if (car eshell-command-body
)
1132 (assert (not synchronous-p
))
1133 (eshell-do-eval (car eshell-command-body
)))
1134 (unless (car eshell-test-body
)
1135 (setcar eshell-test-body
(eshell-copy-tree (car args
))))
1136 (if (cadr (eshell-do-eval (car eshell-test-body
)))
1137 (setcar eshell-command-body
(eshell-copy-tree (cadr args
)))
1138 (setcar eshell-command-body
(eshell-copy-tree (car (cddr args
)))))
1139 (eshell-do-eval (car eshell-command-body
) synchronous-p
))
1140 (setcar eshell-command-body nil
)
1141 (setcar eshell-test-body nil
))
1142 ((eq (car form
) 'setcar
)
1143 (setcar (cdr args
) (eshell-do-eval (cadr args
) synchronous-p
))
1145 ((eq (car form
) 'setcdr
)
1146 (setcar (cdr args
) (eshell-do-eval (cadr args
) synchronous-p
))
1148 ((memq (car form
) '(let catch condition-case unwind-protect
))
1149 ;; `let', `condition-case' and `unwind-protect' have to be
1150 ;; handled specially, because we only want to call
1151 ;; `eshell-do-eval' on their first form.
1153 ;; NOTE: This requires obedience by all forms which this
1154 ;; function might encounter, that they do not contain
1155 ;; other special forms.
1156 (if (and (eq (car form
) 'let
)
1157 (not (eq (car (cadr args
)) 'eshell-do-eval
)))
1158 (eshell-manipulate "evaluating let args"
1159 (eshell-for letarg
(car args
)
1160 (if (and (listp letarg
)
1161 (not (eq (cadr letarg
) 'quote
)))
1163 (list (eshell-do-eval
1164 (cadr letarg
) synchronous-p
)))))))
1165 (unless (eq (car form
) 'unwind-protect
)
1166 (setq args
(cdr args
)))
1167 (unless (eq (caar args
) 'eshell-do-eval
)
1168 (eshell-manipulate "handling special form"
1169 (setcar args
(list 'eshell-do-eval
1170 (list 'quote
(car args
))
1174 (if (and args
(not (memq (car form
) '(run-hooks))))
1176 (format "evaluating arguments to `%s'"
1177 (symbol-name (car form
)))
1179 (setcar args
(eshell-do-eval (car args
) synchronous-p
))
1180 (setq args
(cdr args
)))))
1182 ((eq (car form
) 'progn
)
1184 ((eq (car form
) 'prog1
)
1187 ;; If a command desire to replace its execution form with
1188 ;; another command form, all it needs to do is throw the new
1189 ;; form using the exception tag `eshell-replace-command'.
1190 ;; For example, let's say that the form currently being
1193 ;; (eshell-named-command "hello")
1195 ;; Now, let's assume the 'hello' command is an Eshell alias,
1196 ;; the definition of which yields the command:
1198 ;; (eshell-named-command "echo" (list "Hello" "world"))
1200 ;; What the alias code would like to do is simply substitute
1201 ;; the alias form for the original form. To accomplish
1202 ;; this, all it needs to do is to throw the substitution
1203 ;; form with the `eshell-replace-command' tag, and the form
1204 ;; will be replaced within the current command, and
1205 ;; execution will then resume (iteratively) as before.
1206 ;; Thus, aliases can even contain references to asynchronous
1207 ;; sub-commands, and things will still work out as they
1209 (let (result new-form
)
1211 (catch 'eshell-replace-command
1213 (setq result
(eval form
)))))
1215 (eshell-manipulate "substituting replacement form"
1216 (setcar form
(car new-form
))
1217 (setcdr form
(cdr new-form
)))
1218 (eshell-do-eval form synchronous-p
))
1219 (if (and (memq (car form
) eshell-deferrable-commands
)
1220 (not eshell-current-subjob-p
)
1222 (eshell-processp result
))
1224 (eshell/wait result
)
1225 (eshell-manipulate "inserting ignore form"
1226 (setcar form
'ignore
)
1228 (throw 'eshell-defer result
))
1229 (list 'quote result
))))))))))))
1231 ;; command invocation
1233 (defun eshell/which
(command &rest names
)
1234 "Identify the COMMAND, and where it is located."
1235 (eshell-for name
(cons command names
)
1236 (let (program alias direct
)
1237 (if (eq (aref name
0) eshell-explicit-command-char
)
1238 (setq name
(substring name
1)
1240 (if (and (not direct
)
1241 (eshell-using-module 'eshell-alias
)
1243 (funcall (symbol-function 'eshell-lookup-alias
)
1246 (concat name
" is an alias, defined as \""
1247 (cadr alias
) "\"")))
1249 (setq program
(eshell-search-path name
))
1250 (let* ((esym (eshell-find-alias-function name
))
1251 (sym (or esym
(intern-soft name
))))
1252 (if (and (or esym
(and sym
(fboundp sym
)))
1253 (or eshell-prefer-lisp-functions
(not direct
)))
1254 (let ((desc (let ((inhibit-redisplay t
))
1255 (save-window-excursion
1257 (describe-function sym
)
1259 (setq desc
(substring desc
0
1260 (1- (or (string-match "\n" desc
)
1262 (if (buffer-live-p (get-buffer "*Help*"))
1263 (kill-buffer "*Help*"))
1264 (setq program
(or desc name
))))))
1266 (eshell-error (format "which: no %s in (%s)\n"
1267 name
(getenv "PATH")))
1268 (eshell-printn program
)))))
1270 (put 'eshell
/which
'eshell-no-numeric-conversions t
)
1272 (defun eshell-named-command (command &optional args
)
1273 "Insert output from a plain COMMAND, using ARGS.
1274 COMMAND may result in an alias being executed, or a plain command."
1275 (setq eshell-last-arguments args
1276 eshell-last-command-name
(eshell-stringify command
))
1277 (run-hook-with-args 'eshell-prepare-command-hook
)
1278 (assert (stringp eshell-last-command-name
))
1279 (if eshell-last-command-name
1280 (or (run-hook-with-args-until-success
1281 'eshell-named-command-hook eshell-last-command-name
1282 eshell-last-arguments
)
1283 (eshell-plain-command eshell-last-command-name
1284 eshell-last-arguments
))))
1286 (defalias 'eshell-named-command
* 'eshell-named-command
)
1288 (defun eshell-find-alias-function (name)
1289 "Check whether a function called `eshell/NAME' exists."
1290 (let* ((sym (intern-soft (concat "eshell/" name
)))
1291 (file (symbol-file sym
'defun
)))
1292 ;; If the function exists, but is defined in an eshell module
1293 ;; that's not currently enabled, don't report it as found
1295 (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file
))
1297 (intern (file-name-sans-extension
1298 (file-name-nondirectory
1299 (concat "eshell-" (match-string 2 file
)))))))
1300 (if (and (functionp sym
)
1301 (or (null module-sym
)
1302 (eshell-using-module module-sym
)
1303 (memq module-sym
(eshell-subgroups 'eshell
))))
1305 ;; Otherwise, if it's bound, return it.
1309 (defun eshell-plain-command (command args
)
1310 "Insert output from a plain COMMAND, using ARGS.
1311 COMMAND may result in either a Lisp function being executed by name,
1312 or an external command."
1313 (let* ((esym (eshell-find-alias-function command
))
1314 (sym (or esym
(intern-soft command
))))
1315 (if (and sym
(fboundp sym
)
1316 (or esym eshell-prefer-lisp-functions
1317 (not (eshell-search-path command
))))
1318 (eshell-lisp-command sym args
)
1319 (eshell-external-command command args
))))
1321 (defun eshell-exec-lisp (printer errprint func-or-form args form-p
)
1322 "Execute a lisp FUNC-OR-FORM, maybe passing ARGS.
1323 PRINTER and ERRPRINT are functions to use for printing regular
1324 messages, and errors. FORM-P should be non-nil if FUNC-OR-FORM
1325 represent a lisp form; ARGS will be ignored in that case."
1327 (eshell-condition-case err
1330 (save-current-buffer
1333 (apply func-or-form args
))))
1334 (and result
(funcall printer result
))
1337 (let ((msg (error-message-string err
)))
1338 (if (and (not form-p
)
1339 (string-match "^Wrong number of arguments" msg
)
1340 (fboundp 'eldoc-get-fnsym-args-string
))
1341 (let ((func-doc (eldoc-get-fnsym-args-string func-or-form
)))
1342 (setq msg
(format "usage: %s" func-doc
))))
1343 (funcall errprint msg
))
1346 (defsubst eshell-apply
* (printer errprint func args
)
1347 "Call FUNC, with ARGS, trapping errors and return them as output.
1348 PRINTER and ERRPRINT are functions to use for printing regular
1349 messages, and errors."
1350 (eshell-exec-lisp printer errprint func args nil
))
1352 (defsubst eshell-funcall
* (printer errprint func
&rest args
)
1353 "Call FUNC, with ARGS, trapping errors and return them as output."
1354 (eshell-apply* printer errprint func args
))
1356 (defsubst eshell-eval
* (printer errprint form
)
1357 "Evaluate FORM, trapping errors and returning them."
1358 (eshell-exec-lisp printer errprint form nil t
))
1360 (defsubst eshell-apply
(func args
)
1361 "Call FUNC, with ARGS, trapping errors and return them as output.
1362 PRINTER and ERRPRINT are functions to use for printing regular
1363 messages, and errors."
1364 (eshell-apply* 'eshell-print
'eshell-error func args
))
1366 (defsubst eshell-funcall
(func &rest args
)
1367 "Call FUNC, with ARGS, trapping errors and return them as output."
1368 (eshell-apply func args
))
1370 (defsubst eshell-eval
(form)
1371 "Evaluate FORM, trapping errors and returning them."
1372 (eshell-eval* 'eshell-print
'eshell-error form
))
1374 (defsubst eshell-applyn
(func args
)
1375 "Call FUNC, with ARGS, trapping errors and return them as output.
1376 PRINTER and ERRPRINT are functions to use for printing regular
1377 messages, and errors."
1378 (eshell-apply* 'eshell-printn
'eshell-errorn func args
))
1380 (defsubst eshell-funcalln
(func &rest args
)
1381 "Call FUNC, with ARGS, trapping errors and return them as output."
1382 (eshell-applyn func args
))
1384 (defsubst eshell-evaln
(form)
1385 "Evaluate FORM, trapping errors and returning them."
1386 (eshell-eval* 'eshell-printn
'eshell-errorn form
))
1388 (defun eshell-lisp-command (object &optional args
)
1389 "Insert Lisp OBJECT, using ARGS if a function."
1390 (catch 'eshell-external
; deferred to an external command
1391 (let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
1393 (if (functionp object
)
1395 (setq eshell-last-arguments args
1396 eshell-last-command-name
1397 (concat "#<function " (symbol-name object
) ">"))
1398 ;; if any of the arguments are flagged as numbers
1399 ;; waiting for conversion, convert them now
1400 (unless (get object
'eshell-no-numeric-conversions
)
1402 (let ((arg (car args
)))
1403 (if (and (stringp arg
)
1405 (not (text-property-not-all
1406 0 (length arg
) 'number t arg
)))
1407 (setcar args
(string-to-number arg
))))
1408 (setq args
(cdr args
))))
1409 (eshell-apply object eshell-last-arguments
))
1410 (setq eshell-last-arguments args
1411 eshell-last-command-name
"#<Lisp object>")
1412 (eshell-eval object
))))
1413 (if (and eshell-ensure-newline-p
1415 (goto-char eshell-last-output-end
)
1417 (eshell-print "\n"))
1418 (eshell-close-handles 0 (list 'quote result
)))))
1420 (defalias 'eshell-lisp-command
* 'eshell-lisp-command
)
1424 ;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366
1425 ;;; esh-cmd.el ends here