]> git.eshelyaron.com Git - emacs.git/commitdiff
Add QUOTED argument to 'eshell-stringify'
authorJim Porter <jporterbugs@gmail.com>
Sun, 20 Oct 2024 22:30:19 +0000 (15:30 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 8 Nov 2024 13:30:31 +0000 (14:30 +0100)
This will make it easier to reconstitute numbers that we converted to
strings.

* lisp/eshell/esh-util.el (eshell--numeric-string-p): New function.
(eshell-stringify, eshell-stringify-list): Add QUOTED argument.
(eshell-convert, eshell-list-to-string): Stringify as quoted.

* lisp/eshell/esh-arg.el (eshell--numberlike-p): Remove.
(eshell-concat-1): Pass along QUOTED.

* lisp/eshell/esh-cmd.el (eshell-lisp-command): Use
'eshell--numeric-string-p'.

* lisp/eshell/esh-var.el (eshell-parse-variable):
* lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): Stringify as
quoted.

(cherry picked from commit 4d69d3778a51427654965cbcc5bb03611034b656)

lisp/eshell/em-cmpl.el
lisp/eshell/esh-arg.el
lisp/eshell/esh-cmd.el
lisp/eshell/esh-util.el
lisp/eshell/esh-var.el

index 4c79f7b187a85978fe8ccf8208f7095e6deaa91f..ef931db62b206e0030a0e8992d3da5812781aa80 100644 (file)
@@ -444,7 +444,7 @@ to writing a completion function."
                ('nil
                 (propertize "" 'pcomplete-arg-value arg))
                (_
-                (propertize (eshell-stringify arg)
+                (propertize (eshell-stringify arg t)
                             'pcomplete-arg-value arg))))
           args)
          posns)))
index 4ea25f7f2027743dfc7737ea1c1755f2022ccb17..4f8119670d2a38dfebbb8a1611d2dda52afd529d 100644 (file)
@@ -239,19 +239,16 @@ would produce (\"abc\" \"d\")."
          (t
           (setq result (eshell-concat-1 quoted result i))))))))
 
-(defsubst eshell--numberlike-p (object)
-  (or (numberp object)
-      (and (stringp object) (get-text-property 0 'number object))))
-
 (defun eshell-concat-1 (quoted first second)
   "Concatenate FIRST and SECOND.
 If QUOTED is nil and either FIRST or SECOND are numberlike, try to mark
 the result as a number as well."
-  (let ((result (concat (eshell-stringify first) (eshell-stringify second))))
+  (let ((result (concat (eshell-stringify first quoted)
+                        (eshell-stringify second quoted))))
     (remove-text-properties 0 (length result) '(number) result)
     (when (and (not quoted)
-               (or (eshell--numberlike-p first)
-                   (eshell--numberlike-p second)))
+               (or (numberp first)  (eshell--numeric-string-p first)
+                   (numberp second) (eshell--numeric-string-p second)))
       (eshell-mark-numeric-string result))
     result))
 
index 88d9c0affef45c4881e0103113c54b37a3f79c86..441a39ac86ab17ee0d65d1c2f3f3b1d8de5b54de 100644 (file)
@@ -1577,9 +1577,7 @@ a string naming a Lisp function."
                     (while args
                       (let ((arg (car args)))
                         (cond
-                         ((and numeric (stringp arg) (> (length arg) 0)
-                               (text-property-any 0 (length arg)
-                                                  'number t arg))
+                         ((and numeric (eshell--numeric-string-p arg))
                           ;; If any of the arguments are flagged as
                           ;; numbers waiting for conversion, convert
                           ;; them now.
index 65e19228e0e04ec03989382288d4ff2cac7b6cde..de3f86ccae4e3d1235ef661f56175468c7fe572f 100644 (file)
@@ -353,6 +353,12 @@ See `eshell-convertible-to-number-p'."
     (eshell--do-mark-numeric-string string))
   string)
 
+(defsubst eshell--numeric-string-p (string)
+  "Return non-nil if STRING has been marked as numeric."
+  (and (stringp string)
+       (length> string 0)
+       (not (text-property-not-all 0 (length string) 'number t string))))
+
 (defun eshell-convert-to-number (string)
   "Try to convert STRING to a number.
 If STRING doesn't look like a number (or
@@ -377,7 +383,7 @@ trailing newlines removed.  Otherwise, this behaves as follows:
   (cond
    ((not (stringp string))
     (if to-string
-        (eshell-stringify string)
+        (eshell-stringify string t)
       string))
    (to-string (string-trim-right string "\n+"))
    (t (let ((len (length string)))
@@ -499,25 +505,27 @@ Prepend remote identification of `default-directory', if any."
 
 (define-obsolete-function-alias 'eshell-flatten-list #'flatten-tree "27.1")
 
-(defun eshell-stringify (object)
+(defun eshell-stringify (object &optional quoted)
   "Convert OBJECT into a string value."
   (cond
    ((stringp object) object)
    ((numberp object)
-    (number-to-string object))
+    (if quoted
+        (number-to-string object)
+      (propertize (number-to-string object) 'number t)))
    ((and (eq object t)
         (not eshell-stringify-t))
     nil)
    (t
     (string-trim-right (pp-to-string object)))))
 
-(defsubst eshell-stringify-list (args)
+(defsubst eshell-stringify-list (args &optional quoted)
   "Convert each element of ARGS into a string value."
-  (mapcar #'eshell-stringify args))
+  (mapcar (lambda (i) (eshell-stringify i quoted)) args))
 
 (defsubst eshell-list-to-string (list)
   "Convert LIST into a single string separated by spaces."
-  (mapconcat #'eshell-stringify list " "))
+  (mapconcat (lambda (i) (eshell-stringify i t)) list " "))
 
 (defsubst eshell-flatten-and-stringify (&rest args)
   "Flatten and stringify all of the ARGS into a single string."
index e3ff76abc26525238ee775734b5c77c4c502ad03..bf474c5e279fdc3bd8c8724d834106265f32ec62 100644 (file)
@@ -495,7 +495,7 @@ process any indices that come after the variable reference."
       (if splice
           (setq value `(eshell-list-to-string ,value)
                 splice nil)
-        (setq value `(eshell-stringify ,value))))
+        (setq value `(eshell-stringify ,value t))))
     (setq value `(eshell-escape-arg ,value))
     (when splice
       (setq value `(eshell-splice-args ,value)))