mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-25 07:28:20 +00:00
Add QUOTED argument to 'eshell-stringify'
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.
This commit is contained in:
parent
08d5994b43
commit
4d69d3778a
@ -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)))
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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."
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user