-;;;_ > icomplete-prime-session ()
-(defun icomplete-prime-session ()
-
- "Prep emacs v 19 for icompletion. For emacs v19.18 and later revs,
-icomplete is installed in 'minibuffer-setup-hook'. Global pre- and
-post-command-hook functions are used in v19.17 and earlier revs."
-
- (let* ((v19-rev (and (string-match "^19\\.\\([0-9]+\\)" emacs-version)
- (string-to-int (substring emacs-version
- (match-beginning 1)
- (match-end 1))))))
-
- (cond ((and v19-rev ; emacs v 19, some rev,
- (> v19-rev 17))
- ;; Post v19rev17, has minibuffer-setup-hook, use it:
- (add-hook 'minibuffer-setup-hook 'icomplete-prime-minibuffer))
- (v19-rev
- ;; v19rev17 and prior (including lucid): use global
- ;; pre- and post-command-hooks, instead:
- (add-hook 'pre-command-hook 'icomplete-pre-command-hook 'append)
- (add-hook 'post-command-hook
- 'icomplete-post-command-hook 'append))
- ((format "icomplete: non v19 emacs, %s - %s"
- emacs-version "try elisp-archive icomplete")))))
-;;;_ > icomplete-prime-minibuffer ()
-(defun icomplete-prime-minibuffer ()
-
- "Prep emacs, v 19.18 or later, for icomplete. \(icomplete-prime-
-session establishes global hooks, instead, in emacs 19 versions 19.17
-and prior.\) Run via minibuffer-setup-hook \(emacs 19.18 or later\),
-adds icomplete pre- and post-command hooks to do icomplete display
-management."
-
- ;; We append the hooks because preliminary version of blink-paren
- ;; post-command-hook i have interferes with proper operation of
- ;; minibuffer quit.
- (make-local-variable 'pre-command-hook)
- (make-local-variable 'post-command-hook)
- (add-hook 'pre-command-hook 'icomplete-pre-command-hook)
- (add-hook 'post-command-hook 'icomplete-post-command-hook))
-;;;_ > icomplete-window-minibuffer-p ()
-(defmacro icomplete-window-minibuffer-p ()
-
- "Returns non-nil if current window is a minibuffer window.
-Trivially equates to '(window-minibuffer-p nil)', with the nil
-provided in case the argument is not optional in Lucid emacs (which
-some net correspondance seems to indicate)."
-
- '(window-minibuffer-p nil))
-
-;;;_ + Completion
-;;;_ - Completion feedback hooks
-;;;_ > icomplete-pre-command-hook ()
-(defun icomplete-pre-command-hook ()
- "Cleanup completions exhibit before user's new input (or whatever) is dealt
-with."
- (if (and (icomplete-window-minibuffer-p)
- (not (symbolp minibuffer-completion-table))
- (not icomplete-inhibit))
- (if (and (boundp 'icomplete-eoinput)
- icomplete-eoinput)
- (if (> icomplete-eoinput (point-max))
- ;; Oops, got rug pulled out from under us - reinit:
- (setq icomplete-eoinput (point-max))
- (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
- (delete-region icomplete-eoinput (point-max))))
- (make-local-variable 'icomplete-eoinput)
- (setq icomplete-eoinput 1))))
-;;;_ > icomplete-post-command-hook ()
-(defun icomplete-post-command-hook ()
- "Exhibit completions, leaving icomplete-eoinput with position where user
-input leaves off and exhibit begins, so icomplete-pre-command-hook can
-subsequently cleanup."
- (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
- (not icomplete-inhibit) ; ... not specifically inhibited.
- ;(sit-for 0) ; ... redisplay and if there's input
- ; waiting, then don't icomplete
- ; (stigs suggestion) (too jumpy!)
- ;; Inhibit for file-name and other custom-func completions:
- (not (symbolp minibuffer-completion-table))
- )
- (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
- (icomplete-exhibit))))
-;;;_ > icomplete-window-setup-hook ()
-(defun icomplete-window-setup-hook ()
- "Exhibit completions, leaving icomplete-eoinput with position where user
-input leaves off and exhibit begins, so icomplete-pre-command-hook can
-subsequently cleanup."
- (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
- )
- (message "ic ws doing")(sit-for 1)))
-;;;_ > icomplete-exhibit ()
+;;;_ = icomplete-pre-command-hook
+(defvar icomplete-pre-command-hook nil
+ "Incremental-minibuffer-completion pre-command-hook.
+
+Is run in minibuffer before user input when `icomplete-mode' is non-nil.
+Use `icomplete-mode' function to set it up properly for incremental
+minibuffer completion.")
+(add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
+;;;_ = icomplete-post-command-hook
+(defvar icomplete-post-command-hook nil
+ "Incremental-minibuffer-completion post-command-hook.
+
+Is run in minibuffer after user input when `icomplete-mode' is non-nil.
+Use `icomplete-mode' function to set it up properly for incremental
+minibuffer completion.")
+(add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
+
+(defun icomplete-get-keys (func-name)
+ "Return strings naming keys bound to `func-name', or nil if none.
+Examines the prior, not current, buffer, presuming that current buffer
+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)))
+ (if keys
+ (concat "<"
+ (mapconcat 'key-description
+ (sort keys
+ #'(lambda (x y)
+ (< (length x) (length y))))
+ ", ")
+ ">"))))))
+
+;;;_ > 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."
+ :global t :group 'icomplete
+ (if icomplete-mode
+ ;; The following is not really necessary after first time -
+ ;; no great loss.
+ (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)
+ (remove-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)))
+
+;;;_ > icomplete-simple-completing-p ()
+(defun icomplete-simple-completing-p ()
+ "Non-nil if current window is minibuffer that's doing simple completion.
+
+Conditions are:
+ the selected window is a minibuffer,
+ and not in the middle of macro execution,
+ and `minibuffer-completion-table' is not a symbol (which would
+ indicate some non-standard, non-simple completion mechanism,
+ like file-name and other custom-func completions)."
+
+ (and (window-minibuffer-p (selected-window))
+ (not executing-kbd-macro)
+ minibuffer-completion-table
+ ;; (or minibuffer-completing-file-name
+ (not (functionp minibuffer-completion-table)))) ;; )
+
+;;;_ > icomplete-minibuffer-setup ()
+(defun icomplete-minibuffer-setup ()
+ "Run in minibuffer on activation to establish incremental completion.
+Usually run by inclusion in `minibuffer-setup-hook'."
+ (when (and icomplete-mode (icomplete-simple-completing-p))
+ (add-hook 'pre-command-hook
+ (lambda () (run-hooks 'icomplete-pre-command-hook))
+ nil t)
+ (add-hook 'post-command-hook
+ (lambda () (run-hooks 'icomplete-post-command-hook))
+ nil t)
+ (run-hooks 'icomplete-minibuffer-setup-hook)))
+;\f
+
+
+;;;_* Completion
+
+;;;_ > icomplete-tidy ()
+(defun icomplete-tidy ()
+ "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
+
+ (unless (>= icomplete-eoinput (point-max))
+ (let ((buffer-undo-list t)) ; prevent entry
+ (delete-region icomplete-eoinput (point-max))))
+
+ ;; Reestablish the safe value.
+ (setq icomplete-eoinput nil)))
+
+;;;_ > icomplete-exhibit ()