[net.emacs] Minibuffer completion

israel@tove.umd.edu (10/02/85)

From: Bruce Israel <israel@tove.umd.edu>

Here is a really useful function that I wrote for minibuffer
completion.  It will complete as much as possible, exiting if there is
only one possibility.  If there are two or more, then it completes
until the two choices differ.  If there aren't any possibilities, then
it removes characters off the end of the completion string until it
gets to a point where completions are possible and stops there.

I bind it to the SPACE key in the minibuffer, since I don't really
like completion by single words at all.  Following the function is the
function call that will bind it to the SPACE key.  Change the
character there if you want to bind it to something else.  Enjoy.

(defun minibuffer-complete-exit-backup nil
   "Minibuffer completion, exiting on unique completion with backup."
   (interactive)
   (let (comp (complete t))
     (set-mark (dot-min))
     (while (null (setq comp (all-completions
			      (region-to-string)
			      minibuffer-completion-table
			      minibuffer-completion-predicate)))
       (setq complete nil)
       (delete-backward-char 1 nil))
     (and complete (if (null (cdr comp)) (minibuffer-complete-and-exit)
			(minibuffer-complete)))))
;
(define-key minibuffer-local-must-match-map " "
     (define-key minibuffer-local-completion-map " "
	  'minibuffer-complete-exit-backup))