Function: mh-folder-completion-function
mh-folder-completion-function is an autoloaded and byte-compiled
function defined in mh-utils.el.gz.
Signature
(mh-folder-completion-function NAME PREDICATE FLAG)
Documentation
Programmable completion for folder names.
NAME is the partial folder name that has been input. PREDICATE if
non-nil is a function that is used to filter the possible
choices. FLAG is nil to indicate try-completion, t for
all-completions, or the symbol lambda for test-completion.
See Info node (elisp) Programmed Completion for details.
Source Code
;; Defined in /usr/src/emacs/lisp/mh-e/mh-utils.el.gz
;;;###mh-autoload
(defun mh-folder-completion-function (name predicate flag)
"Programmable completion for folder names.
NAME is the partial folder name that has been input. PREDICATE if
non-nil is a function that is used to filter the possible
choices. FLAG is nil to indicate `try-completion', t for
`all-completions', or the symbol lambda for `test-completion'.
See Info node `(elisp) Programmed Completion' for details."
(let* ((orig-name name)
;; After normalization, name is nil, +, or +something. If a
;; trailing slash is present, it is preserved.
(name (mh-normalize-folder-name name nil t))
(last-slash (mh-search-from-end ?/ name))
;; nil if + or +folder; +folder/ if slash present.
(last-complete (if last-slash (substring name 0 (1+ last-slash)) nil))
;; Either +folder/remainder, +remainder, or "".
(remainder (cond (last-complete (substring name (1+ last-slash)))
(name (substring name 1))
(t ""))))
(cond ((eq (car-safe flag) 'boundaries)
(cl-list* 'boundaries
(let ((slash (mh-search-from-end ?/ orig-name)))
(if slash (1+ slash)
(if (string-match "\\`\\+" orig-name) 1 0)))
(if (cdr flag) (string-search "/" (cdr flag)))))
((eq flag nil)
(let ((try-res
(try-completion
remainder
(mh-sub-folders last-complete t)
predicate)))
(cond ((eq try-res nil) nil)
((and (eq try-res t) (equal name orig-name)) t)
((eq try-res t) name)
(t (concat (or last-complete "+") try-res)))))
((eq flag t)
(all-completions
remainder (mh-sub-folders last-complete t) predicate))
((eq flag 'lambda)
;; FIXME: if name starts with "/", `path' will end
;; being a relative name without a leading + nor / !? --Stef
(let ((path (concat (unless (and (> (length name) 1)
(eq (aref name 1) ?/))
mh-user-path)
(substring name 1))))
(cond (mh-allow-root-folder-flag (file-directory-p path))
((equal path mh-user-path) nil)
(t (file-directory-p path))))))))