Function: project--read-file-cpd-relative
project--read-file-cpd-relative is a byte-compiled function defined in
project.el.gz.
Signature
(project--read-file-cpd-relative PROMPT ALL-FILES &optional PREDICATE HIST MB-DEFAULT)
Documentation
Read a file name, prompting with PROMPT.
ALL-FILES is a list of possible file name completions.
PREDICATE and HIST have the same meaning as in completing-read.
MB-DEFAULT is used as part of "future history", to be inserted by the user at will.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
(defun project--read-file-cpd-relative (prompt
all-files &optional predicate
hist mb-default)
"Read a file name, prompting with PROMPT.
ALL-FILES is a list of possible file name completions.
PREDICATE and HIST have the same meaning as in `completing-read'.
MB-DEFAULT is used as part of \"future history\", to be inserted
by the user at will."
(let* ((common-parent-directory
(let ((common-prefix (try-completion "" all-files)))
(if (> (length common-prefix) 0)
(file-name-directory common-prefix))))
(cpd-length (length common-parent-directory))
(prompt (if (zerop cpd-length)
prompt
(concat prompt (format " in %s" common-parent-directory))))
(included-cpd (when (member common-parent-directory all-files)
(setq all-files
(delete common-parent-directory all-files))
t))
(substrings (mapcar (lambda (s) (substring s cpd-length)) all-files))
(_ (when included-cpd
(setq substrings (cons "./" substrings))))
(new-collection (project--file-completion-table substrings))
(abbr-cpd (abbreviate-file-name common-parent-directory))
(abbr-cpd-length (length abbr-cpd))
(relname (cl-letf ((history-add-new-input nil)
((symbol-value hist)
(mapcan
(lambda (s)
(and (string-prefix-p abbr-cpd s)
(not (eq abbr-cpd-length (length s)))
(list (substring s abbr-cpd-length))))
(symbol-value hist))))
(project--completing-read-strict prompt
new-collection
predicate
hist mb-default)))
(absname (expand-file-name relname common-parent-directory)))
(when (and hist history-add-new-input)
(add-to-history hist (abbreviate-file-name absname)))
absname))