Function: minibuffer-force-complete

minibuffer-force-complete is an interactive and byte-compiled function defined in minibuffer.el.gz.

Signature

(minibuffer-force-complete &optional START END DONT-CYCLE)

Documentation

Complete the minibuffer to an exact match.

Repeated uses step through the possible completions. DONT-CYCLE tells the function not to setup cycling.

Probably introduced at or before Emacs version 23.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun minibuffer-force-complete (&optional start end dont-cycle)
  "Complete the minibuffer to an exact match.
Repeated uses step through the possible completions.
DONT-CYCLE tells the function not to setup cycling."
  (interactive)
  (setq minibuffer-scroll-window nil)
  ;; FIXME: Need to deal with the extra-size issue here as well.
  ;; FIXME: ~/src/emacs/t<M-TAB>/lisp/minibuffer.el completes to
  ;; ~/src/emacs/trunk/ and throws away lisp/minibuffer.el.
  (let* ((start (copy-marker (or start (minibuffer--completion-prompt-end))))
         (end (or end (point-max)))
         ;; (md (completion--field-metadata start))
         (all (completion-all-sorted-completions start end))
         (base (+ start (or (cdr (last all)) 0))))
    (cond
     ((not (consp all))
      (completion--message
       (if all "No more completions" "No completions")))
     ((not (consp (cdr all)))
      (let ((done (equal (car all) (buffer-substring-no-properties base end))))
        (unless done (completion--replace base end (car all)))
        (completion--done (buffer-substring-no-properties start (point))
                          'finished (when done "Sole completion"))))
     (t
      (completion--replace base end (car all))
      (setq end (+ base (length (car all))))
      (completion--done (buffer-substring-no-properties start (point)) 'sole)
      (setq this-command 'completion-at-point) ;For completion-in-region.
      ;; Set cycling after modifying the buffer since the flush hook resets it.
      (unless dont-cycle
        ;; If completing file names, (car all) may be a directory, so we'd now
        ;; have a new set of possible completions and might want to reset
        ;; completion-all-sorted-completions to nil, but we prefer not to,
        ;; so that repeated calls minibuffer-force-complete still cycle
        ;; through the previous possible completions.
        (let ((last (last all)))
          (setcdr last (cons (car all) (cdr last)))
          (completion--cache-all-sorted-completions start end (cdr all)))
        ;; Make sure repeated uses cycle, even though completion--done might
        ;; have added a space or something that moved us outside of the field.
        ;; (bug#12221).
        (let* ((table minibuffer-completion-table)
               (pred minibuffer-completion-predicate)
               (extra-prop completion-extra-properties)
               (cmd
                (lambda () "Cycle through the possible completions."
                  (interactive)
                  (let ((completion-extra-properties extra-prop))
                    (completion-in-region start (point) table pred)))))
          (setq completion-cycling
                (set-transient-map
                 (let ((map (make-sparse-keymap)))
                   (define-key map [remap completion-at-point] cmd)
                   (define-key map (vector last-command-event) cmd)
                   map)))))))))