Function: eshell-parse-command
eshell-parse-command is an autoloaded and byte-compiled function
defined in esh-cmd.el.gz.
Signature
(eshell-parse-command COMMAND &optional ARGS TOPLEVEL)
Documentation
Parse the COMMAND, adding ARGS if given.
COMMAND can be a string, a cons cell (START . END) demarcating a buffer region, or (:file . FILENAME) to parse the contents of FILENAME.
TOPLEVEL, if non-nil, means that the outermost command (the user's input command) is being parsed, and that pre and post command hooks should be run before and after the command.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
;; Command parsing
(defun eshell-parse-command (command &optional args toplevel)
"Parse the COMMAND, adding ARGS if given.
COMMAND can be a string, a cons cell (START . END) demarcating a
buffer region, or (:file . FILENAME) to parse the contents of
FILENAME.
TOPLEVEL, if non-nil, means that the outermost command (the
user's input command) is being parsed, and that pre and post
command hooks should be run before and after the command."
(pcase-let*
((terms
(append
(if (eshell--region-p command)
(eshell-parse-arguments (car command) (cdr command))
(eshell-with-temp-command command
(goto-char (point-max))
(eshell-parse-arguments (point-min) (point-max))))
args))
;; Split up our commands in reverse order.
(`(,sub-chains . ,sep-terms)
(eshell-split-commands terms "[&;]" t t))
;; The last command (first in our reversed list) is implicitly
;; terminated by ";".
(sep-terms (cons ";" sep-terms))
(steal-handles t)
(commands
(nreverse
(mapcan
(lambda (cmd)
(let ((sep (pop sep-terms)))
(if (null cmd)
(when (equal sep "&")
(error "Empty command before `&'"))
(setq cmd (eshell-parse-pipeline cmd))
(unless eshell-in-pipeline-p
(setq cmd `(eshell-trap-errors ,cmd)))
;; Copy I/O handles so each full statement can manipulate
;; them if they like. Steal the handles for the last
;; command (first in our reversed list); we won't use the
;; originals again anyway.
(setq cmd `(eshell-with-copied-handles ,cmd ,steal-handles)
steal-handles nil)
(when (equal sep "&")
(setq cmd `(eshell-do-subjob ,cmd)))
(list cmd))))
sub-chains))))
(if toplevel
`(eshell-commands (progn
(run-hooks 'eshell-pre-command-hook)
(unwind-protect
(progn ,@commands)
(run-hooks 'eshell-post-command-hook))))
(macroexp-progn commands))))