Function: eshell-parse-index

eshell-parse-index is a byte-compiled function defined in esh-var.el.gz.

Signature

(eshell-parse-index INDEX)

Documentation

Parse a single INDEX in string form.

If INDEX looks like a number, return that number.

If INDEX looks like "[BEGIN]..[END]", where BEGIN and END look like integers, return a cons cell of BEGIN and END as numbers; BEGIN and/or END can be omitted here, in which case their value in the cons is nil.

Otherwise (including if INDEX is not a string), return the original value of INDEX.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-var.el.gz
(defun eshell-parse-index (index)
  "Parse a single INDEX in string form.
If INDEX looks like a number, return that number.

If INDEX looks like \"[BEGIN]..[END]\", where BEGIN and END look
like integers, return a cons cell of BEGIN and END as numbers;
BEGIN and/or END can be omitted here, in which case their value
in the cons is nil.

Otherwise (including if INDEX is not a string), return
the original value of INDEX."
  (save-match-data
    (cond
     ((and (stringp index) (get-text-property 0 'number index))
      (string-to-number index))
     ((and (stringp index)
           (not (text-property-any 0 (length index) 'escaped t index))
           (string-match (rx string-start
                             (group-n 1 (? (regexp eshell-integer-regexp)))
                             ".."
                             (group-n 2 (? (regexp eshell-integer-regexp)))
                             string-end)
                         index))
      (let ((begin (match-string 1 index))
            (end (match-string 2 index)))
        (cons (unless (string-empty-p begin) (string-to-number begin))
              (unless (string-empty-p end) (string-to-number end)))))
     (t
      index))))