Function: eshell-convert

eshell-convert is a byte-compiled function defined in esh-util.el.gz.

Signature

(eshell-convert STRING &optional TO-STRING)

Documentation

Convert STRING into a more-native Lisp object.

If TO-STRING is non-nil, always return a single string with trailing newlines removed. Otherwise, this behaves as follows:

* Return non-strings as-is.

* Split multiline strings by line.

* If eshell-convert-numeric-arguments is non-nil and every line
  of output looks like a number, convert them to numbers.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-util.el.gz
(defun eshell-convert (string &optional to-string)
  "Convert STRING into a more-native Lisp object.
If TO-STRING is non-nil, always return a single string with
trailing newlines removed.  Otherwise, this behaves as follows:

* Return non-strings as-is.

* Split multiline strings by line.

* If `eshell-convert-numeric-arguments' is non-nil and every line
  of output looks like a number, convert them to numbers."
  (cond
   ((not (stringp string))
    (if to-string
        (eshell-stringify string t)
      string))
   (to-string (string-trim-right string "\n+"))
   (t (let ((len (length string)))
        (if (= len 0)
	    string
	  (when (eq (aref string (1- len)) ?\n)
	    (setq string (substring string 0 (1- len))))
          (if (string-search "\n" string)
              (let ((lines (split-string string "\n")))
                (when (seq-every-p #'eshell-convertible-to-number-p lines)
                  (mapc #'eshell--do-mark-numeric-string lines))
                lines)
            (eshell-mark-numeric-string string)))))))