summaryrefslogtreecommitdiff
path: root/lisp/pcomplete.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-06-05 19:51:29 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2022-06-05 19:51:29 -0400
commit0a36671f415bd681ddca0bad8612aca031fd407d (patch)
tree6a51c6df72dffcf2aa73458b7f3f9775a11a7c51 /lisp/pcomplete.el
parentf5e8e7a7b9db94092503e35be3a3501905798ed5 (diff)
downloademacs-0a36671f415bd681ddca0bad8612aca031fd407d.tar.gz
pcomplete.el: Fix part of bug#50470
Try and handle the case where `pcomplete-parse-arguments-function` directly returns a list of completions. * lisp/pcomplete.el (pcomplete-parse-arguments): Don't modify the buffer if we're not allowed to. Instead use the buffer's current content as the "pattern to be completed" and return the list of completions as is. Also, use `try-completions` to simplify the previous code.
Diffstat (limited to 'lisp/pcomplete.el')
-rw-r--r--lisp/pcomplete.el43
1 files changed, 24 insertions, 19 deletions
diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el
index a1492af89d2..3393c322e30 100644
--- a/lisp/pcomplete.el
+++ b/lisp/pcomplete.el
@@ -802,25 +802,30 @@ this is `comint-dynamic-complete-functions'."
(let ((begin (pcomplete-begin 'last)))
(if (and (listp pcomplete-stub) ;??
(not pcomplete-expand-only-p))
- (let* ((completions pcomplete-stub) ;??
- (common-stub (car completions))
- (c completions)
- (len (length common-stub)))
- (while (and c (> len 0))
- (while (and (> len 0)
- (not (string=
- (substring common-stub 0 len)
- (substring (car c) 0
- (min (length (car c))
- len)))))
- (setq len (1- len)))
- (setq c (cdr c)))
- (setq pcomplete-stub (substring common-stub 0 len)
- pcomplete-autolist t)
- (when (and begin (> len 0) (not pcomplete-show-list))
- (delete-region begin (point))
- (pcomplete-insert-entry "" pcomplete-stub))
- (throw 'pcomplete-completions completions))
+ ;; If `pcomplete-stub' is a list, it means it's a list of
+ ;; completions computed during parsing, e.g. Eshell uses
+ ;; that to turn globs into lists of completions.
+ (if (not pcomplete-allow-modifications)
+ (progn
+ ;; FIXME: The mapping from what's in the buffer to the list
+ ;; of completions can be arbitrary and will often fail to be
+ ;; understood by the completion style. See bug#50470.
+ ;; E.g. `pcomplete-stub' may end up being "~/Down*"
+ ;; while the completions contain entries like
+ ;; "/home/<foo>/Downloads" which will fail to match the
+ ;; "~/Down*" completion pattern since the completion
+ ;; is neither told that it's a file nor a global pattern.
+ (setq pcomplete-stub (buffer-substring begin (point)))
+ (throw 'pcomplete-completions pcomplete-stub))
+ (let* ((completions pcomplete-stub)
+ (common-prefix (try-completion "" completions))
+ (len (length common-prefix)))
+ (setq pcomplete-stub common-prefix
+ pcomplete-autolist t)
+ (when (and begin (> len 0) (not pcomplete-show-list))
+ (delete-region begin (point))
+ (pcomplete-insert-entry "" pcomplete-stub))
+ (throw 'pcomplete-completions completions)))
(when expand-p
(if (stringp pcomplete-stub)
(when begin