diff options
Diffstat (limited to 'lisp/eshell/esh-var.el')
-rw-r--r-- | lisp/eshell/esh-var.el | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 75ccf5b8353..f91fb89412e 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -179,26 +179,50 @@ if they are quoted with a backslash." (eshell-apply-indices eshell-command-arguments indices))))) "This list provides aliasing for variable references. -It is very similar in concept to what `eshell-user-aliases-list' does -for commands. Each member of this defines the name of a command, -and the Lisp value to return for that variable if it is accessed -via the syntax `$NAME'. - -If the value is a function, that function will be called with two -arguments: the list of the indices that was used in the reference, and -whether the user is requesting the length of the ultimate element. -For example, a reference of `$NAME[10][20]' would result in the -function for alias `NAME' being called (assuming it were aliased to a -function), and the arguments passed to this function would be the list -'(10 20)', and nil." +Each member defines the name of a variable, and a Lisp value used to +compute the string value that will be returned when the variable is +accessed via the syntax `$NAME'. + +If the value is a function, call that function with two arguments: the +list of the indices that was used in the reference, and whether the +user is requesting the length of the ultimate element. For example, a +reference of `$NAME[10][20]' would result in the function for alias +`NAME' being called (assuming it were aliased to a function), and the +arguments passed to this function would be the list '(10 20)', and +nil. + +If the value is a string, return the value for the variable with that +name in the current environment. If no variable with that name exists +in the environment, but if a symbol with that same name exists and has +a value bound to it, return its value instead. You can prioritize +symbol values over environment values by setting +`eshell-prefer-lisp-variables' to t. + +If the value is a symbol, return the value bound to it. + +If the value has any other type, signal an error. + +Additionally, each member may specify if it should be copied to the +environment of created subprocesses." :type '(repeat (list string sexp (choice (const :tag "Copy to environment" t) (const :tag "Use only in Eshell" nil))))) (put 'eshell-variable-aliases-list 'risky-local-variable t) +(defvar eshell-var-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c M-v") #'eshell-insert-envvar) + map)) + ;;; Functions: +(define-minor-mode eshell-var-mode + "Minor mode for the esh-var module. + +\\{eshell-var-mode-map}" + :keymap eshell-var-mode-map) + (defun eshell-var-initialize () ;Called from `eshell-mode' via intern-soft! "Initialize the variable handle code." ;; Break the association with our parent's environment. Otherwise, @@ -207,11 +231,6 @@ function), and the arguments passed to this function would be the list (set (make-local-variable 'process-environment) (eshell-copy-environment))) - ;; This is supposedly run after enabling esh-mode, when eshell-command-map - ;; already exists. - (defvar eshell-command-map) - (define-key eshell-command-map [(meta ?v)] 'eshell-insert-envvar) - (set (make-local-variable 'eshell-special-chars-inside-quoting) (append eshell-special-chars-inside-quoting '(?$))) (set (make-local-variable 'eshell-special-chars-outside-quoting) @@ -363,9 +382,8 @@ This function is explicit for adding to `eshell-parse-argument-hook'." (defun eshell-envvar-names (&optional environment) "Return a list of currently visible environment variable names." - (mapcar (function - (lambda (x) - (substring x 0 (string-match "=" x)))) + (mapcar (lambda (x) + (substring x 0 (string-match "=" x))) (or environment process-environment))) (defun eshell-environment-variables () @@ -444,8 +462,8 @@ Possible options are: (eshell-as-subcommand ,(eshell-parse-command cmd)) (ignore (nconc eshell-this-command-hook - (list (function (lambda () - (delete-file ,temp)))))) + (list (lambda () + (delete-file ,temp))))) (quote ,temp))) (goto-char (1+ end))))))) ((eq (char-after) ?\() @@ -599,14 +617,13 @@ For example, to retrieve the second element of a user's record in (sort (append (mapcar - (function - (lambda (varname) - (let ((value (eshell-get-variable varname))) - (if (and value - (stringp value) - (file-directory-p value)) - (concat varname "/") - varname)))) + (lambda (varname) + (let ((value (eshell-get-variable varname))) + (if (and value + (stringp value) + (file-directory-p value)) + (concat varname "/") + varname))) (eshell-envvar-names (eshell-environment-variables))) (all-completions argname obarray 'boundp) completions) |