1 ;;;_. icomplete.el - minibuffer completion incremental feedback
3 ;;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
5 ;;; Author: Ken Manheimer <klm@nist.gov>
6 ;;; Maintainer: Ken Manheimer <klm@nist.gov>
7 ;;; Version: Id: icomplete.el,v 4.3 1994/08/31 18:48:29 klm Exp
8 ;;; Created: Mar 1993 klm@nist.gov - first release to usenet
9 ;;; Keywords: help, abbrev
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;; Loading this package implements a more fine-grained minibuffer
30 ;;; completion feedback scheme. Prospective completions are concisely
31 ;;; indicated within the minibuffer itself, with each successive
34 ;;; See 'icomplete-completions' docstring for a description of the
35 ;;; icomplete display format.
37 ;;; See the `icomplete-minibuffer-setup-hook' docstring for a means to
38 ;;; customize icomplete setup for interoperation with other
39 ;;; minibuffer-oriented packages.
41 ;;; To activate icomplete mode, simply load the package. You can
42 ;;; subsequently deactivate it by invoking the function icomplete-mode
43 ;;; with a negative prefix-arg (C-U -1 ESC-x icomplete-mode). Also,
44 ;;; you can prevent activation of the mode during package load by
45 ;;; first setting the variable `icomplete-mode' to nil. Icompletion
46 ;;; can be enabled any time after the package is loaded by invoking
47 ;;; icomplete-mode without a prefix arg.
49 ;;; Thanks to everyone for their suggestions for refinements of this
50 ;;; package. I particularly have to credit Michael Cook, who
51 ;;; implemented an incremental completion style in his 'iswitch'
52 ;;; functions that served as a model for icomplete. Some other
53 ;;; contributors: Noah Freidman (restructuring as minor mode), Colin
54 ;;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and
64 ;;;_* User Customization variables
67 ;;;_ = icomplete-minibuffer-setup-hook
68 (defvar icomplete-minibuffer-setup-hook nil
69 "*Icomplete-specific customization of minibuffer setup.
71 This hook is run during minibuffer setup iff icomplete will be active.
72 It is intended for use in customizing icomplete for interoperation
73 with other packages. For instance:
75 \(add-hook 'icomplete-minibuffer-setup-hook
78 \(make-local-variable 'resize-minibuffer-window-max-height)
79 \(setq resize-minibuffer-window-max-height 3))))
81 will constrain rsz-mini to a maximum minibuffer height of 3 lines when
82 icompletion is occurring.")
84 ;;;_ + Internal Variables
86 (defvar icomplete-mode t
87 "Non-nil enables incremental minibuffer completion, once
88 `\\[icomplete-mode]' function has set things up.")
89 ;;;_ = icomplete-eoinput 1
90 (defvar icomplete-eoinput
1
91 "Point where minibuffer input ends and completion info begins.")
92 (make-variable-buffer-local 'icomplete-eoinput
)
93 ;;;_ = icomplete-pre-command-hook
94 (defvar icomplete-pre-command-hook nil
95 "Incremental-minibuffer-completion pre-command-hook.
97 Is run in minibuffer before user input when `icomplete-mode' is non-nil.
98 Use `icomplete-mode' function to set it up properly for incremental
99 minibuffer completion.")
100 (add-hook 'icomplete-pre-command-hook
'icomplete-tidy
)
101 ;;;_ = icomplete-post-command-hook
102 (defvar icomplete-post-command-hook nil
103 "Incremental-minibuffer-completion post-command-hook.
105 Is run in minibuffer after user input when `icomplete-mode' is non-nil.
106 Use `icomplete-mode' function to set it up properly for incremental
107 minibuffer completion.")
108 (add-hook 'icomplete-post-command-hook
'icomplete-exhibit
)
110 ;;;_ > icomplete-mode (&optional prefix)
112 (defun icomplete-mode (&optional prefix
)
113 "Activate incremental minibuffer completion for this emacs session,
114 or deactivate with negative prefix arg."
116 (or prefix
(setq prefix
0))
118 (setq icomplete-mode t
)
119 ;; The following is not really necessary after first time -
121 (add-hook 'minibuffer-setup-hook
'icomplete-minibuffer-setup
))
122 (t (setq icomplete-mode nil
))))
124 ;;;_ > icomplete-simple-completing-p ()
125 (defun icomplete-simple-completing-p ()
127 "Non-nil if current window is minibuffer that's doing simple completion.
130 the selected window is a minibuffer,
131 and not in the middle of macro execution,
132 and minibuffer-completion-table is not a symbol (which would
133 indicate some non-standard, non-simple completion mechansm,
134 like file-name and other custom-func completions)."
136 (and (window-minibuffer-p (selected-window))
137 (not executing-macro
)
138 (not (symbolp minibuffer-completion-table
))))
140 ;;;_ > icomplete-minibuffer-setup ()
142 (defun icomplete-minibuffer-setup ()
143 "Run in minibuffer on activation to establish incremental completion.
144 Usually run by inclusion in `minibuffer-setup-hook'."
145 (cond ((and icomplete-mode
(icomplete-simple-completing-p))
146 (make-local-hook 'pre-command-hook
)
147 (add-hook 'pre-command-hook
149 (run-hooks 'icomplete-pre-command-hook
)))
151 (make-local-hook 'post-command-hook
)
152 (add-hook 'post-command-hook
154 (run-hooks 'icomplete-post-command-hook
)))
156 (run-hooks 'icomplete-minibuffer-setup-hook
))))
160 ;;;_ > icomplete-tidy ()
161 (defun icomplete-tidy ()
162 "Remove completions display \(if any) prior to new user input.
163 Should be run in on the minibuffer `pre-command-hook'. See `icomplete-mode'
164 and `minibuffer-setup-hook'."
165 (if (icomplete-simple-completing-p)
166 (if (and (boundp 'icomplete-eoinput
)
169 (if (> icomplete-eoinput
(point-max))
170 ;; Oops, got rug pulled out from under us - reinit:
171 (setq icomplete-eoinput
(point-max))
172 (let ((buffer-undo-list buffer-undo-list
)) ; prevent entry
173 (delete-region icomplete-eoinput
(point-max))))
175 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
176 (make-local-variable 'icomplete-eoinput
)
177 (setq icomplete-eoinput
1))))
179 ;;;_ > icomplete-exhibit ()
180 (defun icomplete-exhibit ()
181 "Insert icomplete completions display.
182 Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
183 and `minibuffer-setup-hook'."
184 (if (icomplete-simple-completing-p)
185 (let ((contents (buffer-substring (point-min)(point-max)))
186 (buffer-undo-list t
))
188 (goto-char (point-max))
189 ; Register the end of input, so we
190 ; know where the extra stuff
191 ; (match-status info) begins:
192 (if (not (boundp 'icomplete-eoinput
))
193 ;; In case it got wiped out by major mode business:
194 (make-local-variable 'icomplete-eoinput
))
195 (setq icomplete-eoinput
(point))
196 ; Insert the match-status information:
197 (if (> (point-max) 1)
199 (icomplete-completions contents
200 minibuffer-completion-table
201 minibuffer-completion-predicate
203 minibuffer-completion-confirm
))))))))
205 ;;;_ > icomplete-completions (name candidates predicate require-match)
206 (defun icomplete-completions (name candidates predicate require-match
)
207 "Identify prospective candidates for minibuffer completion.
209 The display is updated with each minibuffer keystroke during
210 minibuffer completion.
212 Prospective completion suffixes (if any) are displayed, bracketed by
213 one of \(), \[], or \{} pairs. The choice of brackets is as follows:
215 \(...) - a single prospect is identified and matching is enforced,
216 \[...] - a single prospect is identified but matching is optional, or
217 \{...} - multiple prospects, separated by commas, are indicated, and
218 further input is required to distingish a single one.
220 The displays for disambiguous matches have ` [Matched]' appended
221 \(whether complete or not), or ` \[No matches]', if no eligible
224 (let ((comps (all-completions name candidates predicate
))
225 ; "-determined" - only one candidate
226 (open-bracket-determined (if require-match
"(" "["))
227 (close-bracket-determined (if require-match
")" "]"))
228 ;"-prospects" - more than one candidate
229 (open-bracket-prospects "{")
230 (close-bracket-prospects "}")
232 (cond ((null comps
) (format " %sNo matches%s"
233 open-bracket-determined
234 close-bracket-determined
))
235 ((null (cdr comps
)) ;one match
236 (concat (if (and (> (length (car comps
))
238 (concat open-bracket-determined
239 (substring (car comps
) (length name
))
240 close-bracket-determined
)
244 (let* ((most (try-completion name candidates predicate
))
245 (most-len (length most
))
252 (mapcar '(lambda (com)
253 (if (= (length com
) most-len
)
254 ;; Most is one exact match,
255 ;; note that and leave out
256 ;; for later indication:
258 (setq most-is-exact t
)
264 (concat (and (> most-len
(length name
))
265 (concat open-bracket-determined
266 (substring most
(length name
))
267 close-bracket-determined
))
268 open-bracket-prospects
270 (concat "," alternatives
)
272 close-bracket-prospects
))))))
274 ;;;_ + Initialization
275 ;;; If user hasn't setq-default icomplete-mode to nil, then setup for
281 ;;;_* Local emacs vars.
283 ;;;outline-layout: (-2 :)
286 ;;; icomplete.el ends here