master bb2e759b574 2/8: New 'eshell-convert-args' utility function

Jim Porter <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit bb2e759b57436e81a814b2b8e3e397a59e6becad
Author: Jim Porter <[email protected]>
Commit: Jim Porter <[email protected]>

    New 'eshell-convert-args' utility function
    
    * lisp/eshell/esh-cmd.el (eshell-lisp-command): Extract from here...
    * lisp/eshell/esh-util.el (eshell-convert-args): ... to this new
    function.
---
 lisp/eshell/esh-cmd.el  | 25 +++++--------------------
 lisp/eshell/esh-util.el | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 5292acb964a..f4f593fde90 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1582,31 +1582,16 @@ a string naming a Lisp function."
   (catch 'eshell-external               ; deferred to an external command
     (when (memq eshell-in-pipeline-p '(nil last))
       (eshell-set-exit-info 0))
-    (setq eshell-last-arguments args)
     (let* ((eshell-ensure-newline-p t)
            (command-form-p (and (functionp object)
                                 (symbolp object)))
            result)
       (if command-form-p
-          (let ((numeric (not (get object 'eshell-no-numeric-conversions)))
-                (fname-args (get object 'eshell-filename-arguments)))
-            (when (or numeric fname-args)
-              (while args
-                (let ((arg (car args)))
-                  (cond
-                   ((and numeric (eshell--numeric-string-p arg))
-                    ;; If any of the arguments are flagged as numbers
-                    ;; waiting for conversion, convert them now.
-                    (setcar args (string-to-number arg)))
-                   ((and fname-args (stringp arg)
-                         (string-equal arg "~"))
-                    ;; If any of the arguments match "~", prepend "./"
-                    ;; to treat it as a regular file name.
-                    (setcar args (concat "./" arg)))))
-                (setq args (cdr args))))
-            (setq eshell-last-command-name
-                  (concat "#<function " (symbol-name object) ">")))
-        (setq eshell-last-command-name "#<Lisp object>"))
+          (setq eshell-last-arguments (eshell-convert-args args object)
+                eshell-last-command-name (format "#<function %s>"
+                                                 (symbol-name object)))
+        (setq eshell-last-arguments args
+              eshell-last-command-name "#<Lisp object>"))
       (setq result (eshell-exec-lisp
                     #'eshell-print-maybe-n #'eshell-error-maybe-n
                     object eshell-last-arguments (not command-form-p)))
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index c9264602d0f..7fca9635c78 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -429,6 +429,31 @@ trailing newlines removed.  Otherwise, this behaves as follows:
                 lines)
             (eshell-mark-numeric-string string)))))))
 
+(defun eshell-convert-args (args function)
+  "Convert ARGS to their preferred forms when calling FUNCTION.
+This consults the properties `eshell-no-numeric-conversions' and
+`eshell-filename-arguments' on FUNCTION to determine the appropriate
+conversions to apply to each string argument in ARGS."
+  (or (when (symbolp function)
+        (let ((numeric (not (get function 'eshell-no-numeric-conversions)))
+              (fname-args (get function 'eshell-filename-arguments)))
+          (when (or numeric fname-args)
+            (mapcar (lambda (arg)
+                      (cond
+                       ((and numeric (eshell--numeric-string-p arg))
+                        ;; If any of the arguments are flagged as numbers
+                        ;; waiting for conversion, convert them now.
+                        (string-to-number arg))
+                       ((and fname-args (stringp arg)
+                             (string-equal arg "~"))
+                        ;; If any of the arguments match "~", prepend "./"
+                        ;; to treat it as a regular file name.
+                        (concat "./" arg))
+                       (t
+                        arg)))
+                    args))))
+      args))
+
 (defvar-local eshell-path-env (getenv "PATH")
   "Content of $PATH.
 It might be different from \(getenv \"PATH\"), when
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.