Function: eshell-parse-variable-ref

eshell-parse-variable-ref is a byte-compiled function defined in esh-var.el.gz.

Signature

(eshell-parse-variable-ref)

Documentation

Eval a variable reference.

Returns a Lisp form which, if evaluated, will return the value of the variable.

Possible options are:

  NAME an environment or Lisp variable value
  "LONG-NAME" disambiguates the length of the name
  'LONG-NAME' as above
  {COMMAND} result of command is variable's value
  (LISP-FORM) result of Lisp form is variable's value
  <COMMAND> write the output of command to a temporary file;
                result is the file name

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-var.el.gz
(defun eshell-parse-variable-ref ()
  "Eval a variable reference.
Returns a Lisp form which, if evaluated, will return the value of the
variable.

Possible options are:

  NAME          an environment or Lisp variable value
  \"LONG-NAME\"   disambiguates the length of the name
  'LONG-NAME'   as above
  {COMMAND}     result of command is variable's value
  (LISP-FORM)   result of Lisp form is variable's value
  <COMMAND>     write the output of command to a temporary file;
                result is the file name"
  (cond
   ((eq (char-after) ?{)
    (let ((end (eshell-find-delimiter ?\{ ?\})))
      (if (not end)
          (throw 'eshell-incomplete ?\{)
        (prog1
            `(eshell-convert
              (eshell-command-to-value
               (eshell-as-subcommand
                ,(eshell-parse-command (cons (1+ (point)) end)))))
          (goto-char (1+ end))))))
   ((memq (char-after) '(?\' ?\"))
    (let ((name (if (eq (char-after) ?\')
                    (eshell-parse-literal-quote)
                  (eshell-parse-double-quote))))
      (if name
	  `(eshell-get-variable ,(eval name) indices))))
   ((eq (char-after) ?\<)
    (let ((end (eshell-find-delimiter ?\< ?\>)))
      (if (not end)
          (throw 'eshell-incomplete ?\<)
        (let* ((temp (make-temp-file temporary-file-directory))
               (cmd (concat (buffer-substring (1+ (point)) end)
                            " > " temp)))
          (prog1
              `(let ((eshell-current-handles
                      (eshell-create-handles ,temp 'overwrite)))
                 (progn
                   (eshell-as-subcommand ,(eshell-parse-command cmd))
                   (ignore
                    (nconc eshell-this-command-hook
                           ;; Quote this lambda; it will be evaluated
                           ;; by `eshell-do-eval', which requires very
                           ;; particular forms in order to work
                           ;; properly.  See bug#54190.
                           (list (function (lambda ()
                                   (delete-file ,temp))))))
                   (quote ,temp)))
            (goto-char (1+ end)))))))
   ((eq (char-after) ?\()
    (condition-case nil
        `(eshell-command-to-value
          (eshell-lisp-command
           ',(read (current-buffer))))
      (end-of-file
       (throw 'eshell-incomplete ?\())))
   ((assoc (char-to-string (char-after))
           eshell-variable-aliases-list)
    (forward-char)
    `(eshell-get-variable ,(char-to-string (char-before)) indices))
   ((looking-at eshell-variable-name-regexp)
    (prog1
        `(eshell-get-variable ,(match-string 0) indices)
      (goto-char (match-end 0))))
   (t
    (error "Invalid variable reference"))))