Function: eshell-apply-indices
eshell-apply-indices is a byte-compiled function defined in
esh-var.el.gz.
Signature
(eshell-apply-indices VALUE INDICES &optional QUOTED)
Documentation
Apply to VALUE all of the given INDICES, returning the sub-result.
The format of INDICES is:
((INT-OR-NAME-OR-OTHER INT-OR-NAME INT-OR-NAME ...)
...)
Each member of INDICES represents a level of nesting. If the first
member of a sublist is not an integer or name, and the value it's
referencing is a string, that will be used as the regexp with which
is to divide the string into sub-parts. The default is whitespace.
Otherwise, each INT-OR-NAME refers to an element of the list value.
Integers imply a direct index, and names, an associate lookup using
assoc.
If QUOTED is non-nil, this was invoked inside double-quotes. This
affects the behavior of splitting strings: without quoting, the split
values are marked as numbers via eshell-mark-numeric-string if
possible; with quoting, they're left as plain strings.
For example, to retrieve the second element of a user's record in
'/etc/passwd', the variable reference would look like:
${grep johnw /etc/passwd}[: 2]
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-var.el.gz
(defun eshell-apply-indices (value indices &optional quoted)
"Apply to VALUE all of the given INDICES, returning the sub-result.
The format of INDICES is:
((INT-OR-NAME-OR-OTHER INT-OR-NAME INT-OR-NAME ...)
...)
Each member of INDICES represents a level of nesting. If the first
member of a sublist is not an integer or name, and the value it's
referencing is a string, that will be used as the regexp with which
is to divide the string into sub-parts. The default is whitespace.
Otherwise, each INT-OR-NAME refers to an element of the list value.
Integers imply a direct index, and names, an associate lookup using
`assoc'.
If QUOTED is non-nil, this was invoked inside double-quotes. This
affects the behavior of splitting strings: without quoting, the split
values are marked as numbers via `eshell-mark-numeric-string' if
possible; with quoting, they're left as plain strings.
For example, to retrieve the second element of a user's record in
'/etc/passwd', the variable reference would look like:
${grep johnw /etc/passwd}[: 2]"
(dolist (refs indices value)
;; For string values, check if the first index looks like a
;; regexp, and if so, use that to split the string.
(when (stringp value)
(let (separator (first (car refs)))
(when (stringp (eshell-parse-index first))
(setq separator first
refs (cdr refs)))
(setq value (split-string value separator))
(unless quoted
(setq value (mapcar #'eshell-mark-numeric-string value)))))
(cond
((< (length refs) 0)
(error "Invalid array variable index: %s"
(eshell-stringify refs)))
((= (length refs) 1)
(setq value (eshell-index-value value (car refs))))
(t
(let (new-value)
(dolist (ref refs)
(push (eshell-index-value value ref) new-value))
(setq value (nreverse new-value)))))))