Function: eshell-complete-variable-reference

eshell-complete-variable-reference is a byte-compiled function defined in esh-var.el.gz.

Signature

(eshell-complete-variable-reference)

Documentation

If there is a variable reference, complete it.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-var.el.gz
;;;_* Variable name completion

(defun eshell-complete-variable-reference ()
  "If there is a variable reference, complete it."
  (let ((arg (pcomplete-actual-arg)))
    (when (string-match
           (rx "$" (? (or "#" "@"))
               (or (group-n 1 (? (regexp eshell-variable-name-regexp))
                            string-end)
                   (seq (group-n 2 (or "'" "\""))
                        (group-n 1 (+ anychar)))))
           arg)
      (setq pcomplete-stub (substring arg (match-beginning 1)))
      (let ((delimiter (match-string 2 arg)))
        ;; When finished with completion, insert the trailing
        ;; delimiter, if any, and add a trailing slash if the variable
        ;; refers to a directory.
        (add-function
         :before-until (var pcomplete-exit-function)
         (lambda (variable status)
           (when (eq status 'finished)
             (when delimiter
               (if (looking-at (regexp-quote delimiter))
                   (goto-char (match-end 0))
                 (insert delimiter)))
             (let ((non-essential t)
                   (value (eshell-get-variable variable)))
               (when (and (stringp value) (file-directory-p value))
                 (insert "/")
                 ;; Tell Pcomplete not to insert its own termination
                 ;; string.
                 t))))))
      (throw 'pcomplete-completions (eshell-variables-list)))))