annotate lisp/icomplete.el @ 76030:efb5f82c7b14

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Tue, 20 Feb 2007 02:23:04 +0000
parents e3694f1cb928
children b7ca30840f44 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29154
23a0f9dcc01d Fix header for Finder.
Dave Love <fx@gnu.org>
parents: 27023
diff changeset
1 ;;; icomplete.el --- minibuffer completion incremental feedback
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74296
diff changeset
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
6 ;; Author: Ken Manheimer <klm@i.am>
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
7 ;; Maintainer: Ken Manheimer <klm@i.am>
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
8 ;; Created: Mar 1993 Ken Manheimer, klm@nist.gov - first release to usenet
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
9 ;; Last update: Ken Manheimer <klm@i.am>, 11/18/1999.
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 12933
diff changeset
10 ;; Keywords: help, abbrev
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
12 ;; This file is part of GNU Emacs.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
13
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
17 ;; any later version.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
18
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
19 ;; GNU Emacs is distributed in the hope that it will be useful,
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
22 ;; GNU General Public License for more details.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
23
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
24 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60853
diff changeset
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60853
diff changeset
27 ;; Boston, MA 02110-1301, USA.
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
28
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Commentary:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
31 ;; Loading this package implements a more fine-grained minibuffer
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
32 ;; completion feedback scheme. Prospective completions are concisely
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
33 ;; indicated within the minibuffer itself, with each successive
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
34 ;; keystroke.
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
35
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
36 ;; See `icomplete-completions' docstring for a description of the
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
37 ;; icomplete display format.
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
38
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
39 ;; See the `icomplete-minibuffer-setup-hook' docstring for a means to
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
40 ;; customize icomplete setup for interoperation with other
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
41 ;; minibuffer-oriented packages.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
43 ;; To activate icomplete mode, load the package and use the
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
44 ;; `icomplete-mode' function. You can subsequently deactivate it by
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
45 ;; invoking the function icomplete-mode with a negative prefix-arg
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
46 ;; (C-U -1 ESC-x icomplete-mode). Also, you can prevent activation of
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
47 ;; the mode during package load by first setting the variable
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
48 ;; `icomplete-mode' to nil. Icompletion can be enabled any time after
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
49 ;; the package is loaded by invoking icomplete-mode without a prefix
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
50 ;; arg.
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
51
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
52 ;; Thanks to everyone for their suggestions for refinements of this
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
53 ;; package. I particularly have to credit Michael Cook, who
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
54 ;; implemented an incremental completion style in his 'iswitch'
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
55 ;; functions that served as a model for icomplete. Some other
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
56 ;; contributors: Noah Friedman (restructuring as minor mode), Colin
18251
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
57 ;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and others.
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
58
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13989
diff changeset
59 ;; klm.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; Code:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
63 ;;;_* Provide
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (provide 'icomplete)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
66
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
67 (defgroup icomplete nil
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
68 "Show completions dynamically in minibuffer."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
69 :prefix "icomplete-"
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
70 :group 'minibuffer)
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
71
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
72 ;;;_* User Customization variables
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
73 (defcustom icomplete-prospects-length 80
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
74 "*Length of string displaying the prospects."
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
75 :type 'integer
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
76 :group 'icomplete)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
77
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
78 (defcustom icomplete-compute-delay .3
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
79 "*Completions-computation stall, used only with large-number
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
80 completions - see `icomplete-delay-completions-threshold'."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
81 :type 'number
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
82 :group 'icomplete)
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
83
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
84 (defcustom icomplete-delay-completions-threshold 400
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
85 "*Pending-completions number over which to apply icomplete-compute-delay."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
86 :type 'integer
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
87 :group 'icomplete)
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
88
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
89 (defcustom icomplete-max-delay-chars 3
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
90 "*Maximum number of initial chars to apply icomplete compute delay."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
91 :type 'integer
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
92 :group 'icomplete)
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
93
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
94 (defcustom icomplete-show-key-bindings t
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
95 "*If non-nil, show key bindings as well as completion for sole matches."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
96 :type 'boolean
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
97 :group 'icomplete)
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
98
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
99 (defcustom icomplete-minibuffer-setup-hook nil
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
100 "*Icomplete-specific customization of minibuffer setup.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
101
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
102 This hook is run during minibuffer setup iff icomplete will be active.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
103 It is intended for use in customizing icomplete for interoperation
35467
d9a298a82b9a (icomplete-minibuffer-setup-hook): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 29154
diff changeset
104 with other features and packages. For instance:
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
105
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
106 \(add-hook 'icomplete-minibuffer-setup-hook
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
107 \(function
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
108 \(lambda ()
35467
d9a298a82b9a (icomplete-minibuffer-setup-hook): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 29154
diff changeset
109 \(make-local-variable 'max-mini-window-height)
d9a298a82b9a (icomplete-minibuffer-setup-hook): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 29154
diff changeset
110 \(setq max-mini-window-height 3))))
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
111
35467
d9a298a82b9a (icomplete-minibuffer-setup-hook): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 29154
diff changeset
112 will constrain Emacs to a maximum minibuffer height of 3 lines when
20764
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
113 icompletion is occurring."
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
114 :type 'hook
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
115 :group 'icomplete)
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
116
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
117
d1d94511b3b7 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18251
diff changeset
118 ;;;_* Initialization
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
120 ;;;_ + Internal Variables
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
121 ;;;_ = icomplete-eoinput nil
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
122 (defvar icomplete-eoinput nil
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 "Point where minibuffer input ends and completion info begins.")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (make-variable-buffer-local 'icomplete-eoinput)
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
125 ;;;_ = icomplete-pre-command-hook
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
126 (defvar icomplete-pre-command-hook nil
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
127 "Incremental-minibuffer-completion pre-command-hook.
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
128
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
129 Is run in minibuffer before user input when `icomplete-mode' is non-nil.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
130 Use `icomplete-mode' function to set it up properly for incremental
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
131 minibuffer completion.")
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
132 (add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
133 ;;;_ = icomplete-post-command-hook
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
134 (defvar icomplete-post-command-hook nil
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
135 "Incremental-minibuffer-completion post-command-hook.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
137 Is run in minibuffer after user input when `icomplete-mode' is non-nil.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
138 Use `icomplete-mode' function to set it up properly for incremental
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
139 minibuffer completion.")
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
140 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
141
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
142 (defun icomplete-get-keys (func-name)
18251
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
143 "Return strings naming keys bound to `func-name', or nil if none.
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
144 Examines the prior, not current, buffer, presuming that current buffer
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
145 is minibuffer."
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
146 (if (commandp func-name)
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
147 (save-excursion
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
148 (let* ((sym (intern func-name))
68983
064f4da012f5 (icomplete-get-keys): Use `t' for the second arg `visible-ok'
Juri Linkov <juri@jurta.org>
parents: 68866
diff changeset
149 (buf (other-buffer nil t))
18251
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
150 (map (save-excursion (set-buffer buf) (current-local-map)))
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
151 (keys (where-is-internal sym map)))
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
152 (if keys
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
153 (concat "<"
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
154 (mapconcat 'key-description
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
155 (sort keys
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
156 #'(lambda (x y)
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
157 (< (length x) (length y))))
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
158 ", ")
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
159 ">"))))))
73078
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
160 ;;;_ = icomplete-with-completion-tables
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
161 (defvar icomplete-with-completion-tables '(internal-complete-buffer)
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
162 "Specialized completion tables with which icomplete should operate.
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
163
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
164 Icomplete does not operate with any specialized completion tables
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
165 except those on this list.")
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
166
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
167 ;;;_ > icomplete-mode (&optional prefix)
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
168 ;;;###autoload
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
169 (define-minor-mode icomplete-mode
37171
b2411ccdbf22 (icomplete-mode): Treat an argument like other
Gerd Moellmann <gerd@gnu.org>
parents: 35467
diff changeset
170 "Toggle incremental minibuffer completion for this Emacs session.
b2411ccdbf22 (icomplete-mode): Treat an argument like other
Gerd Moellmann <gerd@gnu.org>
parents: 35467
diff changeset
171 With a numeric argument, turn Icomplete mode on iff ARG is positive."
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
172 :global t :group 'icomplete
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
173 (if icomplete-mode
37171
b2411ccdbf22 (icomplete-mode): Treat an argument like other
Gerd Moellmann <gerd@gnu.org>
parents: 35467
diff changeset
174 ;; The following is not really necessary after first time -
b2411ccdbf22 (icomplete-mode): Treat an argument like other
Gerd Moellmann <gerd@gnu.org>
parents: 35467
diff changeset
175 ;; no great loss.
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
176 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
177 (remove-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
179 ;;;_ > icomplete-simple-completing-p ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
180 (defun icomplete-simple-completing-p ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
181 "Non-nil if current window is minibuffer that's doing simple completion.
8434
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
182
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
183 Conditions are:
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
184 the selected window is a minibuffer,
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
185 and not in the middle of macro execution,
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
186 and `minibuffer-completion-table' is not a symbol (which would
13989
d60fffb9acd1 (icomplete-simple-completing-p, icomplete-completions):
Karl Heuer <kwzh@gnu.org>
parents: 13337
diff changeset
187 indicate some non-standard, non-simple completion mechanism,
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
188 like file-name and other custom-func completions)."
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
189
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
190 (and (window-minibuffer-p (selected-window))
15302
c23c9712ef5c Use executing-kbd-macro, not executing-macro.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
191 (not executing-kbd-macro)
60853
53a24edea9ee (icomplete-simple-completing-p): Don't turn on icomplete
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 60805
diff changeset
192 minibuffer-completion-table
73078
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
193 (or (not (functionp minibuffer-completion-table))
4bf12abbb384 2006-09-23 Ken Manheimer <ken.manheimer@gmail.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 68983
diff changeset
194 (member minibuffer-completion-table
73095
9566558723f8 * icomplete.el (icomplete-simple-completing-p): Use the correct
Chong Yidong <cyd@stupidchicken.com>
parents: 73078
diff changeset
195 icomplete-with-completion-tables))))
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
196
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
197 ;;;_ > icomplete-minibuffer-setup ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
198 (defun icomplete-minibuffer-setup ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
199 "Run in minibuffer on activation to establish incremental completion.
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
200 Usually run by inclusion in `minibuffer-setup-hook'."
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
201 (when (and icomplete-mode (icomplete-simple-completing-p))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
202 (add-hook 'pre-command-hook
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
203 (lambda () (run-hooks 'icomplete-pre-command-hook))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
204 nil t)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
205 (add-hook 'post-command-hook
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
206 (lambda () (run-hooks 'icomplete-post-command-hook))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
207 nil t)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
208 (run-hooks 'icomplete-minibuffer-setup-hook)))
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
209 ;
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
210
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
211
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
212 ;;;_* Completion
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
213
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
214 ;;;_ > icomplete-tidy ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
215 (defun icomplete-tidy ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
216 "Remove completions display \(if any) prior to new user input.
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
217 Should be run in on the minibuffer `pre-command-hook'. See `icomplete-mode'
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
218 and `minibuffer-setup-hook'."
74296
9e75cb6ef88c (icomplete-tidy, icomplete-exhibit): Check that
Kim F. Storm <storm@cua.dk>
parents: 73095
diff changeset
219 (when (and icomplete-mode icomplete-eoinput)
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
220
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
221 (unless (>= icomplete-eoinput (point-max))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
222 (let ((buffer-undo-list t)) ; prevent entry
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
223 (delete-region icomplete-eoinput (point-max))))
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
224
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
225 ;; Reestablish the safe value.
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
226 (setq icomplete-eoinput nil)))
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
227
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
228 ;;;_ > icomplete-exhibit ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
229 (defun icomplete-exhibit ()
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
230 "Insert icomplete completions display.
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
231 Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
232 and `minibuffer-setup-hook'."
74296
9e75cb6ef88c (icomplete-tidy, icomplete-exhibit): Check that
Kim F. Storm <storm@cua.dk>
parents: 73095
diff changeset
233 (when (and icomplete-mode (icomplete-simple-completing-p))
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
234 (save-excursion
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
235 (goto-char (point-max))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
236 ;; Register the end of input, so we know where the extra stuff
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
237 ;; (match-status info) begins:
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
238 (setq icomplete-eoinput (point))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ; Insert the match-status information:
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
240 (if (and (> (point-max) (minibuffer-prompt-end))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
241 buffer-undo-list ; Wait for some user input.
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
242 (or
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
243 ;; Don't bother with delay after certain number of chars:
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
244 (> (- (point) (field-beginning)) icomplete-max-delay-chars)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
245 ;; Don't delay if alternatives number is small enough:
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
246 (and (sequencep minibuffer-completion-table)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
247 (< (length minibuffer-completion-table)
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
248 icomplete-delay-completions-threshold))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
249 ;; Delay - give some grace time for next keystroke, before
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
250 ;; embarking on computing completions:
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
251 (sit-for icomplete-compute-delay)))
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
252 (let ((text (while-no-input
64793
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
253 (list
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
254 (icomplete-completions
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
255 (field-string)
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
256 minibuffer-completion-table
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
257 minibuffer-completion-predicate
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
258 (not minibuffer-completion-confirm)))))
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
259 (buffer-undo-list t))
64793
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
260 ;; Do nothing if while-no-input was aborted.
2898eac3abad (icomplete-exhibit): Adapt to new while-no-input calling convention.
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
261 (if (consp text) (insert (car text))))))))
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
262
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
263 ;;;_ > icomplete-completions (name candidates predicate require-match)
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
264 (defun icomplete-completions (name candidates predicate require-match)
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 "Identify prospective candidates for minibuffer completion.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
267 The display is updated with each minibuffer keystroke during
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 minibuffer completion.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 Prospective completion suffixes (if any) are displayed, bracketed by
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 one of \(), \[], or \{} pairs. The choice of brackets is as follows:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 \(...) - a single prospect is identified and matching is enforced,
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 \[...] - a single prospect is identified but matching is optional, or
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 \{...} - multiple prospects, separated by commas, are indicated, and
13989
d60fffb9acd1 (icomplete-simple-completing-p, icomplete-completions):
Karl Heuer <kwzh@gnu.org>
parents: 13337
diff changeset
276 further input is required to distinguish a single one.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
13989
d60fffb9acd1 (icomplete-simple-completing-p, icomplete-completions):
Karl Heuer <kwzh@gnu.org>
parents: 13337
diff changeset
278 The displays for unambiguous matches have ` [Matched]' appended
12933
61f11030ecc9 (icomplete-minibuffer-setup): Use make-local-hook
Richard M. Stallman <rms@gnu.org>
parents: 11035
diff changeset
279 \(whether complete or not), or ` \[No matches]', if no eligible
18251
e0327e90d706 Don't call icomplete-mode; let the user do that.
Richard M. Stallman <rms@gnu.org>
parents: 18060
diff changeset
280 matches exist. \(Keybindings for uniquely matched commands
18029
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
281 are exhibited within the square braces.)"
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
282
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
283 ;; 'all-completions' doesn't like empty
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
284 ;; minibuffer-completion-table's (ie: (nil))
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
285 (if (and (listp candidates) (null (car candidates)))
82a56bdb2381 Integrated Emacs 19.34 and XEmacs 19.15
Karl Heuer <kwzh@gnu.org>
parents: 15302
diff changeset
286 (setq candidates nil))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (let ((comps (all-completions name candidates predicate))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ; "-determined" - only one candidate
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (open-bracket-determined (if require-match "(" "["))
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
291 (close-bracket-determined (if require-match ")" "]")))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
292 ;; `concat'/`mapconcat' is the slow part. With the introduction of
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
293 ;; `icomplete-prospects-length', there is no need for `catch'/`throw'.
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
294 (if (null comps) (format " %sNo matches%s"
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
295 open-bracket-determined
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
296 close-bracket-determined)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
297 (let* ((most-try (try-completion name (mapcar (function list) comps)))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
298 (most (if (stringp most-try) most-try (car comps)))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
299 (most-len (length most))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
300 (determ (and (> most-len (length name))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
301 (concat open-bracket-determined
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
302 (substring most (length name))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
303 close-bracket-determined)))
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
304 ;;"-prospects" - more than one candidate
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
305 (prospects-len 0)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
306 prospects most-is-exact comp)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
307 (if (eq most-try t)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
308 (setq prospects nil)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
309 (while (and comps (< prospects-len icomplete-prospects-length))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
310 (setq comp (substring (car comps) most-len)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
311 comps (cdr comps))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
312 (cond ((string-equal comp "") (setq most-is-exact t))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
313 ((member comp prospects))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
314 (t (setq prospects (cons comp prospects)
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
315 prospects-len (+ (length comp) 1 prospects-len))))))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
316 (if prospects
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
317 (concat determ
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
318 "{"
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
319 (and most-is-exact ",")
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
320 (mapconcat 'identity
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
321 (sort prospects (function string-lessp))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
322 ",")
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
323 (and comps ",...")
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
324 "}")
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
325 (concat determ
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
326 " [Matched"
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
327 (let ((keys (and icomplete-show-key-bindings
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
328 (commandp (intern-soft most))
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
329 (icomplete-get-keys most))))
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
330 (if keys (concat "; " keys) ""))
26516
d9368f38a7b5 (icomplete-completions): Use an explicit variable
Gerd Moellmann <gerd@gnu.org>
parents: 24644
diff changeset
331 "]"))))))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
333 ;;;_* Local emacs vars.
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
334 ;;;Local variables:
68866
5340157fbfc2 * files.el (safe-local-variable-values): New option.
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
335 ;;;allout-layout: (-2 :)
8871
299cfe0a6069 Major rewrite to behave more like a minor mode.
Richard M. Stallman <rms@gnu.org>
parents: 8434
diff changeset
336 ;;;End:
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
60805
aba5f8c41ae0 Don't forcibly turn on the mode upon load.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
338 ;; arch-tag: 339ec25a-0741-4eb6-be63-997532e89b0f
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ;;; icomplete.el ends here