*** empty log message ***
[bpt/emacs.git] / lisp / icomplete.el
index bbfb817..3eb4b4b 100644 (file)
@@ -1,7 +1,7 @@
 ;;; icomplete.el --- minibuffer completion incremental feedback
 
 ;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003,
-;;   2004, 2005 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Ken Manheimer <klm@i.am>
 ;; Maintainer: Ken Manheimer <klm@i.am>
@@ -13,7 +13,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -99,7 +99,7 @@ completions - see `icomplete-delay-completions-threshold'."
 (defcustom icomplete-minibuffer-setup-hook nil
   "*Icomplete-specific customization of minibuffer setup.
 
-This hook is run during minibuffer setup iff icomplete will be active.
+This hook is run during minibuffer setup if icomplete is active.
 It is intended for use in customizing icomplete for interoperation
 with other features and packages.  For instance:
 
@@ -146,9 +146,8 @@ is minibuffer."
   (if (commandp func-name)
     (save-excursion
       (let* ((sym (intern func-name))
-            (buf (other-buffer))
-            (map (save-excursion (set-buffer buf) (current-local-map)))
-            (keys (where-is-internal sym map)))
+            (buf (other-buffer nil t))
+            (keys (with-current-buffer buf (where-is-internal sym))))
        (if keys
            (concat "<"
                    (mapconcat 'key-description
@@ -157,12 +156,19 @@ is minibuffer."
                                         (< (length x) (length y))))
                               ", ")
                    ">"))))))
+;;;_  = icomplete-with-completion-tables
+(defvar icomplete-with-completion-tables '(internal-complete-buffer)
+  "Specialized completion tables with which icomplete should operate.
+
+Icomplete does not operate with any specialized completion tables
+except those on this list.")
 
 ;;;_ > icomplete-mode (&optional prefix)
 ;;;###autoload
 (define-minor-mode icomplete-mode
   "Toggle incremental minibuffer completion for this Emacs session.
-With a numeric argument, turn Icomplete mode on iff ARG is positive."
+With a numeric argument, turn Icomplete mode on if ARG is positive,
+otherwise turn it off."
   :global t :group 'icomplete
   (if icomplete-mode
       ;; The following is not really necessary after first time -
@@ -184,8 +190,9 @@ Conditions are:
   (and (window-minibuffer-p (selected-window))
        (not executing-kbd-macro)
        minibuffer-completion-table
-       ;; (or minibuffer-completing-file-name
-       (not (functionp minibuffer-completion-table)))) ;; )
+       (or (not (functionp minibuffer-completion-table))
+           (member minibuffer-completion-table
+                   icomplete-with-completion-tables))))
 
 ;;;_ > icomplete-minibuffer-setup ()
 (defun icomplete-minibuffer-setup ()
@@ -209,10 +216,11 @@ Usually run by inclusion in `minibuffer-setup-hook'."
   "Remove completions display \(if any) prior to new user input.
 Should be run in on the minibuffer `pre-command-hook'.  See `icomplete-mode'
 and `minibuffer-setup-hook'."
-  (when icomplete-eoinput
+  (when (and icomplete-mode icomplete-eoinput)
 
     (unless (>= icomplete-eoinput (point-max))
-      (let ((buffer-undo-list t)) ; prevent entry
+      (let ((buffer-undo-list t) ; prevent entry
+           deactivate-mark)
        (delete-region icomplete-eoinput (point-max))))
 
     ;; Reestablish the safe value.
@@ -223,7 +231,7 @@ and `minibuffer-setup-hook'."
   "Insert icomplete completions display.
 Should be run via minibuffer `post-command-hook'.  See `icomplete-mode'
 and `minibuffer-setup-hook'."
-  (when (icomplete-simple-completing-p)
+  (when (and icomplete-mode (icomplete-simple-completing-p))
     (save-excursion
       (goto-char (point-max))
       ;; Register the end of input, so we know where the extra stuff
@@ -243,13 +251,16 @@ and `minibuffer-setup-hook'."
                ;; embarking on computing completions:
                (sit-for icomplete-compute-delay)))
          (let ((text (while-no-input
-                       (icomplete-completions
-                        (field-string)
-                        minibuffer-completion-table
-                        minibuffer-completion-predicate
-                        (not minibuffer-completion-confirm))))
-               (buffer-undo-list t))
-           (if text (insert text)))))))
+                       (list
+                        (icomplete-completions
+                         (field-string)
+                         minibuffer-completion-table
+                         minibuffer-completion-predicate
+                         (not minibuffer-completion-confirm)))))
+               (buffer-undo-list t)
+               deactivate-mark)
+           ;; Do nothing if while-no-input was aborted.
+           (if (consp text) (insert (car text))))))))
 
 ;;;_ > icomplete-completions (name candidates predicate require-match)
 (defun icomplete-completions (name candidates predicate require-match)
@@ -323,7 +334,7 @@ are exhibited within the square braces.)"
 
 ;;;_* Local emacs vars.
 ;;;Local variables:
-;;;outline-layout: (-2 :)
+;;;allout-layout: (-2 :)
 ;;;End:
 
 ;; arch-tag: 339ec25a-0741-4eb6-be63-997532e89b0f