* lisp/eshell/esh-cmd.el (eshell--local-vars): New variable.
authorGlenn Morris <rgm@gnu.org>
Sun, 15 Sep 2013 00:10:45 +0000 (17:10 -0700)
committerGlenn Morris <rgm@gnu.org>
Sun, 15 Sep 2013 00:10:45 +0000 (17:10 -0700)
(eshell-rewrite-for-command): Add for loop vars to eshell--local-vars.

* lisp/eshell/esh-var.el (eshell-get-variable): Respect eshell--local-vars.

* test/automated/eshell.el (eshell-test/for-name-shadow-loop):
New test.
(eshell-test/for-loop, eshell-test/for-name-loop): Doc fix.

Fixes: debbugs:15372

lisp/ChangeLog
lisp/eshell/esh-cmd.el
lisp/eshell/esh-var.el
test/ChangeLog
test/automated/eshell.el

index 8384f53..f63a0d6 100644 (file)
@@ -1,3 +1,9 @@
+2013-09-15  Glenn Morris  <rgm@gnu.org>
+
+       * eshell/esh-cmd.el (eshell--local-vars): New variable.  (Bug#15372)
+       (eshell-rewrite-for-command): Add for loop vars to eshell--local-vars.
+       * eshell/esh-var.el (eshell-get-variable): Respect eshell--local-vars.
+
 2013-09-14  Glenn Morris  <rgm@gnu.org>
 
        * eshell/esh-var.el (eshell-variable-aliases-list): Fix doc typo.
index cc4fdd1..75e0e1d 100644 (file)
@@ -473,6 +473,8 @@ the second is ignored."
     arg))
 
 (defvar eshell-last-command-status)     ;Define in esh-io.el.
+(defvar eshell--local-vars nil
+  "List of locally bound vars that should take precedence over env-vars.")
 
 (defun eshell-rewrite-for-command (terms)
   "Rewrite a `for' command into its equivalent Eshell command form.
@@ -495,7 +497,9 @@ implemented via rewriting, rather than as a function."
               (eshell-command-body '(nil))
                (eshell-test-body '(nil)))
           (while (car for-items)
-            (let ((,(intern (cadr terms)) (car for-items)))
+            (let ((,(intern (cadr terms)) (car for-items))
+                  (eshell--local-vars (cons ',(intern (cadr terms))
+                                           eshell--local-vars)))
               (eshell-protect
                ,(eshell-invokify-arg body t)))
             (setcar for-items (cadr for-items))
index 8dd1961..3121dad 100644 (file)
@@ -502,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))))
index 21b2242..85119db 100644 (file)
@@ -1,3 +1,9 @@
+2013-09-15  Glenn Morris  <rgm@gnu.org>
+
+       * automated/eshell.el (eshell-test/for-name-shadow-loop):
+       New test.  (Bug#15372)
+       (eshell-test/for-loop, eshell-test/for-name-loop): Doc fix.
+
 2013-09-13  Glenn Morris  <rgm@gnu.org>
 
        * automated/eshell.el (with-temp-eshell):
index b9eb316..6f7a353 100644 (file)
   (should (equal (eshell-test-command-result "(+ 1 2)") 3)))
 
 (ert-deftest eshell-test/for-loop ()
-  "Test `eshell-command-result' with an elisp command."
+  "Test `eshell-command-result' with a for loop.."
   (let ((process-environment (cons "foo" process-environment)))
     (should (equal (eshell-test-command-result
                     "for foo in 5 { echo $foo }") 5))))
 
 (ert-deftest eshell-test/for-name-loop () ;Bug#15231
-  "Test `eshell-command-result' with an elisp command."
+  "Test `eshell-command-result' with a for loop using `name'."
   (let ((process-environment (cons "name" process-environment)))
     (should (equal (eshell-test-command-result
                     "for name in 3 { echo $name }") 3))))
 
+(ert-deftest eshell-test/for-name-shadow-loop () ; bug#15372
+  "Test `eshell-command-result' with a for loop using an env-var."
+  (let ((process-environment (cons "name=env-value" process-environment)))
+    (should (equal (eshell-test-command-result
+                    "for name in 3 { echo $name }") 3))))
+
 (ert-deftest eshell-test/lisp-command-args ()
   "Test `eshell-command-result' with elisp and trailing args.
 Test that trailing arguments outside the S-expression are