• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/eshell/

Lines Matching +defs:command +defs:args

1 ;;; esh-cmd.el --- command invocation
30 "Executing an Eshell command is as simple as typing it in and
47 ;; A Lisp function can be invoked using Lisp syntax, or command shell
61 ;; Ordinarily, if 'dired' were also available as an external command,
74 ;; Whenever a command is specified using a simple name, such as 'ls',
76 ;; If it exists, it will be called in preference to any other command
77 ;; which might have matched the name 'ls' (such as command aliases,
123 ;; There are several hooks involved with command execution, which can
126 (defcustom eshell-pre-command-hook nil
127 "*A hook run before each interactive command is invoked."
131 (defcustom eshell-post-command-hook nil
132 "*A hook run after each interactive command is invoked."
136 (defcustom eshell-prepare-command-hook nil
137 "*A set of functions called to prepare a named command.
138 The command name and its argument are in `eshell-last-command-name'
142 To prevent a command from executing at all, set
143 `eshell-last-command-name' to nil."
147 (defcustom eshell-named-command-hook nil
148 "*A set of functions called before a named command is invoked.
149 Each function will be passed the command name and arguments that were
150 passed to `eshell-named-command'.
152 If any of the functions returns a non-nil value, the named command
154 `eshell-named-command'.
156 In order to substitute an alternate command form for execution, the
157 hook function should throw it using the tag `eshell-replace-command'.
160 (add-hook 'eshell-named-command-hook 'subst-with-cd)
161 (defun subst-with-cd (command args)
162 (throw 'eshell-replace-command
163 (eshell-parse-command \"cd\" args)))
166 command (i.e., 'ls' as opposed to '*ls' or '(ls)') to be replaced by a
171 (defcustom eshell-pre-rewrite-command-hook
172 '(eshell-no-command-conversion
174 "*A hook run before command rewriting begins.
175 The terms of the command to be rewritten is passed as arguments, and
180 (defcustom eshell-rewrite-command-hook
181 '(eshell-rewrite-for-command
182 eshell-rewrite-while-command
183 eshell-rewrite-if-command
184 eshell-rewrite-sexp-command
186 eshell-rewrite-named-command)
187 "*A set of functions used to rewrite the command argument.
188 Once parsing of a command line is completed, the next step is to
192 syntaxes at the beginning of a command line. They are welcome to do
194 substitute command form is the one used. Each function is passed the
195 command's full argument list, which is a list of sexps (typically
200 (defcustom eshell-post-rewrite-command-hook nil
201 "*A hook run after command rewriting is finished.
202 Each function is passed the symbol containing the rewritten command,
209 That is, if a command is defined by a function named eshell/NAME,
210 and NAME is part of this list, it is invoked as a complex command.
212 command works fine without being part of this list, then it doesn't
216 return non-nil if the command is complex."
238 (defcustom eshell-debug-command nil
241 will have to visit the file 'eshell-cmd.el' and run the command
247 '(eshell-named-command
248 eshell-lisp-command
252 command will wait for completion (in the background) before finishing
253 the command."
270 command line.")
274 (defvar eshell-current-command nil)
275 (defvar eshell-command-name nil)
276 (defvar eshell-command-arguments nil)
280 (defvar eshell-last-command-name nil)
282 "When this foreground process completes, resume command evaluation.")
287 "Return currently running command process, if non-Lisp."
291 "Initialize the Eshell command processing module."
292 (set (make-local-variable 'eshell-current-command) nil)
293 (set (make-local-variable 'eshell-command-name) nil)
294 (set (make-local-variable 'eshell-command-arguments) nil)
296 (set (make-local-variable 'eshell-last-command-name) nil)
299 (add-hook 'eshell-kill-hook 'eshell-resume-command nil t)
301 ;; make sure that if a command is over, and no process is being
302 ;; waited for, that `eshell-current-command' is set to nil. This
305 (add-hook 'eshell-post-command-hook
308 (setq eshell-current-command nil
322 (eshell-command-result-p "+ 1 2; + $$ 2" "3\n5\n"))
326 (eshell-command-result-p "+ 1 2; + $$ $$" "3\n6\n"))
330 (eshell-command-result-p "+ 1 2; + $_ 4" "3\n6\n"))
343 (defun eshell-parse-command (command &optional args top-level)
346 region. TOP-LEVEL, if non-nil, means that the outermost command (the
347 user's input command) is being parsed, and that pre and post command
348 hooks should be run before and after the command."
352 (if (consp command)
353 (eshell-parse-arguments (car command) (cdr command))
357 (insert command)
361 args))
386 (list '(run-hooks 'eshell-pre-command-hook)))
392 '(run-hooks 'eshell-post-command-hook)))))
397 (defun eshell-debug-show-parsed-args (terms)
400 (if eshell-debug-command
401 (eshell-debug-command "parsed arguments" terms))))
403 (defun eshell-no-command-conversion (terms)
404 "Don't convert the command argument."
412 (setq terms (cdr terms)) ; skip command argument
417 (list 'eshell-command-to-value
421 (defun eshell-rewrite-sexp-command (terms)
425 (eq (caar terms) 'eshell-command-to-value))
428 (eshell-deftest cmd lisp-command
429 "Evaluate Lisp command"
430 (eshell-command-result-p "(+ 1 2)" "3"))
432 (eshell-deftest cmd lisp-command-args
433 "Evaluate Lisp command (ignore args)"
434 (eshell-command-result-p "(+ 1 2) 3" "3"))
444 (eshell-command-result-p "{+ 1 2}" "3\n"))
446 (eshell-deftest cmd subcommand-args
447 "Run subcommand (ignore args)"
448 (eshell-command-result-p "{+ 1 2} 3" "3\n"))
452 (eshell-command-result-p "{(+ 1 2)}" "3\n"))
454 (defun eshell-rewrite-named-command (terms)
455 "If no other rewriting rule transforms TERMS, assume a named command."
457 'eshell-named-command*
458 'eshell-named-command))
460 (args (cdr terms)))
461 (if args
465 (eshell-deftest cmd named-command
466 "Execute named command"
467 (eshell-command-result-p "+ 1 2" "3\n"))
470 (defvar eshell-command-body)
474 "Change ARG so it can be invoked from a structured command.
479 from this command. If both SHARE-OUTPUT and SILENT are non-nil,
490 (eq (car (cadr arg)) 'eshell-command-to-value))
497 (defun eshell-rewrite-for-command (terms)
498 "Rewrite a `for' command into its equivalent Eshell command form.
519 (list 'eshell-command-body
546 'eshell-last-command-status
548 'eshell-last-command-result)))))))
550 (defun eshell-structure-basic-command (func names keyword test body
552 "With TERMS, KEYWORD, and two NAMES, structure a basic command.
578 ;; command
580 'let (list (list 'eshell-command-body
586 'eshell-last-command-status
588 'eshell-last-command-result))))
590 (defun eshell-rewrite-while-command (terms)
591 "Rewrite a `while' command into its equivalent Eshell command form.
597 (eshell-structure-basic-command
603 (defun eshell-rewrite-if-command (terms)
604 "Rewrite an `if' command into its equivalent Eshell command form.
610 (eshell-structure-basic-command
624 "Return non-nil if the last command was \"successful\".
626 For an external command, it means an exit code of 0."
629 eshell-last-command-name))
630 eshell-last-command-result
631 (= eshell-last-command-status 0)))
647 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd)
648 (setq cmd (run-hook-with-args-until-success
649 'eshell-rewrite-command-hook cmd))
650 (run-hook-with-args 'eshell-post-rewrite-command-hook 'cmd)
670 (setq final (eshell-structure-basic-command
680 "Parse a subcommand argument of the form '{command}'."
692 (eshell-parse-command (cons (1+ (point)) end)))
707 (list 'eshell-command-to-value
708 (list 'eshell-lisp-command (list 'quote obj)))
762 "Evaluate a command OBJECT as a subjob.
769 "Place a valid set of handles, and context, around command OBJECT."
777 Also, the variable `eshell-this-command-hook' is available for the
783 `(let ((eshell-this-command-hook (list 'ignore)))
787 (run-hooks 'eshell-this-command-hook))
789 (run-hooks 'eshell-this-command-hook)
836 Output of each command is passed as input to the next one in the pipeline.
888 (defmacro eshell-as-subcommand (command)
894 ,command))
896 (defmacro eshell-do-command-to-value (object)
897 "Run a subcommand prepared by `eshell-command-to-value'.
905 (defmacro eshell-command-to-value (object)
907 Returns a string comprising the output from the command."
909 (eshell-do-command-to-value ,object)))
920 ;; of threads in Lisp), is that it evaluates the command sequence
924 ;; command tree.
926 (defun eshell/eshell-debug (&rest args)
927 "A command for toggling certain debug variables."
930 ((not args)
933 (if eshell-debug-command
935 ((or (string= (car args) "-h")
936 (string= (car args) "--help"))
939 This command is used to aid in debugging problems related to Eshell
944 commands shows command execution progress in `*eshell last cmd*'
947 (while args
949 ((string= (car args) "errors")
951 ((string= (car args) "commands")
952 (setq eshell-debug-command (not eshell-debug-command))))
953 (setq args (cdr args)))))))
956 "Completion for the `debug' command."
959 (defun eshell-debug-command (tag subform)
962 (text (eshell-stringify eshell-current-command)))
971 (defun eshell-invoke-directly (command input)
972 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name)
974 (eq (car (cadr base)) 'eshell-named-command))
987 (defun eshell-eval-command (command &optional input)
989 (if eshell-current-command
990 ;; we can just stick the new command at the end of the current
992 (setcdr (last (cdr eshell-current-command))
1000 (list 'quote command)))))
1001 (and eshell-debug-command
1006 (insert "command: \"" input "\"\n"))))
1007 (setq eshell-current-command command)
1017 (defun eshell-resume-command (proc status)
1018 "Resume the current command when a process ends."
1031 (when eshell-current-command
1037 eshell-current-command))))))
1046 (if (not eshell-debug-command)
1049 (eshell-debug-command ,(eval tag) form)
1051 (eshell-debug-command ,(concat "done " (eval tag)) form))))
1108 (let ((args (cdr form)))
1113 (when (car eshell-command-body)
1115 (eshell-do-eval (car eshell-command-body))
1116 (setcar eshell-command-body nil)
1119 (setcar eshell-test-body (eshell-copy-tree (car args))))
1121 (setcar eshell-command-body (eshell-copy-tree (cadr args)))
1122 (eshell-do-eval (car eshell-command-body) synchronous-p)
1123 (setcar eshell-command-body nil)
1124 (setcar eshell-test-body (eshell-copy-tree (car args))))
1125 (setcar eshell-command-body nil))
1129 (if (car eshell-command-body)
1132 (eshell-do-eval (car eshell-command-body)))
1134 (setcar eshell-test-body (eshell-copy-tree (car args))))
1136 (setcar eshell-command-body (eshell-copy-tree (cadr args)))
1137 (setcar eshell-command-body (eshell-copy-tree (car (cddr args)))))
1138 (eshell-do-eval (car eshell-command-body) synchronous-p))
1139 (setcar eshell-command-body nil)
1142 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p))
1145 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p))
1156 (not (eq (car (cadr args)) 'eshell-do-eval)))
1157 (eshell-manipulate "evaluating let args"
1158 (eshell-for letarg (car args)
1165 (setq args (cdr args)))
1166 (unless (eq (caar args) 'eshell-do-eval)
1168 (setcar args (list 'eshell-do-eval
1169 (list 'quote (car args))
1173 (if (and args (not (memq (car form) '(run-hooks))))
1177 (while args
1178 (setcar args (eshell-do-eval (car args) synchronous-p))
1179 (setq args (cdr args)))))
1186 ;; If a command desire to replace its execution form with
1187 ;; another command form, all it needs to do is throw the new
1188 ;; form using the exception tag `eshell-replace-command'.
1192 ;; (eshell-named-command "hello")
1194 ;; Now, let's assume the 'hello' command is an Eshell alias,
1195 ;; the definition of which yields the command:
1197 ;; (eshell-named-command "echo" (list "Hello" "world"))
1202 ;; form with the `eshell-replace-command' tag, and the form
1203 ;; will be replaced within the current command, and
1210 (catch 'eshell-replace-command
1230 ;; command invocation
1232 (defun eshell/which (command &rest names)
1234 (eshell-for name (cons command names)
1236 (if (eq (aref name 0) eshell-explicit-command-char)
1271 (defun eshell-named-command (command &optional args)
1273 COMMAND may result in an alias being executed, or a plain command."
1274 (setq eshell-last-arguments args
1275 eshell-last-command-name (eshell-stringify command))
1276 (run-hook-with-args 'eshell-prepare-command-hook)
1277 (assert (stringp eshell-last-command-name))
1278 (if eshell-last-command-name
1279 (or (run-hook-with-args-until-success
1280 'eshell-named-command-hook eshell-last-command-name
1282 (eshell-plain-command eshell-last-command-name
1285 (defalias 'eshell-named-command* 'eshell-named-command)
1308 (defun eshell-plain-command (command args)
1311 or an external command."
1312 (let* ((esym (eshell-find-alias-function command))
1313 (sym (or esym (intern-soft command))))
1316 (not (eshell-search-path command))))
1317 (eshell-lisp-command sym args)
1318 (eshell-external-command command args))))
1320 (defun eshell-exec-lisp (printer errprint func-or-form args form-p)
1332 (apply func-or-form args))))
1339 (fboundp 'eldoc-get-fnsym-args-string))
1340 (let ((func-doc (eldoc-get-fnsym-args-string func-or-form)))
1345 (defsubst eshell-apply* (printer errprint func args)
1349 (eshell-exec-lisp printer errprint func args nil))
1351 (defsubst eshell-funcall* (printer errprint func &rest args)
1353 (eshell-apply* printer errprint func args))
1359 (defsubst eshell-apply (func args)
1363 (eshell-apply* 'eshell-print 'eshell-error func args))
1365 (defsubst eshell-funcall (func &rest args)
1367 (eshell-apply func args))
1373 (defsubst eshell-applyn (func args)
1377 (eshell-apply* 'eshell-printn 'eshell-errorn func args))
1379 (defsubst eshell-funcalln (func &rest args)
1381 (eshell-applyn func args))
1387 (defun eshell-lisp-command (object &optional args)
1389 (catch 'eshell-external ; deferred to an external command
1394 (setq eshell-last-arguments args
1395 eshell-last-command-name
1400 (while args
1401 (let ((arg (car args)))
1406 (setcar args (string-to-number arg))))
1407 (setq args (cdr args))))
1409 (setq eshell-last-arguments args
1410 eshell-last-command-name "#<Lisp object>")
1419 (defalias 'eshell-lisp-command* 'eshell-lisp-command)