2000-05-24 15:12:19 +00:00
|
|
|
|
;;; icomplete.el --- minibuffer completion incremental feedback
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
2001-04-03 14:48:02 +00:00
|
|
|
|
;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001
|
|
|
|
|
;;; Free Software Foundation, Inc.
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1999-11-21 13:44:26 +00:00
|
|
|
|
;; Author: Ken Manheimer <klm@i.am>
|
|
|
|
|
;; Maintainer: Ken Manheimer <klm@i.am>
|
|
|
|
|
;; Created: Mar 1993 Ken Manheimer, klm@nist.gov - first release to usenet
|
|
|
|
|
;; Last update: Ken Manheimer <klm@i.am>, 11/18/1999.
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; Keywords: help, abbrev
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;; 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)
|
|
|
|
|
;; any later version.
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
1993-12-30 11:56:19 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;; Commentary:
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; Loading this package implements a more fine-grained minibuffer
|
|
|
|
|
;; completion feedback scheme. Prospective completions are concisely
|
|
|
|
|
;; indicated within the minibuffer itself, with each successive
|
|
|
|
|
;; keystroke.
|
|
|
|
|
|
1998-01-24 11:35:59 +00:00
|
|
|
|
;; See `icomplete-completions' docstring for a description of the
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; icomplete display format.
|
|
|
|
|
|
|
|
|
|
;; See the `icomplete-minibuffer-setup-hook' docstring for a means to
|
|
|
|
|
;; customize icomplete setup for interoperation with other
|
|
|
|
|
;; minibuffer-oriented packages.
|
|
|
|
|
|
1999-11-21 13:44:26 +00:00
|
|
|
|
;; To activate icomplete mode, load the package and use the
|
|
|
|
|
;; `icomplete-mode' function. You can subsequently deactivate it by
|
|
|
|
|
;; invoking the function icomplete-mode with a negative prefix-arg
|
|
|
|
|
;; (C-U -1 ESC-x icomplete-mode). Also, you can prevent activation of
|
|
|
|
|
;; the mode during package load by first setting the variable
|
|
|
|
|
;; `icomplete-mode' to nil. Icompletion can be enabled any time after
|
|
|
|
|
;; the package is loaded by invoking icomplete-mode without a prefix
|
|
|
|
|
;; arg.
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; Thanks to everyone for their suggestions for refinements of this
|
|
|
|
|
;; package. I particularly have to credit Michael Cook, who
|
|
|
|
|
;; implemented an incremental completion style in his 'iswitch'
|
|
|
|
|
;; functions that served as a model for icomplete. Some other
|
1998-01-24 11:35:59 +00:00
|
|
|
|
;; contributors: Noah Friedman (restructuring as minor mode), Colin
|
1997-06-15 02:37:58 +00:00
|
|
|
|
;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and others.
|
1996-01-14 07:34:30 +00:00
|
|
|
|
|
|
|
|
|
;; klm.
|
1993-12-30 11:56:19 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
;;;_* Provide
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(provide 'icomplete)
|
|
|
|
|
|
1998-01-24 11:35:59 +00:00
|
|
|
|
|
|
|
|
|
(defgroup icomplete nil
|
|
|
|
|
"Show completions dynamically in minibuffer."
|
|
|
|
|
:prefix "icomplete-"
|
|
|
|
|
:group 'minibuffer)
|
|
|
|
|
|
|
|
|
|
(defcustom icomplete-mode nil
|
1999-11-21 13:44:26 +00:00
|
|
|
|
"*Toggle incremental minibuffer completion.
|
2003-02-04 11:26:42 +00:00
|
|
|
|
As text is typed into the minibuffer, prospective completions are indicated
|
1998-01-24 11:35:59 +00:00
|
|
|
|
in the minibuffer.
|
1999-04-27 18:58:13 +00:00
|
|
|
|
Setting this variable directly does not take effect;
|
|
|
|
|
use either \\[customize] or the function `icomplete-mode'."
|
1998-01-24 11:35:59 +00:00
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(icomplete-mode (if value 1 -1)))
|
|
|
|
|
:initialize 'custom-initialize-default
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'icomplete
|
|
|
|
|
:require 'icomplete)
|
|
|
|
|
|
1999-11-21 13:44:26 +00:00
|
|
|
|
;;;_* User Customization variables
|
|
|
|
|
(defcustom icomplete-prospects-length 80
|
|
|
|
|
"*Length of string displaying the prospects."
|
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
1998-01-24 11:35:59 +00:00
|
|
|
|
(defcustom icomplete-compute-delay .3
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
"*Completions-computation stall, used only with large-number
|
1998-01-24 11:35:59 +00:00
|
|
|
|
completions - see `icomplete-delay-completions-threshold'."
|
|
|
|
|
:type 'number
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
|
|
|
|
(defcustom icomplete-delay-completions-threshold 400
|
|
|
|
|
"*Pending-completions number over which to apply icomplete-compute-delay."
|
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
|
|
|
|
(defcustom icomplete-max-delay-chars 3
|
|
|
|
|
"*Maximum number of initial chars to apply icomplete compute delay."
|
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
|
|
|
|
(defcustom icomplete-show-key-bindings t
|
|
|
|
|
"*If non-nil, show key bindings as well as completion for sole matches."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
|
|
|
|
(defcustom icomplete-minibuffer-setup-hook nil
|
1994-09-18 08:27:12 +00:00
|
|
|
|
"*Icomplete-specific customization of minibuffer setup.
|
|
|
|
|
|
|
|
|
|
This hook is run during minibuffer setup iff icomplete will be active.
|
|
|
|
|
It is intended for use in customizing icomplete for interoperation
|
2001-01-22 16:03:42 +00:00
|
|
|
|
with other features and packages. For instance:
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
\(add-hook 'icomplete-minibuffer-setup-hook
|
1994-09-18 08:27:12 +00:00
|
|
|
|
\(function
|
|
|
|
|
\(lambda ()
|
2001-01-22 16:03:42 +00:00
|
|
|
|
\(make-local-variable 'max-mini-window-height)
|
|
|
|
|
\(setq max-mini-window-height 3))))
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
2001-01-22 16:03:42 +00:00
|
|
|
|
will constrain Emacs to a maximum minibuffer height of 3 lines when
|
1998-01-24 11:35:59 +00:00
|
|
|
|
icompletion is occurring."
|
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'icomplete)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;_* Initialization
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1993-12-30 11:56:19 +00:00
|
|
|
|
;;;_ + Internal Variables
|
|
|
|
|
;;;_ = icomplete-eoinput 1
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(defvar icomplete-eoinput 1
|
|
|
|
|
"Point where minibuffer input ends and completion info begins.")
|
|
|
|
|
(make-variable-buffer-local 'icomplete-eoinput)
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_ = 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)
|
|
|
|
|
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
(defun icomplete-get-keys (func-name)
|
1997-06-15 02:37:58 +00:00
|
|
|
|
"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)
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((sym (intern func-name))
|
1997-06-15 02:37:58 +00:00
|
|
|
|
(buf (other-buffer))
|
|
|
|
|
(map (save-excursion (set-buffer buf) (current-local-map)))
|
|
|
|
|
(keys (where-is-internal sym map)))
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
(if keys
|
|
|
|
|
(concat "<"
|
|
|
|
|
(mapconcat 'key-description
|
|
|
|
|
(sort keys
|
|
|
|
|
#'(lambda (x y)
|
|
|
|
|
(< (length x) (length y))))
|
|
|
|
|
", ")
|
|
|
|
|
">"))))))
|
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_ > icomplete-mode (&optional prefix)
|
1993-12-30 11:56:19 +00:00
|
|
|
|
;;;###autoload
|
2001-04-03 14:48:02 +00:00
|
|
|
|
(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))))
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
|
|
|
|
;;;_ > 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
|
1996-01-04 23:41:53 +00:00
|
|
|
|
indicate some non-standard, non-simple completion mechanism,
|
1994-09-18 08:27:12 +00:00
|
|
|
|
like file-name and other custom-func completions)."
|
|
|
|
|
|
|
|
|
|
(and (window-minibuffer-p (selected-window))
|
1996-05-29 17:17:34 +00:00
|
|
|
|
(not executing-kbd-macro)
|
1994-09-18 08:27:12 +00:00
|
|
|
|
(not (symbolp minibuffer-completion-table))))
|
1995-08-22 20:30:57 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_ > icomplete-minibuffer-setup ()
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun icomplete-minibuffer-setup ()
|
|
|
|
|
"Run in minibuffer on activation to establish incremental completion.
|
1995-08-22 20:30:57 +00:00
|
|
|
|
Usually run by inclusion in `minibuffer-setup-hook'."
|
1994-09-18 08:27:12 +00:00
|
|
|
|
(cond ((and icomplete-mode (icomplete-simple-completing-p))
|
|
|
|
|
(add-hook 'pre-command-hook
|
|
|
|
|
(function (lambda ()
|
1995-08-22 20:30:57 +00:00
|
|
|
|
(run-hooks 'icomplete-pre-command-hook)))
|
|
|
|
|
nil t)
|
1994-09-18 08:27:12 +00:00
|
|
|
|
(add-hook 'post-command-hook
|
|
|
|
|
(function (lambda ()
|
1995-08-22 20:30:57 +00:00
|
|
|
|
(run-hooks 'icomplete-post-command-hook)))
|
|
|
|
|
nil t)
|
1994-09-18 08:27:12 +00:00
|
|
|
|
(run-hooks 'icomplete-minibuffer-setup-hook))))
|
1999-11-21 13:44:26 +00:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_* Completion
|
|
|
|
|
|
|
|
|
|
;;;_ > icomplete-tidy ()
|
|
|
|
|
(defun icomplete-tidy ()
|
|
|
|
|
"Remove completions display \(if any) prior to new user input.
|
1995-08-22 20:30:57 +00:00
|
|
|
|
Should be run in on the minibuffer `pre-command-hook'. See `icomplete-mode'
|
1994-09-18 08:27:12 +00:00
|
|
|
|
and `minibuffer-setup-hook'."
|
|
|
|
|
(if (icomplete-simple-completing-p)
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(if (and (boundp 'icomplete-eoinput)
|
|
|
|
|
icomplete-eoinput)
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(if (> icomplete-eoinput (point-max))
|
|
|
|
|
;; Oops, got rug pulled out from under us - reinit:
|
|
|
|
|
(setq icomplete-eoinput (point-max))
|
1993-12-30 11:56:19 +00:00
|
|
|
|
(let ((buffer-undo-list buffer-undo-list )) ; prevent entry
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(delete-region icomplete-eoinput (point-max))))
|
1994-09-18 08:27:12 +00:00
|
|
|
|
|
1993-12-30 11:56:19 +00:00
|
|
|
|
;; Reestablish the local variable 'cause minibuffer-setup is weird:
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(make-local-variable 'icomplete-eoinput)
|
|
|
|
|
(setq icomplete-eoinput 1))))
|
1995-08-22 20:30:57 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_ > icomplete-exhibit ()
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(defun icomplete-exhibit ()
|
1994-09-18 08:27:12 +00:00
|
|
|
|
"Insert icomplete completions display.
|
1995-08-22 20:30:57 +00:00
|
|
|
|
Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
|
1994-09-18 08:27:12 +00:00
|
|
|
|
and `minibuffer-setup-hook'."
|
|
|
|
|
(if (icomplete-simple-completing-p)
|
1999-12-28 18:14:44 +00:00
|
|
|
|
(let ((contents (buffer-substring (minibuffer-prompt-end)(point-max)))
|
1993-11-24 00:36:31 +00:00
|
|
|
|
(buffer-undo-list t))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
; Register the end of input, so we
|
|
|
|
|
; know where the extra stuff
|
|
|
|
|
; (match-status info) begins:
|
|
|
|
|
(if (not (boundp 'icomplete-eoinput))
|
|
|
|
|
;; In case it got wiped out by major mode business:
|
|
|
|
|
(make-local-variable 'icomplete-eoinput))
|
|
|
|
|
(setq icomplete-eoinput (point))
|
|
|
|
|
; Insert the match-status information:
|
2002-02-26 16:05:35 +00:00
|
|
|
|
(if (and (> (point-max) (minibuffer-prompt-end))
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
(or
|
|
|
|
|
;; Don't bother with delay after certain number of chars:
|
|
|
|
|
(> (point-max) icomplete-max-delay-chars)
|
|
|
|
|
;; Don't delay if alternatives number is small enough:
|
|
|
|
|
(if minibuffer-completion-table
|
|
|
|
|
(cond ((numberp minibuffer-completion-table)
|
|
|
|
|
(< minibuffer-completion-table
|
|
|
|
|
icomplete-delay-completions-threshold))
|
|
|
|
|
((sequencep minibuffer-completion-table)
|
|
|
|
|
(< (length minibuffer-completion-table)
|
|
|
|
|
icomplete-delay-completions-threshold))
|
|
|
|
|
))
|
|
|
|
|
;; Delay - give some grace time for next keystroke, before
|
|
|
|
|
;; embarking on computing completions:
|
|
|
|
|
(sit-for icomplete-compute-delay)))
|
2001-11-26 07:33:15 +00:00
|
|
|
|
(insert
|
1994-09-18 08:27:12 +00:00
|
|
|
|
(icomplete-completions contents
|
|
|
|
|
minibuffer-completion-table
|
|
|
|
|
minibuffer-completion-predicate
|
|
|
|
|
(not
|
|
|
|
|
minibuffer-completion-confirm))))))))
|
1995-08-22 20:30:57 +00:00
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_ > icomplete-completions (name candidates predicate require-match)
|
|
|
|
|
(defun icomplete-completions (name candidates predicate require-match)
|
1993-11-24 00:36:31 +00:00
|
|
|
|
"Identify prospective candidates for minibuffer completion.
|
|
|
|
|
|
1993-12-30 11:56:19 +00:00
|
|
|
|
The display is updated with each minibuffer keystroke during
|
1993-11-24 00:36:31 +00:00
|
|
|
|
minibuffer completion.
|
|
|
|
|
|
|
|
|
|
Prospective completion suffixes (if any) are displayed, bracketed by
|
|
|
|
|
one of \(), \[], or \{} pairs. The choice of brackets is as follows:
|
|
|
|
|
|
|
|
|
|
\(...) - a single prospect is identified and matching is enforced,
|
|
|
|
|
\[...] - a single prospect is identified but matching is optional, or
|
|
|
|
|
\{...} - multiple prospects, separated by commas, are indicated, and
|
1996-01-04 23:41:53 +00:00
|
|
|
|
further input is required to distinguish a single one.
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1996-01-04 23:41:53 +00:00
|
|
|
|
The displays for unambiguous matches have ` [Matched]' appended
|
1995-08-22 20:30:57 +00:00
|
|
|
|
\(whether complete or not), or ` \[No matches]', if no eligible
|
1997-06-15 02:37:58 +00:00
|
|
|
|
matches exist. \(Keybindings for uniquely matched commands
|
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc).
Integrated hacked up XEmacs immediate keybindings display. See
`icomplete-show-key-bindings', `icomplete-get-keys', and
`icomplete-completions'. Doesn't work with mainline GNU
Emacs 19.34 (because the cmdloop doesn't set owindow, and the
current-local-map doesn't take optional buffer arg), so feature
is, by default, inhibited unless we're running in XEmacs.
(icomplete-get-keys): Return keys bound to func name in buffer
"owindow" - since "owindow" is calling-buffer history present
only in XEmacs, this function is only useful in XEmacs.
(icomplete-max-delay-chars, icomplete-compute-delay): New vars.
(icomplete-delay-completions-threshold): New var.
These customize the delay behavior, so that completions don't
intrude as quickly for short input.
1997-05-29 18:18:23 +00:00
|
|
|
|
are exhibited within the square braces.)"
|
|
|
|
|
|
|
|
|
|
;; 'all-completions' doesn't like empty
|
|
|
|
|
;; minibuffer-completion-table's (ie: (nil))
|
|
|
|
|
(if (and (listp candidates) (null (car candidates)))
|
|
|
|
|
(setq candidates nil))
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
|
|
|
|
(let ((comps (all-completions name candidates predicate))
|
|
|
|
|
; "-determined" - only one candidate
|
|
|
|
|
(open-bracket-determined (if require-match "(" "["))
|
1999-11-21 13:44:26 +00:00
|
|
|
|
(close-bracket-determined (if require-match ")" "]")))
|
|
|
|
|
;; `concat'/`mapconcat' is the slow part. With the introduction of
|
|
|
|
|
;; `icomplete-prospects-length', there is no need for `catch'/`throw'.
|
|
|
|
|
(if (null comps) (format " %sNo matches%s"
|
|
|
|
|
open-bracket-determined
|
|
|
|
|
close-bracket-determined)
|
|
|
|
|
(let* ((most-try (try-completion name (mapcar (function list) comps)))
|
|
|
|
|
(most (if (stringp most-try) most-try (car comps)))
|
|
|
|
|
(most-len (length most))
|
|
|
|
|
(determ (and (> most-len (length name))
|
|
|
|
|
(concat open-bracket-determined
|
|
|
|
|
(substring most (length name))
|
|
|
|
|
close-bracket-determined)))
|
|
|
|
|
(open-bracket-prospects "{")
|
|
|
|
|
(close-bracket-prospects "}")
|
1993-11-24 00:36:31 +00:00
|
|
|
|
;"-prospects" - more than one candidate
|
1999-11-21 13:44:26 +00:00
|
|
|
|
(prospects-len 0)
|
|
|
|
|
prospects most-is-exact comp)
|
|
|
|
|
(if (eq most-try t)
|
|
|
|
|
(setq prospects nil)
|
|
|
|
|
(while (and comps (< prospects-len icomplete-prospects-length))
|
|
|
|
|
(setq comp (substring (car comps) most-len)
|
|
|
|
|
comps (cdr comps))
|
|
|
|
|
(cond ((string-equal comp "") (setq most-is-exact t))
|
|
|
|
|
((member comp prospects))
|
|
|
|
|
(t (setq prospects (cons comp prospects)
|
|
|
|
|
prospects-len (+ (length comp) 1 prospects-len))))))
|
|
|
|
|
(if prospects
|
|
|
|
|
(concat determ
|
|
|
|
|
open-bracket-prospects
|
|
|
|
|
(and most-is-exact ",")
|
|
|
|
|
(mapconcat 'identity
|
|
|
|
|
(sort prospects (function string-lessp))
|
|
|
|
|
",")
|
|
|
|
|
(and comps ",...")
|
|
|
|
|
close-bracket-prospects)
|
|
|
|
|
(concat determ
|
|
|
|
|
" [Matched"
|
|
|
|
|
(let ((keys (and icomplete-show-key-bindings
|
|
|
|
|
(commandp (intern-soft most))
|
|
|
|
|
(icomplete-get-keys most))))
|
|
|
|
|
(if keys
|
|
|
|
|
(concat "; " keys)
|
|
|
|
|
""))
|
|
|
|
|
"]"))))))
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
1998-01-24 11:35:59 +00:00
|
|
|
|
(if icomplete-mode
|
|
|
|
|
(icomplete-mode 1))
|
|
|
|
|
|
1994-09-18 08:27:12 +00:00
|
|
|
|
;;;_* Local emacs vars.
|
|
|
|
|
;;;Local variables:
|
|
|
|
|
;;;outline-layout: (-2 :)
|
|
|
|
|
;;;End:
|
1993-11-24 00:36:31 +00:00
|
|
|
|
|
|
|
|
|
;;; icomplete.el ends here
|