aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKarl Heuer1997-05-29 18:18:23 +0000
committerKarl Heuer1997-05-29 18:18:23 +0000
commit92f7d0036fe5eeb041a9cadc9560dc1645a3fb4f (patch)
tree652a3eb320f496557f22904d43e1a414792f583f /lisp
parentc8d05b030b6952ef458ec7bb2438059d9ac5ddf0 (diff)
downloademacs-92f7d0036fe5eeb041a9cadc9560dc1645a3fb4f.tar.gz
emacs-92f7d0036fe5eeb041a9cadc9560dc1645a3fb4f.zip
Integrated Emacs 19.34 and XEmacs 19.15
corrections (typos, style, command revisions, etc). Integrated hacked up XEmacs immediate keybindings display. See `icomplete-show-key-bindings', `icomplete-get-keys', and `icomplete-completions'. Doesn't work with mainline GNU Emacs 19.34 (because the cmdloop doesn't set owindow, and the current-local-map doesn't take optional buffer arg), so feature is, by default, inhibited unless we're running in XEmacs. (icomplete-get-keys): Return keys bound to func name in buffer "owindow" - since "owindow" is calling-buffer history present only in XEmacs, this function is only useful in XEmacs. (icomplete-max-delay-chars, icomplete-compute-delay): New vars. (icomplete-delay-completions-threshold): New var. These customize the delay behavior, so that completions don't intrude as quickly for short input.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/icomplete.el181
1 files changed, 133 insertions, 48 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 025af152a9d..f90100fd4d7 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -1,9 +1,9 @@
1;;; icomplete.el --- minibuffer completion incremental feedback 1;;;_. icomplete.el - minibuffer completion incremental feedback
2 2
3;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. 3;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 4
5;; Author: Ken Manheimer <klm@nist.gov> 5;; Author: Ken Manheimer <klm@python.org>
6;; Maintainer: Ken Manheimer <klm@nist.gov> 6;; Maintainer: Ken Manheimer <klm@python.org>
7;; Created: Mar 1993 klm@nist.gov - first release to usenet 7;; Created: Mar 1993 klm@nist.gov - first release to usenet
8;; Keywords: help, abbrev 8;; Keywords: help, abbrev
9 9
@@ -24,6 +24,10 @@
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA. 25;; Boston, MA 02111-1307, USA.
26 26
27;; This file is also part of XEmacs.
28;; Hacked for XEmacs: David Hughes 7th September 1995
29;; With some integration and refinement by Ken Manheimer, May 1997
30
27;;; Commentary: 31;;; Commentary:
28 32
29;; Loading this package implements a more fine-grained minibuffer 33;; Loading this package implements a more fine-grained minibuffer
@@ -46,6 +50,11 @@
46;; can be enabled any time after the package is loaded by invoking 50;; can be enabled any time after the package is loaded by invoking
47;; icomplete-mode without a prefix arg. 51;; icomplete-mode without a prefix arg.
48 52
53;; This version of icomplete runs on Emacs 19.18 and later. (It
54;; depends on the incorporation of minibuffer-setup-hook.) The elisp
55;; archives, ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive,
56;; probably still has a version that works in GNU Emacs v18.
57
49;; Thanks to everyone for their suggestions for refinements of this 58;; Thanks to everyone for their suggestions for refinements of this
50;; package. I particularly have to credit Michael Cook, who 59;; package. I particularly have to credit Michael Cook, who
51;; implemented an incremental completion style in his 'iswitch' 60;; implemented an incremental completion style in his 'iswitch'
@@ -62,6 +71,13 @@
62(provide 'icomplete) 71(provide 'icomplete)
63 72
64;;;_* User Customization variables 73;;;_* User Customization variables
74(defvar icomplete-compute-delay .3
75 "*Completions-computation stall, used only with large-number
76completions - see `icomplete-delay-completions-threshold'.")
77(defvar icomplete-delay-completions-threshold 400
78 "*Pending-completions number over which to apply icomplete-compute-delay.")
79(defvar icomplete-max-delay-chars 3
80 "*Maximum number of initial chars to apply icomplete compute delay.")
65 81
66;;;_* Initialization 82;;;_* Initialization
67;;;_ = icomplete-minibuffer-setup-hook 83;;;_ = icomplete-minibuffer-setup-hook
@@ -72,7 +88,7 @@ This hook is run during minibuffer setup iff icomplete will be active.
72It is intended for use in customizing icomplete for interoperation 88It is intended for use in customizing icomplete for interoperation
73with other packages. For instance: 89with other packages. For instance:
74 90
75 \(add-hook 'icomplete-minibuffer-setup-hook 91 \(add-hook 'icomplete-minibuffer-setup-hook
76 \(function 92 \(function
77 \(lambda () 93 \(lambda ()
78 \(make-local-variable 'resize-minibuffer-window-max-height) 94 \(make-local-variable 'resize-minibuffer-window-max-height)
@@ -107,6 +123,30 @@ Use `icomplete-mode' function to set it up properly for incremental
107minibuffer completion.") 123minibuffer completion.")
108(add-hook 'icomplete-post-command-hook 'icomplete-exhibit) 124(add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
109 125
126(defvar icomplete-show-key-bindings (string-match "XEmacs\\|Lucid"
127 emacs-version)
128 "When non-nil show key bindings as well as completion when matching
129a command. Currently working only for XEmacs - see `icomplete-get-keys'.")
130
131(defun icomplete-get-keys (func-name)
132 "Return the keys `func-name' is bound to as a string, or nil if none.
133 NOTE that this depends on `owindow' minbuf setting and `current-local-map'
134 taking arg, both present in XEmacs but not present in mainline GNU Emacs
135 19.34."
136 (when (commandp func-name)
137 (save-excursion
138 (let* ((sym (intern func-name))
139 (buf (set-buffer (window-buffer owindow)))
140 (keys (where-is-internal sym (current-local-map buf))))
141 (if keys
142 (concat "<"
143 (mapconcat 'key-description
144 (sort keys
145 #'(lambda (x y)
146 (< (length x) (length y))))
147 ", ")
148 ">"))))))
149
110;;;_ > icomplete-mode (&optional prefix) 150;;;_ > icomplete-mode (&optional prefix)
111;;;###autoload 151;;;###autoload
112(defun icomplete-mode (&optional prefix) 152(defun icomplete-mode (&optional prefix)
@@ -179,6 +219,7 @@ and `minibuffer-setup-hook'."
179;;;_ > icomplete-exhibit () 219;;;_ > icomplete-exhibit ()
180(defun icomplete-exhibit () 220(defun icomplete-exhibit ()
181 "Insert icomplete completions display. 221 "Insert icomplete completions display.
222
182Should be run via minibuffer `post-command-hook'. See `icomplete-mode' 223Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
183and `minibuffer-setup-hook'." 224and `minibuffer-setup-hook'."
184 (if (icomplete-simple-completing-p) 225 (if (icomplete-simple-completing-p)
@@ -194,7 +235,22 @@ and `minibuffer-setup-hook'."
194 (make-local-variable 'icomplete-eoinput)) 235 (make-local-variable 'icomplete-eoinput))
195 (setq icomplete-eoinput (point)) 236 (setq icomplete-eoinput (point))
196 ; Insert the match-status information: 237 ; Insert the match-status information:
197 (if (> (point-max) 1) 238 (if (and (> (point-max) 1)
239 (or
240 ;; Don't bother with delay after certain number of chars:
241 (> (point-max) icomplete-max-delay-chars)
242 ;; Don't delay if alternatives number is small enough:
243 (if minibuffer-completion-table
244 (cond ((numberp minibuffer-completion-table)
245 (< minibuffer-completion-table
246 icomplete-delay-completions-threshold))
247 ((sequencep minibuffer-completion-table)
248 (< (length minibuffer-completion-table)
249 icomplete-delay-completions-threshold))
250 ))
251 ;; Delay - give some grace time for next keystroke, before
252 ;; embarking on computing completions:
253 (sit-for icomplete-compute-delay)))
198 (insert-string 254 (insert-string
199 (icomplete-completions contents 255 (icomplete-completions contents
200 minibuffer-completion-table 256 minibuffer-completion-table
@@ -219,7 +275,13 @@ one of \(), \[], or \{} pairs. The choice of brackets is as follows:
219 275
220The displays for unambiguous matches have ` [Matched]' appended 276The displays for unambiguous matches have ` [Matched]' appended
221\(whether complete or not), or ` \[No matches]', if no eligible 277\(whether complete or not), or ` \[No matches]', if no eligible
222matches exist." 278matches exist. \(In XEmacs, keybindings for matched commands, if any,
279are exhibited within the square braces.)"
280
281 ;; 'all-completions' doesn't like empty
282 ;; minibuffer-completion-table's (ie: (nil))
283 (if (and (listp candidates) (null (car candidates)))
284 (setq candidates nil))
223 285
224 (let ((comps (all-completions name candidates predicate)) 286 (let ((comps (all-completions name candidates predicate))
225 ; "-determined" - only one candidate 287 ; "-determined" - only one candidate
@@ -229,47 +291,71 @@ matches exist."
229 (open-bracket-prospects "{") 291 (open-bracket-prospects "{")
230 (close-bracket-prospects "}") 292 (close-bracket-prospects "}")
231 ) 293 )
232 (cond ((null comps) (format " %sNo matches%s" 294 (catch 'input
233 open-bracket-determined 295 (cond ((null comps) (format " %sNo matches%s"
234 close-bracket-determined)) 296 open-bracket-determined
235 ((null (cdr comps)) ;one match 297 close-bracket-determined))
236 (concat (if (and (> (length (car comps)) 298 ((null (cdr comps)) ;one match
237 (length name))) 299 (concat (if (and (> (length (car comps))
238 (concat open-bracket-determined 300 (length name)))
239 (substring (car comps) (length name)) 301 (concat open-bracket-determined
240 close-bracket-determined) 302 (substring (car comps) (length name))
241 "") 303 close-bracket-determined)
242 " [Matched]")) 304 "")
243 (t ;multiple matches 305 " [Matched"
244 (let* ((most (try-completion name candidates predicate)) 306 (let ((keys (and icomplete-show-key-bindings
245 (most-len (length most)) 307 (commandp (intern-soft (car comps)))
246 most-is-exact 308 (icomplete-get-keys (car comps)))))
247 (alternatives 309 (if keys
248 (apply 310 (concat "; " keys)
249 (function concat) 311 ""))
250 (cdr (apply 312 "]"))
251 (function nconc) 313 (t ;multiple matches
252 (mapcar '(lambda (com) 314 (let* ((most
253 (if (= (length com) most-len) 315 (try-completion name candidates
254 ;; Most is one exact match, 316 (and predicate
255 ;; note that and leave out 317 ;; Wrap predicate in impatience - ie,
256 ;; for later indication: 318 ;; `throw' up when pending input is
257 (progn 319 ;; noticed. Adds some overhead to
258 (setq most-is-exact t) 320 ;; predicate, but should be worth it.
259 ()) 321 (function
260 (list "," 322 (lambda (item)
261 (substring com 323 (if (input-pending-p)
262 most-len)))) 324 (throw 'input "")
263 comps)))))) 325 (apply predicate
264 (concat (and (> most-len (length name)) 326 item nil)))))))
265 (concat open-bracket-determined 327 (most-len (length most))
266 (substring most (length name)) 328 most-is-exact
267 close-bracket-determined)) 329 (alternatives
268 open-bracket-prospects 330 (substring
269 (if most-is-exact 331 (apply (function concat)
270 (concat "," alternatives) 332 (mapcar (function
271 alternatives) 333 (lambda (com)
272 close-bracket-prospects)))))) 334 (if (input-pending-p)
335 (throw 'input ""))
336 (if (= (length com) most-len)
337 ;; Most is one exact match,
338 ;; note that and leave out
339 ;; for later indication:
340 (progn
341 (setq most-is-exact t)
342 ())
343 (concat ","
344 (substring com
345 most-len)))))
346 comps))
347 1)))
348 (concat (and (> most-len (length name))
349 (concat open-bracket-determined
350 (substring most (length name))
351 close-bracket-determined))
352 open-bracket-prospects
353 (if most-is-exact
354 ;; Add a ',' at the front to indicate "complete but
355 ;; not unique":
356 (concat "," alternatives)
357 alternatives)
358 close-bracket-prospects)))))))
273 359
274;;;_ + Initialization 360;;;_ + Initialization
275;;; If user hasn't setq-default icomplete-mode to nil, then setup for 361;;; If user hasn't setq-default icomplete-mode to nil, then setup for
@@ -284,4 +370,3 @@ matches exist."
284;;;End: 370;;;End:
285 371
286;;; icomplete.el ends here 372;;; icomplete.el ends here
287