Trailing whitespace deleted.
[bpt/emacs.git] / lisp / icomplete.el
index aba6ab4..4e368c8 100644 (file)
@@ -1,6 +1,7 @@
-;;;_+ icomplete.el - minibuffer completion incremental feedback
+;;; icomplete.el --- minibuffer completion incremental feedback
 
-;; Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001
+;;;  Free Software Foundation, Inc.
 
 ;; Author: Ken Manheimer <klm@i.am>
 ;; Maintainer: Ken Manheimer <klm@i.am>
@@ -70,7 +71,7 @@
 
 (defcustom icomplete-mode nil
   "*Toggle incremental minibuffer completion.
-As text is typed into the minibuffer, prospective completions are indicated 
+As text is typed into the minibuffer, prospective completions are indicated
 in the minibuffer.
 Setting this variable directly does not take effect;
 use either \\[customize] or the function `icomplete-mode'."
@@ -113,15 +114,15 @@ completions - see `icomplete-delay-completions-threshold'."
 
 This hook is run during minibuffer setup iff icomplete will be active.
 It is intended for use in customizing icomplete for interoperation
-with other packages.  For instance:
+with other features and packages.  For instance:
 
   \(add-hook 'icomplete-minibuffer-setup-hook
            \(function
             \(lambda ()
-              \(make-local-variable 'resize-minibuffer-window-max-height)
-              \(setq resize-minibuffer-window-max-height 3))))
+              \(make-local-variable 'max-mini-window-height)
+              \(setq max-mini-window-height 3))))
 
-will constrain rsz-mini to a maximum minibuffer height of 3 lines when
+will constrain Emacs to a maximum minibuffer height of 3 lines when
 icompletion is occurring."
   :type 'hook
   :group 'icomplete)
@@ -172,17 +173,18 @@ is minibuffer."
 
 ;;;_ > icomplete-mode (&optional prefix)
 ;;;###autoload
-(defun icomplete-mode (&optional prefix)
-  "Activate incremental minibuffer completion for this Emacs session.
-Deactivates with negative universal argument."
-  (interactive "p")
-  (or prefix (setq prefix 0))
-  (cond ((>= prefix 0)
-        (setq icomplete-mode t)
-        ;; The following is not really necessary after first time -
-        ;; no great loss.
-        (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup))
-       (t (setq icomplete-mode nil))))
+(defun icomplete-mode (&optional arg)
+  "Toggle incremental minibuffer completion for this Emacs session.
+With a numeric argument, turn Icomplete mode on iff ARG is positive."
+  (interactive "P")
+  (let ((on-p (if (null arg)
+                 (not icomplete-mode)
+               (> (prefix-numeric-value arg) 0))))
+    (setq icomplete-mode on-p)
+    (when on-p
+      ;; The following is not really necessary after first time -
+      ;; no great loss.
+      (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup))))
 
 ;;;_ > icomplete-simple-completing-p ()
 (defun icomplete-simple-completing-p ()
@@ -205,12 +207,10 @@ Conditions are:
   "Run in minibuffer on activation to establish incremental completion.
 Usually run by inclusion in `minibuffer-setup-hook'."
   (cond ((and icomplete-mode (icomplete-simple-completing-p))
-        (make-local-hook 'pre-command-hook)
         (add-hook 'pre-command-hook
                   (function (lambda ()
                               (run-hooks 'icomplete-pre-command-hook)))
                   nil t)
-        (make-local-hook 'post-command-hook)
         (add-hook 'post-command-hook
                   (function (lambda ()
                               (run-hooks 'icomplete-post-command-hook)))
@@ -246,7 +246,7 @@ and `minibuffer-setup-hook'."
 Should be run via minibuffer `post-command-hook'.  See `icomplete-mode'
 and `minibuffer-setup-hook'."
   (if (icomplete-simple-completing-p)
-      (let ((contents (buffer-substring (point-min)(point-max)))
+      (let ((contents (buffer-substring (minibuffer-prompt-end)(point-max)))
            (buffer-undo-list t))
        (save-excursion
          (goto-char (point-max))
@@ -258,7 +258,7 @@ and `minibuffer-setup-hook'."
              (make-local-variable 'icomplete-eoinput))
          (setq icomplete-eoinput (point))
                                         ; Insert the match-status information:
-         (if (and (> (point-max) 1)
+         (if (and (> (point-max) (minibuffer-prompt-end))
                   (or
                    ;; Don't bother with delay after certain number of chars:
                    (> (point-max) icomplete-max-delay-chars)
@@ -274,7 +274,7 @@ and `minibuffer-setup-hook'."
                    ;; Delay - give some grace time for next keystroke, before
                    ;; embarking on computing completions:
                    (sit-for icomplete-compute-delay)))
-             (insert-string
+             (insert
               (icomplete-completions contents
                                      minibuffer-completion-table
                                      minibuffer-completion-predicate