pcomplete--entries: In predicate, check file exists

* lisp/pcomplete.el (pcomplete--entries): In the predicate passed to
completion-table-with-predicate, when PREDICATE is nil, take ourselves
to be responsible for calling file-exists-p (bug#67661).
This commit is contained in:
Sean Whitton 2023-12-29 17:41:35 +00:00
parent b0bead793f
commit d7ff14fcba

View file

@ -902,14 +902,16 @@ this is `comint-dynamic-complete-functions'."
(and dir-ignore (string-match dir-ignore file))
(and file-ignore (string-match file-ignore file))))))))
(reg-pred (if regexp (lambda (file) (string-match regexp file))))
(pred (cond
((null (or ign-pred reg-pred)) predicate)
((null (or ign-pred predicate)) reg-pred)
((null (or reg-pred predicate)) ign-pred)
(t (lambda (f)
;; `completion-file-name-table' calls `file-exists-p' when
;; the predicate is nil.
;; So likewise, defer to PREDICATE if it's there, else take
;; ourselves to be responsible for calling `file-exists-p'.
(pred (if (or ign-pred reg-pred)
(lambda (f)
(and (or (null reg-pred) (funcall reg-pred f))
(or (null ign-pred) (funcall ign-pred f))
(or (null predicate) (funcall predicate f))))))))
(funcall (or predicate #'file-exists-p) f)))
predicate)))
(lambda (s p a)
(if (and (eq a 'metadata) pcomplete-compare-entry-function)
`(metadata (cycle-sort-function