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 either be a string, or a cons cell demarcating a buffer region. 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
(defun eshell-parse-command (command &optional args toplevel)
  "Parse the COMMAND, adding ARGS if given.
COMMAND can either be a string, or a cons cell demarcating a buffer
region.  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."
  (let* (eshell--sep-terms
	 (terms
	  (append
	   (if (consp command)
	       (eshell-parse-arguments (car command) (cdr command))
	     (let ((here (point))
		   (inhibit-point-motion-hooks t))
               (with-silent-modifications
                 ;; FIXME: Why not use a temporary buffer and avoid this
                 ;; "insert&delete" business?  --Stef
                 (insert command)
                 (prog1
                     (eshell-parse-arguments here (point))
                   (delete-region here (point))))))
	   args))
	 (commands
	  (mapcar
           (lambda (cmd)
             (setq cmd
                   (if (or (not (car eshell--sep-terms))
                           (string= (car eshell--sep-terms) ";"))
                       (eshell-parse-pipeline cmd)
                     `(eshell-do-subjob
                       (list ,(eshell-parse-pipeline cmd)))))
             (setq eshell--sep-terms (cdr eshell--sep-terms))
             (if eshell-in-pipeline-p
                 cmd
               `(eshell-trap-errors ,cmd)))
	   (eshell-separate-commands terms "[&;]" nil 'eshell--sep-terms))))
    (let ((cmd commands))
      (while cmd
	(if (cdr cmd)
	    (setcar cmd `(eshell-commands ,(car cmd))))
	(setq cmd (cdr cmd))))
    (if toplevel
	`(eshell-commands (progn
                            (run-hooks 'eshell-pre-command-hook)
                            (catch 'top-level (progn ,@commands))
                            (run-hooks 'eshell-post-command-hook)))
      (macroexp-progn commands))))