annotate lisp/packages/icomplete.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; icomplete.el --- minibuffer completion with incremental feedback
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; Author: Ken Manheimer <klm@nist.gov>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Maintainer: Ken Manheimer <klm@nist.gov>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Version: $Id: icomplete.el,v 1.1.1.1 1996/12/18 03:31:39 steve Exp $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Created: Mar 1993 klm@nist.gov - first release to usenet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Keywords: help, abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; Hacked for XEmacs: David Hughes 7th September 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Synched up with: FSF 19.29.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Loading this package implements a more fine-grained minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; completion feedback scheme. Prospective completions are concisely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; indicated within the minibuffer itself, with each successive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; keystroke.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; See 'icomplete-completions' docstring for a description of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; icomplete display format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; See the `icomplete-minibuffer-setup-hook' docstring for a means to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; customize icomplete setup for interoperation with other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; minibuffer-oriented packages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; To activate icomplete mode, simply load the package. You can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; subsequently deactivate it by invoking the function icomplete-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; with a negative prefix-arg (C-U -1 ESC-x icomplete-mode). Also,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; you can prevent activation of the mode during package load by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; first setting the variable `icomplete-mode' to nil. Icompletion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; can be enabled any time after the package is loaded by invoking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; icomplete-mode without a prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; This version of icomplete runs on Emacs 19.18 and later. (It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; depends on the incorporation of minibuffer-setup-hook.) The elisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; archives, ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; probably still has a version that works in GNU Emacs v18.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; Thanks to everyone for their suggestions for refinements of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; package. I particularly have to credit Michael Cook, who
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; implemented an incremental completion style in his 'iswitch'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; functions that served as a model for icomplete. Some other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; contributors: Noah Freidman (restructuring as minor mode), Colin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; others.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; klm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;_* Provide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (provide 'icomplete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;_* User Customization variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar icomplete-compute-delay .3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "*Completions-computation stall, used only with large-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 completions - see `icomplete-delay-completions-threshold'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar icomplete-delay-completions-threshold 400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "*Pending-completions number over which to apply icomplete-compute-delay.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defvar icomplete-max-delay-chars 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "*Maximum number of initial chars to apply icomplete compute delay.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;;_* Initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;;_ = icomplete-minibuffer-setup-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar icomplete-minibuffer-setup-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "*Icomplete-specific customization of minibuffer setup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 This hook is run during minibuffer setup iff icomplete will be active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 It is intended for use in customizing icomplete for interoperation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 with other packages. For instance:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 \(add-hook 'icomplete-minibuffer-setup-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 \(function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 \(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 \(make-local-variable 'resize-minibuffer-window-max-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 \(setq resize-minibuffer-window-max-height 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 will constrain rsz-mini to a maximum minibuffer height of 3 lines when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 icompletion is occurring.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;;_ + Internal Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;;_ = icomplete-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defvar icomplete-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 "Non-nil enables incremental minibuffer completion, once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 `\\[icomplete-mode]' function has set things up.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;;_ = icomplete-eoinput 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defvar icomplete-eoinput 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Point where minibuffer input ends and completion info begins.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (make-variable-buffer-local 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;;_ = icomplete-pre-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defvar icomplete-pre-command-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 "Incremental-minibuffer-completion pre-command-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Is run in minibuffer before user input when `icomplete-mode' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 Use `icomplete-mode' function to set it up properly for incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 minibuffer completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;;_ = icomplete-post-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defvar icomplete-post-command-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Incremental-minibuffer-completion post-command-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 Is run in minibuffer after user input when `icomplete-mode' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 Use `icomplete-mode' function to set it up properly for incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 minibuffer completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;;_ > icomplete-run-pre-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun icomplete-run-pre-command-hooks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (run-hooks 'icomplete-pre-command-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;;_ > icomplete-run-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun icomplete-run-post-command-hooks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (run-hooks 'icomplete-post-command-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;;_ > icomplete-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun icomplete-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "Activate incremental minibuffer completion for this emacs session,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 or deactivate with negative prefix arg."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (or prefix (setq prefix 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (cond ((>= prefix 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq icomplete-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; The following is not really necessary after first time -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; no great loss.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (t (setq icomplete-mode nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;;_ > icomplete-simple-completing-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun icomplete-simple-completing-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "Non-nil if current window is minibuffer that's doing simple completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 Conditions are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 the selected window is a minibuffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 and not in the middle of macro execution,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 and minibuffer-completion-table is not a symbol (which would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 indicate some non-standard, non-simple completion mechansm,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 like file-name and other custom-func completions)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (not executing-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (not (symbolp minibuffer-completion-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;;_ > icomplete-minibuffer-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun icomplete-minibuffer-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "Run in minibuffer on activation to establish incremental completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 Usually run by inclusion in minibuffer-setup-hook."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (cond ((and icomplete-mode (icomplete-simple-completing-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (make-local-hook 'pre-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (add-hook 'pre-command-hook 'icomplete-run-pre-command-hooks nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (make-local-hook 'post-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (add-hook 'post-command-hook 'icomplete-run-post-command-hooks nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (run-hooks 'icomplete-minibuffer-setup-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;;_* Completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;;_ > icomplete-tidy ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defun icomplete-tidy ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "Remove completions display \(if any) prior to new user input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 Should be run in on the minibuffer pre-command-hook. See `icomplete-mode'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 and `minibuffer-setup-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (icomplete-simple-completing-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (and (boundp 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (> icomplete-eoinput (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Oops, got rug pulled out from under us - reinit:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (setq icomplete-eoinput (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (delete-region icomplete-eoinput (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (make-local-variable 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (setq icomplete-eoinput 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;;_ > icomplete-exhibit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun icomplete-exhibit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Insert icomplete completions display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Should be run via minibuffer post-command-hook. See `icomplete-mode'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 and `minibuffer-setup-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (if (icomplete-simple-completing-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let* ((contents (buffer-substring (point-min)(point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (buffer-undo-list t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ; Register the end of input, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ; know where the extra stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ; (match-status info) begins:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (if (not (boundp 'icomplete-eoinput))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; In case it got wiped out by major mode business:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (make-local-variable 'icomplete-eoinput))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setq icomplete-eoinput (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ; Insert the match-status information:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if (and (> (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; Don't bother with delay after certain number of chars:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (> (point-max) icomplete-max-delay-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; Don't delay if alternatives number is small enough:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (cond ((numberp minibuffer-completion-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (< minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 icomplete-delay-completions-threshold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ((sequencep minibuffer-completion-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (< (length minibuffer-completion-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 icomplete-delay-completions-threshold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; Delay - give some grace time for next keystroke, before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; embarking on computing completions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (sit-for icomplete-compute-delay)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (insert-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (icomplete-completions contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 minibuffer-completion-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 minibuffer-completion-confirm))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;;_ > icomplete-completions (name candidates predicate require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defun icomplete-completions (name candidates predicate require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 "Identify prospective candidates for minibuffer completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 The display is updated with each minibuffer keystroke during
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 minibuffer completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Prospective completion suffixes (if any) are displayed, bracketed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 one of \(), \[], or \{} pairs. The choice of brackets is as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 \(...) - a single prospect is identified and matching is enforced,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 \[...] - a single prospect is identified but matching is optional, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 \{...} - multiple prospects, separated by commas, are indicated, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 further input is required to distingish a single one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 The displays for disambiguous matches have \" [Matched]\" appended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 \(whether complete or not), or \" \[No matches]\", if no eligible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 matches exist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (let ((comps (all-completions name candidates predicate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ; "-determined" - only one candidate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (open-bracket-determined (if require-match "(" "["))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (close-bracket-determined (if require-match ")" "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;"-prospects" - more than one candidate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (open-bracket-prospects "{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (close-bracket-prospects "}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (catch 'input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (cond ((null comps) (format " %sNo matches%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 open-bracket-determined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 close-bracket-determined))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ((null (cdr comps)) ;one match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (concat (if (and (> (length (car comps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (length name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (concat open-bracket-determined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (substring (car comps) (length name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 close-bracket-determined)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 " [Matched]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (t ;multiple matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (let* ((most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (try-completion name candidates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (and predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; Wrap predicate in impatience - ie,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; `throw' up when pending input is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; noticed. Adds some overhead to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; predicate, but should be worth it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (lambda (item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (input-pending-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (throw 'input "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (apply predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 item nil)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (most-len (length most))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 most-is-exact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (alternatives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (apply (function concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (lambda (com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if (input-pending-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (throw 'input ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (= (length com) most-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; Most is one exact match,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; note that and leave out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;; for later indication:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq most-is-exact t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (concat ","
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (substring com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 most-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 comps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (concat (and (> most-len (length name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (concat open-bracket-determined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (substring most (length name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 close-bracket-determined))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 open-bracket-prospects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if most-is-exact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ;; Add a ',' at the front to indicate "complete but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; not unique":
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (concat "," alternatives)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 alternatives)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 close-bracket-prospects)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;;;_ + Initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;;; If user hasn't setq-default icomplete-mode to nil, then setup for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;;; activation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (if icomplete-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (icomplete-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;;;_* Local emacs vars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;;;Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;;;outline-layout: (-2 :)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;;;End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;;; icomplete.el ends here