Function: load-path-filter-cache-directory-files
load-path-filter-cache-directory-files is a byte-compiled function
defined in startup.el.gz.
Signature
(load-path-filter-cache-directory-files PATH FILE SUFFIXES)
Documentation
Filter PATH to leave only directories which might contain FILE with SUFFIXES.
PATH should be a list of directories such as load-path.
Returns a copy of PATH with any directories that cannot contain FILE
with SUFFIXES removed from it.
Doesn't filter PATH if FILE is an absolute file name or if FILE is
a relative file name with leading directories.
Caches contents of directories in load-path-filter--cache.
This function is called from load via load-path-filter-function.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/startup.el.gz
(defun load-path-filter-cache-directory-files (path file suffixes)
"Filter PATH to leave only directories which might contain FILE with SUFFIXES.
PATH should be a list of directories such as `load-path'.
Returns a copy of PATH with any directories that cannot contain FILE
with SUFFIXES removed from it.
Doesn't filter PATH if FILE is an absolute file name or if FILE is
a relative file name with leading directories.
Caches contents of directories in `load-path-filter--cache'.
This function is called from `load' via `load-path-filter-function'."
(if (file-name-directory file)
;; FILE has more than one component, don't bother filtering.
path
(pcase-let
((`(,rx . ,ht)
(with-memoization (alist-get suffixes load-path-filter--cache
nil nil #'equal)
(if (member "" suffixes)
'(nil ;; Optimize the filtering.
;; Don't bother filtering if "" is among the suffixes.
;; It's a much less common use-case and it would use
;; more memory to keep the corresponding info.
. nil)
(cons (concat (regexp-opt suffixes) "\\'")
(make-hash-table :test #'equal))))))
(if (null ht)
path
(let ((completion-regexp-list nil))
(seq-filter
(lambda (dir)
(when (file-directory-p dir)
(try-completion
file
(with-memoization (gethash dir ht)
(directory-files dir nil rx t)))))
path))))))