aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell
diff options
context:
space:
mode:
authorJim Porter2022-09-13 16:14:00 -0700
committerJim Porter2022-09-14 17:27:21 -0700
commitb8e9239b47391c6628d94a4e2e91320c5366d27b (patch)
tree9c36827e8763f35d18984ee41c00dd02715729c0 /lisp/eshell
parent30ca49c8f64b73f991d94b10afcfc0e2d592fe6a (diff)
downloademacs-b8e9239b47391c6628d94a4e2e91320c5366d27b.tar.gz
emacs-b8e9239b47391c6628d94a4e2e91320c5366d27b.zip
Allow using a symbol as an index into an alist in Eshell
* lisp/eshell/esh-var.el (eshell-index-value): If INDEX is a symbol, use 'assoc' for indexing. * test/lisp/eshell/esh-var-tests.el (esh-var-test/interp-var-assoc) (esh-var-test/quoted-interp-var-assoc): Add checks for indexing via symbol (bug#57787).
Diffstat (limited to 'lisp/eshell')
-rw-r--r--lisp/eshell/esh-var.el35
1 files changed, 18 insertions, 17 deletions
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index a9df172e88e..36e59cd5a41 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -646,23 +646,24 @@ For example, to retrieve the second element of a user's record in
646 "Reference VALUE using the given INDEX." 646 "Reference VALUE using the given INDEX."
647 (when (and (stringp index) (get-text-property 0 'number index)) 647 (when (and (stringp index) (get-text-property 0 'number index))
648 (setq index (string-to-number index))) 648 (setq index (string-to-number index)))
649 (if (stringp index) 649 (if (integerp index)
650 (cdr (assoc index value)) 650 (cond
651 (cond 651 ((ring-p value)
652 ((ring-p value) 652 (if (> index (ring-length value))
653 (if (> index (ring-length value)) 653 (error "Index exceeds length of ring")
654 (error "Index exceeds length of ring") 654 (ring-ref value index)))
655 (ring-ref value index))) 655 ((listp value)
656 ((listp value) 656 (if (> index (length value))
657 (if (> index (length value)) 657 (error "Index exceeds length of list")
658 (error "Index exceeds length of list") 658 (nth index value)))
659 (nth index value))) 659 ((vectorp value)
660 ((vectorp value) 660 (if (> index (length value))
661 (if (> index (length value)) 661 (error "Index exceeds length of vector")
662 (error "Index exceeds length of vector") 662 (aref value index)))
663 (aref value index))) 663 (t
664 (t 664 (error "Invalid data type for indexing")))
665 (error "Invalid data type for indexing"))))) 665 ;; INDEX is some non-integer value, so treat VALUE as an alist.
666 (cdr (assoc index value))))
666 667
667;;;_* Variable name completion 668;;;_* Variable name completion
668 669