From 1e53bb4bf2754c724bcb894e730fd77e25dae80c Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 14 Sep 2013 17:10:45 -0700 Subject: [PATCH] * lisp/eshell/esh-cmd.el (eshell--local-vars): New variable. (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 | 6 ++++++ lisp/eshell/esh-cmd.el | 6 +++++- lisp/eshell/esh-var.el | 1 + test/ChangeLog | 6 ++++++ test/automated/eshell.el | 10 ++++++++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8384f53d946..f63a0d6681f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-09-15 Glenn Morris + + * 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 * eshell/esh-var.el (eshell-variable-aliases-list): Fix doc typo. diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index cc4fdd15bda..75e0e1d27c8 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -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)) diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 8dd19618da2..3121dadace2 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -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)))) diff --git a/test/ChangeLog b/test/ChangeLog index 21b22425fb6..85119db69f2 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2013-09-15 Glenn Morris + + * 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 * automated/eshell.el (with-temp-eshell): diff --git a/test/automated/eshell.el b/test/automated/eshell.el index b9eb31660f1..6f7a35371a6 100644 --- a/test/automated/eshell.el +++ b/test/automated/eshell.el @@ -75,17 +75,23 @@ (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 -- 2.39.2