- `narrow-completions-function': function for
narrowing (restricting) the completions list. This function
overrides `minibuffer-narrow-completions-function', which see.
+- `adjust-base-function': function used to adjust the completion
+ base, which is the part of the minibuffer input that is elided
+ from all completion candidates, such as the directory part
+ during file name completion. This function should take one
+ argument, the original completion base, and return a new base.
The metadata of a completion table should be constant between two boundaries."
(let ((metadata (if (functionp table)
(funcall table string pred 'metadata))))
(sort-fun
(or minibuffer-completions-sort-function
(completion-metadata-get all-md 'cycle-sort-function)))
- (group-fun (completion-metadata-get all-md 'group-function)))
+ (group-fun (completion-metadata-get all-md 'group-function))
+ (full-base (substring string 0 base-size))
+ (minibuffer-completion-base
+ (funcall (or (alist-get 'adjust-base-function all-md) #'identity)
+ full-base)))
(when last
(setcdr last nil)
;; exists, on top.
(when (minibufferp)
(setq all (minibuffer--sort-by-position
- (minibuffer--sort-preprocess-history
- (substring string 0 base-size))
+ (minibuffer--sort-preprocess-history full-base)
all)))))
;; Cache input for `minibuffer-restore-completion-input',
;; unless STRING is an exact and sole completion.
- (and (minibufferp)
- (or (consp (cdr all)) ; not sole
- (not (equal (car all) string))) ; not exact
- (minibuffer--cache-completion-input
- (substring string base-size)
- (buffer-substring-no-properties (minibuffer-prompt-end)
- (+ (minibuffer-prompt-end)
- base-size))))
+ (let ((input (substring string base-size)))
+ (and (minibufferp)
+ (or (consp (cdr all)) ; not sole
+ (not (equal input (car all)))) ; not exact
+ (minibuffer--cache-completion-input
+ input (buffer-substring (minibuffer-prompt-end)
+ (+ (minibuffer-prompt-end)
+ base-size)))))
;; Cache the result. This is not just for speed, but also so that
;; repeated calls to minibuffer-force-complete can cycle through
(completion--fail)))
(let* ((prefix (unless (zerop base-size) (substring string 0 base-size)))
- (minibuffer-completion-base (substring string 0 base-size))
+ (full-base (substring string 0 base-size))
(base-prefix (buffer-substring (minibuffer--completion-prompt-end)
(+ start base-size)))
(base-suffix
(sort-fun (completion-metadata-get all-md 'display-sort-function))
(group-fun (completion-metadata-get all-md 'group-function))
(completion-category (completion-metadata-get all-md 'category))
+ (minibuffer-completion-base
+ (funcall (or (alist-get 'adjust-base-function all-md) #'identity)
+ full-base))
(mainbuf (current-buffer))
;; If the *Completions* buffer is shown in a new
;; window, mark it as softly-dedicated, so bury-buffer in
;; delete the window or not.
(display-buffer-mark-dedicated 'soft))
(minibuffer--cache-completion-input (substring string base-size)
- minibuffer-completion-base)
+ full-base)
(with-current-buffer-window
"*Completions*"
;; This is a copy of `display-buffer-fallback-action'