[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ba1923f1f1 2/3: Allow Eshell variable aliases to point to other a
From: |
Lars Ingebrigtsen |
Subject: |
master ba1923f1f1 2/3: Allow Eshell variable aliases to point to other aliases |
Date: |
Tue, 12 Jul 2022 09:12:05 -0400 (EDT) |
branch: master
commit ba1923f1f1bba69bc13620042a00e315946ba82a
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow Eshell variable aliases to point to other aliases
In particular, this resolves an issue where '$+' referenced the real
environment variable '$PWD' instead of the Eshell variable alias of
the same name. This meant that changing directories in Eshell
wouldn't update the value of '$+'.
* lisp/eshell/esh-var.el (eshell-get-variable): Allow Eshell variable
aliaes to point to other aliases.
* test/lisp/eshell/em-dirs-tests.el (em-dirs-test/pwd-var)
(em-dirs-test/short-pwd-var): Adapt tests to check this case
(bug#56509).
---
lisp/eshell/esh-var.el | 41 +++++++++++++++++++--------------------
test/lisp/eshell/em-dirs-tests.el | 10 ++++++----
2 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 5092d2c6a5..e1535c1c5d 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -549,27 +549,26 @@ For example, \"[0 1][2]\" becomes:
"Get the value for the variable NAME.
INDICES is a list of index-lists (see `eshell-parse-indices').
If QUOTED is non-nil, this was invoked inside double-quotes."
- (let* ((alias (assoc name eshell-variable-aliases-list))
- (var (if alias
- (cadr alias)
- name)))
- (if (and alias (functionp var))
- (funcall var indices)
- (eshell-apply-indices
- (cond
- ((stringp var)
- (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))))
- ((symbolp var)
- (symbol-value var))
- (t
- (error "Unknown variable `%s'" (eshell-stringify var))))
- indices quoted))))
+ (if-let ((alias (assoc name eshell-variable-aliases-list)))
+ (let ((target (cadr alias)))
+ (cond
+ ((functionp target)
+ (funcall target indices))
+ ((symbolp target)
+ (eshell-apply-indices (symbol-value target) indices quoted))
+ (t
+ (eshell-get-variable target indices quoted))))
+ (unless (stringp name)
+ (error "Unknown variable `%s'" (eshell-stringify name)))
+ (eshell-apply-indices
+ (let ((sym (intern-soft name)))
+ (if (and sym (boundp sym)
+ (or eshell-prefer-lisp-variables
+ (memq sym eshell--local-vars) ; bug#15372
+ (not (getenv name))))
+ (symbol-value sym)
+ (getenv name)))
+ indices quoted)))
(defun eshell-apply-indices (value indices &optional quoted)
"Apply to VALUE all of the given INDICES, returning the sub-result.
diff --git a/test/lisp/eshell/em-dirs-tests.el
b/test/lisp/eshell/em-dirs-tests.el
index eb27acd208..69480051e4 100644
--- a/test/lisp/eshell/em-dirs-tests.el
+++ b/test/lisp/eshell/em-dirs-tests.el
@@ -36,13 +36,15 @@
(ert-deftest em-dirs-test/pwd-var ()
"Test using the $PWD variable."
- (should (equal (eshell-test-command-result "echo $PWD")
- (expand-file-name (eshell/pwd)))))
+ (let ((default-directory "/some/path"))
+ (should (equal (eshell-test-command-result "echo $PWD")
+ (expand-file-name default-directory)))))
(ert-deftest em-dirs-test/short-pwd-var ()
"Test using the $+ (current directory) variable."
- (should (equal (eshell-test-command-result "echo $+")
- (expand-file-name (eshell/pwd)))))
+ (let ((default-directory "/some/path"))
+ (should (equal (eshell-test-command-result "echo $+")
+ (expand-file-name default-directory)))))
(ert-deftest em-dirs-test/oldpwd-var ()
"Test using the $OLDPWD variable."