aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2005-03-21 19:19:26 +0000
committerStefan Monnier2005-03-21 19:19:26 +0000
commit47fda8fcf65b290cb794cf13e3617b3c60812e48 (patch)
treed65cde7129feab1684aefb0a30ebb79f740b3dbb
parentc9f63b41575d1db78e7ac7f493a626cd6e6ea230 (diff)
downloademacs-47fda8fcf65b290cb794cf13e3617b3c60812e48.tar.gz
emacs-47fda8fcf65b290cb794cf13e3617b3c60812e48.zip
Don't forcibly turn on the mode upon load.
(icomplete-mode): Use define-minor-mode. (icomplete-eoinput): Default to nil. (icomplete-minibuffer-setup): Remove autoload. (icomplete-tidy): Simplify. (icomplete-exhibit): Use buffer-undo-list to determine if we're still in the initial state or if the user has modified the field. Fix handling of icomplete-max-delay-chars. Remove code that handles the oddball case where minibuffer-completion-table is an integer. Wrap icomplete-completions in while-no-input in case building completions takes more time than expected. (icomplete-completions): Simplify.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/icomplete.el152
2 files changed, 73 insertions, 95 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 58f16948876..f33e7e9ec86 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12005-03-21 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * icomplete.el: Don't forcibly turn on the mode upon load.
4 (icomplete-mode): Use define-minor-mode.
5 (icomplete-eoinput): Default to nil.
6 (icomplete-minibuffer-setup): Remove autoload.
7 (icomplete-tidy): Simplify.
8 (icomplete-exhibit): Use buffer-undo-list to determine if we're still
9 in the initial state or if the user has modified the field.
10 Fix handling of icomplete-max-delay-chars.
11 Remove code that handles the oddball case where
12 minibuffer-completion-table is an integer.
13 Wrap icomplete-completions in while-no-input in case building
14 completions takes more time than expected.
15 (icomplete-completions): Simplify.
16
12005-03-21 Richard M. Stallman <rms@gnu.org> 172005-03-21 Richard M. Stallman <rms@gnu.org>
2 18
3 * jka-compr.el (jka-compr-really-do-compress): 19 * jka-compr.el (jka-compr-really-do-compress):
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 6317662d394..49977276aac 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -1,7 +1,7 @@
1;;; icomplete.el --- minibuffer completion incremental feedback 1;;; icomplete.el --- minibuffer completion incremental feedback
2 2
3;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001 3;; Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2005
4;;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
5 5
6;; Author: Ken Manheimer <klm@i.am> 6;; Author: Ken Manheimer <klm@i.am>
7;; Maintainer: Ken Manheimer <klm@i.am> 7;; Maintainer: Ken Manheimer <klm@i.am>
@@ -69,19 +69,6 @@
69 :prefix "icomplete-" 69 :prefix "icomplete-"
70 :group 'minibuffer) 70 :group 'minibuffer)
71 71
72(defcustom icomplete-mode nil
73 "*Toggle incremental minibuffer completion.
74As text is typed into the minibuffer, prospective completions are indicated
75in the minibuffer.
76Setting this variable directly does not take effect;
77use either \\[customize] or the function `icomplete-mode'."
78 :set (lambda (symbol value)
79 (icomplete-mode (if value 1 -1)))
80 :initialize 'custom-initialize-default
81 :type 'boolean
82 :group 'icomplete
83 :require 'icomplete)
84
85;;;_* User Customization variables 72;;;_* User Customization variables
86(defcustom icomplete-prospects-length 80 73(defcustom icomplete-prospects-length 80
87 "*Length of string displaying the prospects." 74 "*Length of string displaying the prospects."
@@ -131,8 +118,8 @@ icompletion is occurring."
131;;;_* Initialization 118;;;_* Initialization
132 119
133;;;_ + Internal Variables 120;;;_ + Internal Variables
134;;;_ = icomplete-eoinput 1 121;;;_ = icomplete-eoinput nil
135(defvar icomplete-eoinput 1 122(defvar icomplete-eoinput nil
136 "Point where minibuffer input ends and completion info begins.") 123 "Point where minibuffer input ends and completion info begins.")
137(make-variable-buffer-local 'icomplete-eoinput) 124(make-variable-buffer-local 'icomplete-eoinput)
138;;;_ = icomplete-pre-command-hook 125;;;_ = icomplete-pre-command-hook
@@ -173,18 +160,15 @@ is minibuffer."
173 160
174;;;_ > icomplete-mode (&optional prefix) 161;;;_ > icomplete-mode (&optional prefix)
175;;;###autoload 162;;;###autoload
176(defun icomplete-mode (&optional arg) 163(define-minor-mode icomplete-mode
177 "Toggle incremental minibuffer completion for this Emacs session. 164 "Toggle incremental minibuffer completion for this Emacs session.
178With a numeric argument, turn Icomplete mode on iff ARG is positive." 165With a numeric argument, turn Icomplete mode on iff ARG is positive."
179 (interactive "P") 166 :global t :group 'icomplete
180 (let ((on-p (if (null arg) 167 (if icomplete-mode
181 (not icomplete-mode)
182 (> (prefix-numeric-value arg) 0))))
183 (setq icomplete-mode on-p)
184 (when on-p
185 ;; The following is not really necessary after first time - 168 ;; The following is not really necessary after first time -
186 ;; no great loss. 169 ;; no great loss.
187 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)))) 170 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)
171 (remove-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)))
188 172
189;;;_ > icomplete-simple-completing-p () 173;;;_ > icomplete-simple-completing-p ()
190(defun icomplete-simple-completing-p () 174(defun icomplete-simple-completing-p ()
@@ -193,29 +177,27 @@ With a numeric argument, turn Icomplete mode on iff ARG is positive."
193Conditions are: 177Conditions are:
194 the selected window is a minibuffer, 178 the selected window is a minibuffer,
195 and not in the middle of macro execution, 179 and not in the middle of macro execution,
196 and minibuffer-completion-table is not a symbol (which would 180 and `minibuffer-completion-table' is not a symbol (which would
197 indicate some non-standard, non-simple completion mechanism, 181 indicate some non-standard, non-simple completion mechanism,
198 like file-name and other custom-func completions)." 182 like file-name and other custom-func completions)."
199 183
200 (and (window-minibuffer-p (selected-window)) 184 (and (window-minibuffer-p (selected-window))
201 (not executing-kbd-macro) 185 (not executing-kbd-macro)
202 (not (symbolp minibuffer-completion-table)))) 186 ;; (or minibuffer-completing-file-name
187 (not (functionp minibuffer-completion-table)))) ;; )
203 188
204;;;_ > icomplete-minibuffer-setup () 189;;;_ > icomplete-minibuffer-setup ()
205;;;###autoload
206(defun icomplete-minibuffer-setup () 190(defun icomplete-minibuffer-setup ()
207 "Run in minibuffer on activation to establish incremental completion. 191 "Run in minibuffer on activation to establish incremental completion.
208Usually run by inclusion in `minibuffer-setup-hook'." 192Usually run by inclusion in `minibuffer-setup-hook'."
209 (cond ((and icomplete-mode (icomplete-simple-completing-p)) 193 (when (and icomplete-mode (icomplete-simple-completing-p))
210 (add-hook 'pre-command-hook 194 (add-hook 'pre-command-hook
211 (function (lambda () 195 (lambda () (run-hooks 'icomplete-pre-command-hook))
212 (run-hooks 'icomplete-pre-command-hook))) 196 nil t)
213 nil t) 197 (add-hook 'post-command-hook
214 (add-hook 'post-command-hook 198 (lambda () (run-hooks 'icomplete-post-command-hook))
215 (function (lambda () 199 nil t)
216 (run-hooks 'icomplete-post-command-hook))) 200 (run-hooks 'icomplete-minibuffer-setup-hook)))
217 nil t)
218 (run-hooks 'icomplete-minibuffer-setup-hook))))
219; 201;
220 202
221 203
@@ -226,60 +208,47 @@ Usually run by inclusion in `minibuffer-setup-hook'."
226 "Remove completions display \(if any) prior to new user input. 208 "Remove completions display \(if any) prior to new user input.
227Should be run in on the minibuffer `pre-command-hook'. See `icomplete-mode' 209Should be run in on the minibuffer `pre-command-hook'. See `icomplete-mode'
228and `minibuffer-setup-hook'." 210and `minibuffer-setup-hook'."
229 (if (icomplete-simple-completing-p) 211 (when icomplete-eoinput
230 (if (and (boundp 'icomplete-eoinput)
231 icomplete-eoinput)
232 212
233 (if (> icomplete-eoinput (point-max)) 213 (unless (>= icomplete-eoinput (point-max))
234 ;; Oops, got rug pulled out from under us - reinit: 214 (let ((buffer-undo-list t)) ; prevent entry
235 (setq icomplete-eoinput (point-max)) 215 (delete-region icomplete-eoinput (point-max))))
236 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
237 (delete-region icomplete-eoinput (point-max))))
238 216
239 ;; Reestablish the local variable 'cause minibuffer-setup is weird: 217 ;; Reestablish the safe value.
240 (make-local-variable 'icomplete-eoinput) 218 (setq icomplete-eoinput nil)))
241 (setq icomplete-eoinput 1))))
242 219
243;;;_ > icomplete-exhibit () 220;;;_ > icomplete-exhibit ()
244(defun icomplete-exhibit () 221(defun icomplete-exhibit ()
245 "Insert icomplete completions display. 222 "Insert icomplete completions display.
246Should be run via minibuffer `post-command-hook'. See `icomplete-mode' 223Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
247and `minibuffer-setup-hook'." 224and `minibuffer-setup-hook'."
248 (if (icomplete-simple-completing-p) 225 (when (icomplete-simple-completing-p)
249 (let ((contents (buffer-substring (minibuffer-prompt-end)(point-max))) 226 (save-excursion
250 (buffer-undo-list t)) 227 (goto-char (point-max))
251 (save-excursion 228 ;; Register the end of input, so we know where the extra stuff
252 (goto-char (point-max)) 229 ;; (match-status info) begins:
253 ; Register the end of input, so we 230 (setq icomplete-eoinput (point))
254 ; know where the extra stuff
255 ; (match-status info) begins:
256 (if (not (boundp 'icomplete-eoinput))
257 ;; In case it got wiped out by major mode business:
258 (make-local-variable 'icomplete-eoinput))
259 (setq icomplete-eoinput (point))
260 ; Insert the match-status information: 231 ; Insert the match-status information:
261 (if (and (> (point-max) (minibuffer-prompt-end)) 232 (if (and (> (point-max) (minibuffer-prompt-end))
262 (or 233 buffer-undo-list ; Wait for some user input.
263 ;; Don't bother with delay after certain number of chars: 234 (or
264 (> (point-max) icomplete-max-delay-chars) 235 ;; Don't bother with delay after certain number of chars:
265 ;; Don't delay if alternatives number is small enough: 236 (> (- (point) (field-beginning)) icomplete-max-delay-chars)
266 (if minibuffer-completion-table 237 ;; Don't delay if alternatives number is small enough:
267 (cond ((numberp minibuffer-completion-table) 238 (and (sequencep minibuffer-completion-table)
268 (< minibuffer-completion-table 239 (< (length minibuffer-completion-table)
269 icomplete-delay-completions-threshold)) 240 icomplete-delay-completions-threshold))
270 ((sequencep minibuffer-completion-table) 241 ;; Delay - give some grace time for next keystroke, before
271 (< (length minibuffer-completion-table) 242 ;; embarking on computing completions:
272 icomplete-delay-completions-threshold)) 243 (sit-for icomplete-compute-delay)))
273 )) 244 (let ((text (while-no-input
274 ;; Delay - give some grace time for next keystroke, before 245 (icomplete-completions
275 ;; embarking on computing completions: 246 (field-string)
276 (sit-for icomplete-compute-delay))) 247 minibuffer-completion-table
277 (insert 248 minibuffer-completion-predicate
278 (icomplete-completions contents 249 (not minibuffer-completion-confirm))))
279 minibuffer-completion-table 250 (buffer-undo-list t))
280 minibuffer-completion-predicate 251 (if text (insert text)))))))
281 (not
282 minibuffer-completion-confirm))))))))
283 252
284;;;_ > icomplete-completions (name candidates predicate require-match) 253;;;_ > icomplete-completions (name candidates predicate require-match)
285(defun icomplete-completions (name candidates predicate require-match) 254(defun icomplete-completions (name candidates predicate require-match)
@@ -322,9 +291,7 @@ are exhibited within the square braces.)"
322 (concat open-bracket-determined 291 (concat open-bracket-determined
323 (substring most (length name)) 292 (substring most (length name))
324 close-bracket-determined))) 293 close-bracket-determined)))
325 (open-bracket-prospects "{") 294 ;;"-prospects" - more than one candidate
326 (close-bracket-prospects "}")
327 ;"-prospects" - more than one candidate
328 (prospects-len 0) 295 (prospects-len 0)
329 prospects most-is-exact comp) 296 prospects most-is-exact comp)
330 (if (eq most-try t) 297 (if (eq most-try t)
@@ -338,30 +305,25 @@ are exhibited within the square braces.)"
338 prospects-len (+ (length comp) 1 prospects-len)))))) 305 prospects-len (+ (length comp) 1 prospects-len))))))
339 (if prospects 306 (if prospects
340 (concat determ 307 (concat determ
341 open-bracket-prospects 308 "{"
342 (and most-is-exact ",") 309 (and most-is-exact ",")
343 (mapconcat 'identity 310 (mapconcat 'identity
344 (sort prospects (function string-lessp)) 311 (sort prospects (function string-lessp))
345 ",") 312 ",")
346 (and comps ",...") 313 (and comps ",...")
347 close-bracket-prospects) 314 "}")
348 (concat determ 315 (concat determ
349 " [Matched" 316 " [Matched"
350 (let ((keys (and icomplete-show-key-bindings 317 (let ((keys (and icomplete-show-key-bindings
351 (commandp (intern-soft most)) 318 (commandp (intern-soft most))
352 (icomplete-get-keys most)))) 319 (icomplete-get-keys most))))
353 (if keys 320 (if keys (concat "; " keys) ""))
354 (concat "; " keys)
355 ""))
356 "]")))))) 321 "]"))))))
357 322
358(if icomplete-mode
359 (icomplete-mode 1))
360
361;;;_* Local emacs vars. 323;;;_* Local emacs vars.
362;;;Local variables: 324;;;Local variables:
363;;;outline-layout: (-2 :) 325;;;outline-layout: (-2 :)
364;;;End: 326;;;End:
365 327
366;;; arch-tag: 339ec25a-0741-4eb6-be63-997532e89b0f 328;; arch-tag: 339ec25a-0741-4eb6-be63-997532e89b0f
367;;; icomplete.el ends here 329;;; icomplete.el ends here