Function: pcomplete-entries
pcomplete-entries is a byte-compiled function defined in
pcomplete.el.gz.
Signature
(pcomplete-entries &optional REGEXP PREDICATE)
Documentation
Complete against a list of directory candidates.
If REGEXP is non-nil, it is a regular expression used to refine the
match (files not matching the REGEXP will be excluded).
If PREDICATE is non-nil, it will also be used to refine the match
(files for which the PREDICATE returns nil will be excluded).
If no directory information can be extracted from the completed
component, default-directory is used as the basis for completion.
Source Code
;; Defined in /usr/src/emacs/lisp/pcomplete.el.gz
(defun pcomplete-entries (&optional regexp predicate)
"Complete against a list of directory candidates.
If REGEXP is non-nil, it is a regular expression used to refine the
match (files not matching the REGEXP will be excluded).
If PREDICATE is non-nil, it will also be used to refine the match
\(files for which the PREDICATE returns nil will be excluded).
If no directory information can be extracted from the completed
component, `default-directory' is used as the basis for completion."
;; FIXME: The old code did env-var expansion here, so we reproduce this
;; behavior for now, but really env-var handling should be performed globally
;; rather than here since it also applies to non-file arguments.
(let ((table (pcomplete--entries regexp predicate)))
(lambda (string pred action)
(let ((strings nil)
(orig-length (length string)))
;; Perform env-var expansion.
(while (string-match pcomplete--env-regexp string)
(push (substring string 0 (match-beginning 1)) strings)
(push (getenv (match-string 2 string)) strings)
(setq string (substring string (match-end 1))))
(if (not (and strings
(or (eq action t)
(eq (car-safe action) 'boundaries))))
(let ((newstring
(mapconcat #'identity (nreverse (cons string strings)) "")))
;; FIXME: We could also try to return unexpanded envvars.
(complete-with-action action table newstring pred))
(let* ((envpos (apply #'+ (mapcar #' length strings)))
(newstring
(mapconcat #'identity (nreverse (cons string strings)) ""))
(bounds (completion-boundaries newstring table pred
(or (cdr-safe action) ""))))
(if (>= (car bounds) envpos)
;; The env-var is "out of bounds".
(if (eq action t)
(complete-with-action action table newstring pred)
`(boundaries
,(+ (car bounds) (- orig-length (length newstring)))
. ,(cdr bounds)))
;; The env-var is in the file bounds.
(if (eq action t)
(let ((comps (complete-with-action
action table newstring pred))
(len (- envpos (car bounds))))
;; Strip the part of each completion that's actually
;; coming from the env-var.
(mapcar (lambda (s) (substring s len)) comps))
`(boundaries
,(+ envpos (- orig-length (length newstring)))
. ,(cdr bounds))))))))))