Further improvement for non-string values in pcomplete

* lisp/pcomplete.el (pcomplete-arg): Use the string representation
of the argument value instead of the text representation of the
argument.  Return the value, even when it is not a string, when
index is 'last'.  Fixes bug#60464.
This commit is contained in:
Gregory Heytings 2023-01-04 16:48:03 +00:00
parent 1ef359095e
commit 72c45fa910

View file

@ -632,6 +632,13 @@ This will modify the current buffer."
;;; Internal Functions:
;; argument handling
(defsubst pcomplete-actual-arg (&optional index offset)
"Return the actual text representation of the last argument.
This is different from `pcomplete-arg', which returns the textual value
that the last argument evaluated to. This function returns what the
user actually typed in."
(buffer-substring (pcomplete-begin index offset) (point)))
(defun pcomplete-arg (&optional index offset)
"Return the textual content of the INDEXth argument.
INDEX is based from the current processing position. If INDEX is
@ -659,11 +666,20 @@ the pcomplete-arg-value text property of that string."
(_ (- pcomplete-index (or index 0))))
(or offset 0))
pcomplete-args)))
(if (stringp arg)
(if (or (stringp arg)
;; FIXME: 'last' is handled specially in Emacs 29, because
;; 'pcomplete-parse-arguments' accepts a list of strings
;; (which are completion candidates) as return value for
;; (pcomplete-arg 'last). See below: "it means it's a
;; list of completions computed during parsing,
;; e.g. Eshell uses that to turn globs into lists of
;; completions". This special case will be dealt with
;; differently in Emacs 30: the pcomplete-arg-value
;; property will be used by 'pcomplete-parse-arguments'.
(eq index 'last))
arg
(propertize
(buffer-substring (pcomplete-begin index offset)
(pcomplete-begin (1- (or index 0)) offset))
(car (split-string (pcomplete-actual-arg index offset)))
'pcomplete-arg-value arg))))
(defun pcomplete-begin (&optional index offset)
@ -679,13 +695,6 @@ See the documentation for `pcomplete-arg'."
(setq index (+ index offset)))
(nth index pcomplete-begins))
(defsubst pcomplete-actual-arg (&optional index offset)
"Return the actual text representation of the last argument.
This is different from `pcomplete-arg', which returns the textual value
that the last argument evaluated to. This function returns what the
user actually typed in."
(buffer-substring (pcomplete-begin index offset) (point)))
(defsubst pcomplete-next-arg ()
"Move the various pointers to the next argument."
(setq pcomplete-index (1+ pcomplete-index)