Function: consult--directory-prompt

consult--directory-prompt is a byte-compiled function defined in consult.el.

Signature

(consult--directory-prompt PROMPT DIR)

Documentation

Return prompt, paths and default directory.

PROMPT is the prompt prefix. The directory is appended to the prompt prefix. For projects only the project name is shown. The default-directory is not shown. Other directories are abbreviated and only the last two path components are shown.

If DIR is a string, it is returned as default directory. If DIR is a list of strings, the list is returned as search paths. If DIR is nil the consult-project-function is tried to retrieve the default directory. If no project is found the default-directory is returned as is. Otherwise the user is asked for the directories or files to search via completing-read-multiple.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--directory-prompt (prompt dir)
  "Return prompt, paths and default directory.

PROMPT is the prompt prefix.  The directory is appended to the
prompt prefix.  For projects only the project name is shown.  The
`default-directory' is not shown.  Other directories are
abbreviated and only the last two path components are shown.

If DIR is a string, it is returned as default directory.  If DIR
is a list of strings, the list is returned as search paths.  If
DIR is nil the `consult-project-function' is tried to retrieve
the default directory.  If no project is found the
`default-directory' is returned as is.  Otherwise the user is
asked for the directories or files to search via
`completing-read-multiple'."
  (let* ((paths nil)
         (dir
          (pcase dir
            ((pred stringp) dir)
            ((or 'nil '(16)) (or (consult--project-root dir) default-directory))
            (_
             (pcase (if (stringp (car-safe dir))
                        dir
                      ;; Preserve this-command across `completing-read-multiple' call,
                      ;; such that `consult-customize' continues to work.
                      (let ((this-command this-command)
                            (def (abbreviate-file-name default-directory))
                            ;; bug#75910: category instead of `minibuffer-completing-file-name'
                            (minibuffer-completing-file-name t)
                            (ignore-case read-file-name-completion-ignore-case))
                        (minibuffer-with-setup-hook
                            (lambda ()
                              (setq-local completion-ignore-case ignore-case)
                              (set-syntax-table minibuffer-local-filename-syntax))
                          (completing-read-multiple "Dirs or files: "
                                                    #'completion-file-name-table
                                                    nil t def 'consult--path-history def))))
               ((and `(,p) (guard (file-directory-p p))) p)
               (ps (setq paths (mapcar (lambda (p)
                                         (file-relative-name (expand-file-name p)))
                                       ps))
                   default-directory)))))
         (edir (file-name-as-directory (expand-file-name dir)))
         (pdir (let ((default-directory edir))
                 ;; Bind default-directory in order to find the project
                 (consult--project-root))))
    (list
     (format "%s (%s): " prompt
             (pcase paths
               ((guard (<= 1 (length paths) 2))
                (string-join (mapcar #'consult--left-truncate-file paths) ", "))
               (`(,p . ,_)
                (format "%d paths, %s, …" (length paths) (consult--left-truncate-file p)))
               ((guard (equal edir pdir)) (concat "Project " (consult--project-name pdir)))
               (_ (consult--left-truncate-file edir))))
     (or paths '("."))
     edir)))