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 converted to numbers via
eshell-convert-to-number if possible; with quoting, they're
left as 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 converted to numbers via
`eshell-convert-to-number' if possible; with quoting, they're
left as 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]"
(while indices
(let ((refs (car indices)))
(when (stringp value)
(let (separator (index (caar indices)))
(when (and (stringp index)
(not (get-text-property 0 'number index)))
(setq separator index
refs (cdr refs)))
(setq value (split-string value separator))
(unless quoted
(setq value (mapcar #'eshell-convert-to-number 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 (list t)))
(while refs
(nconc new-value
(list (eshell-index-value value
(car refs))))
(setq refs (cdr refs)))
(setq value (cdr new-value))))))
(setq indices (cdr indices)))
value)