]> git.eshelyaron.com Git - emacs.git/commitdiff
(completion-all-sorted-completions): New var.
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 21 May 2008 20:52:44 +0000 (20:52 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 21 May 2008 20:52:44 +0000 (20:52 +0000)
(completion--flush-all-sorted-completions)
(completion-all-sorted-completions): New functions.
(minibuffer-force-complete): New command.

etc/NEWS
lisp/ChangeLog
lisp/minibuffer.el

index 8926bbd7ea206cb5c4a2b324fb3445ef30ced861..9d74ae0e1fa6c251b5d7551989ef3512a43ba2ab 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -64,7 +64,10 @@ default toolkit, but you can use --with-x-toolkit=gtk if necessary.
 * Changes in Emacs 23.1
 
 ** Completion.
-*** `completion-style' can be customized to choose your favorite completion.
+*** `completion-styles' can be customized to choose your favorite completion.
+*** The default completion styles include a form of partial-completion.
+*** The new command `minibuffer-force-complete chooses one of the possible
+completions, rather than stopping at the common prefix.
 *** `completion-auto-help' can be set to `lazy' to list the completions only
 if you repeat the completion.  This was already supported in
 `partial-completion-mode'.
index a007ae81304d0bc596cc41efc4e32301f70c389a..2fc1351434d52832c6e12f082db9c75258ce4f04 100644 (file)
@@ -1,3 +1,10 @@
+2008-05-21  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * minibuffer.el (completion-all-sorted-completions): New var.
+       (completion--flush-all-sorted-completions)
+       (completion-all-sorted-completions): New functions.
+       (minibuffer-force-complete): New command.
+
 2008-05-21  Glenn Morris  <rgm@gnu.org>
 
        * files.el (c-postprocess-file-styles): Declare for compiler.
index 5e176637618b55ad3f2ee4bdd39f975882e8f244..59081b8d2692353f0c652fd2ef0e6e7557f623b3 100644 (file)
@@ -489,6 +489,59 @@ scroll the window of possible completions."
                t)
         (t     t)))))
 
+(defvar completion-all-sorted-completions nil)
+(make-variable-buffer-local 'completion-all-sorted-completions)
+
+(defun completion--flush-all-sorted-completions (&rest ignore)
+  (setq completion-all-sorted-completions nil))
+
+(defun completion-all-sorted-completions ()
+  (or completion-all-sorted-completions
+      (let* ((start (field-beginning))
+             (end (field-end))
+             (all (completion-all-completions (buffer-substring start end)
+                                              minibuffer-completion-table
+                                              minibuffer-completion-predicate
+                                              (- (point) start)))
+             (last (last all))
+             (base-size (or (cdr last) 0)))
+        (when last
+          (setcdr last nil)
+          ;; Prefer shorter completions.
+          (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2)))))
+          ;; Prefer recently used completions.
+          (let ((hist (symbol-value minibuffer-history-variable)))
+            (setq all (sort all (lambda (c1 c2)
+                                  (> (length (member c1 hist))
+                                     (length (member c2 hist)))))))
+          ;; Cache the result.  This is not just for speed, but also so that
+          ;; repeated calls to minibuffer-force-complete can cycle through
+          ;; all possibilities.
+          (add-hook 'after-change-functions
+                    'completion--flush-all-sorted-completions nil t)
+          (setq completion-all-sorted-completions
+                (nconc all base-size))))))
+
+(defun minibuffer-force-complete ()
+  "Complete the minibuffer to an exact match.
+Repeated uses step through the possible completions."
+  (interactive)
+  ;; FIXME: Need to deal with the extra-size issue here as well.
+  (let* ((start (field-beginning))
+         (end (field-end))
+         (all (completion-all-sorted-completions)))
+    (if (not (consp all))
+        (minibuffer-message (if all "No more completions" "No completions"))
+      (goto-char end)
+      (insert (car all))
+      (delete-region (+ start (cdr (last all))) end)
+      ;; 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.
+      (setq completion-all-sorted-completions (cdr all)))))
+
 (defun minibuffer-complete-and-exit ()
   "If the minibuffer contents is a valid completion then exit.
 Otherwise try to complete it.  If completion leads to a valid completion,
@@ -861,6 +914,9 @@ specified by COMMON-SUBSTRING."
 
 (let ((map minibuffer-local-completion-map))
   (define-key map "\t" 'minibuffer-complete)
+  ;; M-TAB is already abused for many other purposes, so we should find
+  ;; another binding for it.
+  ;; (define-key map "\e\t" 'minibuffer-force-complete)
   (define-key map " " 'minibuffer-complete-word)
   (define-key map "?" 'minibuffer-completion-help))