Function: shell-environment-variable-completion
shell-environment-variable-completion is a byte-compiled function
defined in shell.el.gz.
Signature
(shell-environment-variable-completion)
Documentation
Completion data for an environment variable at point, if any.
Source Code
;; Defined in /usr/src/emacs/lisp/shell.el.gz
(defun shell-environment-variable-completion ()
"Completion data for an environment variable at point, if any."
(let* ((var (shell-match-partial-variable))
(end (match-end 0)))
(when (and (not (zerop (length var))) (eq (aref var 0) ?$))
(let* ((start
(save-excursion
(goto-char (match-beginning 0))
(looking-at "\\$?[({]*")
(match-end 0)))
(variables (mapcar (lambda (x)
(substring x 0 (string-search "=" x)))
process-environment))
(suffix (pcase (char-before start) (?\{ "}") (?\( ")") (_ ""))))
(list start end variables
:exit-function
(lambda (s finished)
(when (memq finished '(sole finished))
(let ((suf (concat suffix
(if (file-directory-p
(comint-directory (getenv s)))
"/"))))
(if (looking-at (regexp-quote suf))
(goto-char (match-end 0))
(insert suf))))))))))