X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/14beddf4711854b01d400f36166dc71eb39435bb..d63d883a97e385392a12a5155201417dea7437ec:/lisp/eshell/esh-var.el?ds=sidebyside diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 4c42b305ec..689eb66c97 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -1,6 +1,6 @@ -;;; esh-var.el --- handling of variables +;;; esh-var.el --- handling of variables -*- lexical-binding:t -*- -;; Copyright (C) 1999-2011 Free Software Foundation, Inc. +;; Copyright (C) 1999-2014 Free Software Foundation, Inc. ;; Author: John Wiegley @@ -107,12 +107,11 @@ (provide 'esh-var) -(eval-when-compile - (require 'pcomplete) - (require 'esh-test) - (require 'esh-util) - (require 'esh-opt) - (require 'esh-mode)) +(require 'esh-util) +(require 'esh-cmd) +(require 'esh-opt) + +(require 'pcomplete) (require 'env) (require 'ring) @@ -126,8 +125,9 @@ variable value, a subcommand, or even the result of a Lisp form." ;;; User Variables: -(defcustom eshell-var-load-hook '(eshell-var-initialize) +(defcustom eshell-var-load-hook nil "A list of functions to call when loading `eshell-var'." + :version "24.1" ; removed eshell-var-initialize :type 'hook :group 'eshell-var) @@ -184,9 +184,9 @@ if they are quoted with a backslash." 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 defines the name of a -command, and the Lisp value to return for that variable if it is -accessed via the syntax '$NAME'. +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 @@ -344,15 +344,14 @@ This function is explicit for adding to `eshell-parse-argument-hook'." (pcomplete-here)))) (defun eshell/env (&rest args) - "Implemention of `env' in Lisp." + "Implementation of `env' in Lisp." (eshell-init-print-buffer) (eshell-eval-using-options "env" args '((?h "help" nil nil "show this usage screen") :external "env" :usage "") - (eshell-for setting (sort (eshell-environment-variables) - 'string-lessp) + (dolist (setting (sort (eshell-environment-variables) 'string-lessp)) (eshell-buffered-print setting "\n")) (eshell-flush))) @@ -374,7 +373,7 @@ This function is explicit for adding to `eshell-parse-argument-hook'." This involves setting any variable aliases which affect the environment, as specified in `eshell-variable-aliases-list'." (let ((process-environment (eshell-copy-environment))) - (eshell-for var-alias eshell-variable-aliases-list + (dolist (var-alias eshell-variable-aliases-list) (if (nth 2 var-alias) (setenv (car var-alias) (eshell-stringify @@ -396,12 +395,9 @@ process any indices that come after the variable reference." indices (and (not (eobp)) (eq (char-after) ?\[) (eshell-parse-indices)) - value (list 'let - (list (list 'indices - (list 'quote indices))) - value)) + value `(let ((indices ',indices)) ,value)) (if get-len - (list 'length value) + `(length ,value) value))) (defun eshell-parse-variable-ref () @@ -415,91 +411,68 @@ Possible options are: disambiguates the length of the name {COMMAND} result of command is variable's value (LISP-FORM) result of Lisp form is variable's value" - (let (end) - (cond - ((eq (char-after) ?{) - (let ((end (eshell-find-delimiter ?\{ ?\}))) - (if (not end) - (throw 'eshell-incomplete ?\{) - (prog1 - (list 'eshell-convert - (list 'eshell-command-to-value - (list '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 + (cond + ((eq (char-after) ?{) + (let ((end (eshell-find-delimiter ?\{ ?\}))) + (if (not end) + (throw 'eshell-incomplete ?\{) + (prog1 + (list 'eshell-convert + (list 'eshell-command-to-value + (list '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 (list '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 - (list - 'let (list (list 'eshell-current-handles - (list 'eshell-create-handles temp - (list 'quote 'overwrite)))) - (list - 'progn - (list 'eshell-as-subcommand - (eshell-parse-command cmd)) - (list 'ignore - (list 'nconc 'eshell-this-command-hook - (list 'list - (list 'function - (list 'lambda nil - (list 'delete-file temp)))))) - (list 'quote temp))) - (goto-char (1+ end))))))) - ((eq (char-after) ?\() - (condition-case err - (list 'eshell-command-to-value - (list 'eshell-lisp-command - (list 'quote (read (current-buffer))))) - (end-of-file - (throw 'eshell-incomplete ?\()))) - ((assoc (char-to-string (char-after)) - eshell-variable-aliases-list) - (forward-char) - (list 'eshell-get-variable - (char-to-string (char-before)) 'indices)) - ((looking-at eshell-variable-name-regexp) - (prog1 - (list 'eshell-get-variable (match-string 0) 'indices) - (goto-char (match-end 0)))) - (t - (error "Invalid variable reference"))))) - -(eshell-deftest var interp-cmd - "Interpolate command result" - (eshell-command-result-p "+ ${+ 1 2} 3" "6\n")) - -(eshell-deftest var interp-lisp - "Interpolate Lisp form evalution" - (eshell-command-result-p "+ $(+ 1 2) 3" "6\n")) - -(eshell-deftest var interp-concat - "Interpolate and concat command" - (eshell-command-result-p "+ ${+ 1 2}3 3" "36\n")) - -(eshell-deftest var interp-concat-lisp - "Interpolate and concat Lisp form" - (eshell-command-result-p "+ $(+ 1 2)3 3" "36\n")) - -(eshell-deftest var interp-concat2 - "Interpolate and concat two commands" - (eshell-command-result-p "+ ${+ 1 2}${+ 1 2} 3" "36\n")) + ((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 + (list + 'let (list (list 'eshell-current-handles + (list 'eshell-create-handles temp + (list 'quote 'overwrite)))) + (list + 'progn + (list 'eshell-as-subcommand + (eshell-parse-command cmd)) + (list 'ignore + (list 'nconc 'eshell-this-command-hook + (list 'list + (list 'function + (list 'lambda nil + (list 'delete-file temp)))))) + (list 'quote temp))) + (goto-char (1+ end))))))) + ((eq (char-after) ?\() + (condition-case nil + (list 'eshell-command-to-value + (list 'eshell-lisp-command + (list 'quote (read (current-buffer))))) + (end-of-file + (throw 'eshell-incomplete ?\()))) + ((assoc (char-to-string (char-after)) + eshell-variable-aliases-list) + (forward-char) + (list 'eshell-get-variable + (char-to-string (char-before)) 'indices)) + ((looking-at eshell-variable-name-regexp) + (prog1 + (list 'eshell-get-variable (match-string 0) 'indices) + (goto-char (match-end 0)))) + (t + (error "Invalid variable reference")))) -(eshell-deftest var interp-concat-lisp2 - "Interpolate and concat two Lisp forms" - (eshell-command-result-p "+ $(+ 1 2)$(+ 1 2) 3" "36\n")) +(defvar eshell-glob-function) (defun eshell-parse-indices () "Parse and return a list of list of indices." @@ -529,6 +502,7 @@ Possible options are: (let ((sym (intern-soft var))) (if (and sym (boundp sym) (or eshell-prefer-lisp-variables + (memq sym eshell--local-vars) ; bug#15372 (not (getenv var)))) (symbol-value sym) (getenv var)))) @@ -623,7 +597,7 @@ For example, to retrieve the second element of a user's record in "Generate list of applicable variables." (let ((argname pcomplete-stub) completions) - (eshell-for alias eshell-variable-aliases-list + (dolist (alias eshell-variable-aliases-list) (if (string-match (concat "^" argname) (car alias)) (setq completions (cons (car alias) completions)))) (sort