From 72c45fa9109a53cb55d13697d69e9a32a7e289b5 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Wed, 4 Jan 2023 16:48:03 +0000 Subject: [PATCH] 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. --- lisp/pcomplete.el | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 5bee5152463..1ca7a213361 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -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) -- 2.39.2