aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-09-18 08:27:12 +0000
committerRichard M. Stallman1994-09-18 08:27:12 +0000
commit239c87a1997ad89162e74d1fb99690c153b9188f (patch)
tree0af5285ed5e644476c62669b60da7a62ee14112a
parentc0b2f23c46abe01cc32ee1f7cd120d9f00790050 (diff)
downloademacs-239c87a1997ad89162e74d1fb99690c153b9188f.tar.gz
emacs-239c87a1997ad89162e74d1fb99690c153b9188f.zip
Major rewrite to behave more like a minor mode.
Doc fixes. (icomplete-mode): New function and var. (icomplete-minibuffer-setup-hook): New hook. (icomplete-inhibit): Defunct. Using icomplete-pre-command-hook, icomplete-post-command-hook as real hook functions. (icomplete-simple-completing-p): Subsumes icomplete-window-minibuffer-p plus other stuff, determines whether simple completion is active. (icomplete-window-minibuffer-p): Defunct, see above. (icomplete-minibuffer-setup): Use icomplete-simple-completing-p, copy-sequence hooks before adding to them, run hooks properly. (icomplete-tidy): Changed from misnamed icomplete-pre-command-hook; use icomplete-simple-completing-p. (icomplete-exhibit): Changed from misnamed icomplete-post-command-hook; use icomplete-simple-completing-p. (icomplete-completions): Changed from old, misnamed icomplete-exhibit; combined with old misnamed icomplete-prompt.
-rw-r--r--lisp/icomplete.el355
1 files changed, 193 insertions, 162 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 7defbb76a6d..a7b1872001f 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -1,155 +1,195 @@
1;;; icomplete.el - minibuffer completion incremental feedback 1;;;_. icomplete.el - minibuffer completion incremental feedback
2;;; This package is in the public domain. 2
3;;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
3 4
4;;; Author: Ken Manheimer <klm@nist.gov> 5;;; Author: Ken Manheimer <klm@nist.gov>
5;;; Maintainer: Ken Manheimer <klm@nist.gov> 6;;; Maintainer: Ken Manheimer <klm@nist.gov>
6;;; Version: icomplete.el,v 3.3 1993/12/11 11:27:35 klm Exp klm 7;;; Version: Id: icomplete.el,v 4.3 1994/08/31 18:48:29 klm Exp
7;;; Created: Mar 1993 klm@nist.gov - first release to usenet 8;;; Created: Mar 1993 klm@nist.gov - first release to usenet
8;;; Keywords: help, abbrev 9;;; Keywords: help, abbrev
9 10
10;;; Commentary: 11;; This file is part of GNU Emacs.
11 12
12;;; Loading this package implements a more finely-grained completion 13;; GNU Emacs is free software; you can redistribute it and/or modify
13;;; feedback scheme, indicating, within the minibuffer, the 14;; it under the terms of the GNU General Public License as published by
14;;; prospective minibuffer completion candidates, as you type. See 15;; the Free Software Foundation; either version 2, or (at your option)
15;;; the documentation string for 'icomplete-prompt' for a specific 16;; any later version.
16;;; description of icompletion.
17 17
18;;; It should run on most version of Emacs 19 (including Lucid emacs 18;; GNU Emacs is distributed in the hope that it will be useful,
19;;; 19 - thanks to the efforts of Colin Rafferty (craffert@lehman.com) 19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; - thanks, Colin!) This version of icomplete will *not* work on 20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; Emacs 18 versions - the elisp archives, at 21;; GNU General Public License for more details.
22;;; archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive, probably
23;;; still has a version that works in GNU Emacs v18.
24 22
25;;; Thanks to Colin Rafferty for assistance reconciling for lemacs, 23;; You should have received a copy of the GNU General Public License
26;;; and to Michael Cook, who implemented an incremental completion 24;; along with GNU Emacs; see the file COPYING. If not, write to
27;;; style in his 'iswitch' functions that served as the basis for 25;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28;;; icomplete.
29 26
30;;; Code: 27;;; Commentary:
31 28
32;;;_* (Allout outline root topic. Please leave this in.) 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
32;;; keystroke.
33
34;;; See 'icomplete-completions' docstring for a description of the
35;;; icomplete display format.
36
37;;; See the `icomplete-minibuffer-setup-hook' docstring for a means to
38;;; customize icomplete setup for interoperation with other
39;;; minibuffer-oriented packages.
40
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.
48
49;;; This version of icomplete runs on Emacs 19.18 and later. (It
50;;; depends on the incorporation of minibuffer-setup-hook.) The elisp
51;;; archives, ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive,
52;;; probably still has a version that works in GNU Emacs v18.
53
54;;; Thanks to everyone for their suggestions for refinements of this
55;;; package. I particularly have to credit Michael Cook, who
56;;; implemented an incremental completion style in his 'iswitch'
57;;; functions that served as a model for icomplete. Some other
58;;; contributors: Noah Freidman (restructuring as minor mode), Colin
59;;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and
60;;; others.
61
62;;; klm.
33 63
34;;;_ + Provide 64;;; Code:
65
66;;;_* Provide
35(provide 'icomplete) 67(provide 'icomplete)
36 68
37;;;_ + User Customization variables 69;;;_* User Customization variables
38;;;_ = icomplete-inhibit 70
39(defvar icomplete-inhibit nil 71;;;_* Initialization
40 "*Set this variable to t at any time to inhibit icomplete.") 72;;;_ = icomplete-minibuffer-setup-hook
73(defvar icomplete-minibuffer-setup-hook nil
74 "*Icomplete-specific customization of minibuffer setup.
75
76This hook is run during minibuffer setup iff icomplete will be active.
77It is intended for use in customizing icomplete for interoperation
78with other packages. For instance:
79
80 \(add-hook 'icomplete-minibuffer-setup-hook
81 \(function
82 \(lambda ()
83 \(make-local-variable 'resize-minibuffer-window-max-height)
84 \(setq resize-minibuffer-window-max-height 3))))
85
86will constrain rsz-mini to a maximum minibuffer height of 3 lines when
87icompletion is occurring.")
41 88
42;;;_ + Internal Variables 89;;;_ + Internal Variables
90;;;_ = icomplete-mode
91(defvar icomplete-mode t
92 "Non-nil enables incremental minibuffer completion, once
93`\\[icomplete-mode]' function has set things up.")
43;;;_ = icomplete-eoinput 1 94;;;_ = icomplete-eoinput 1
44(defvar icomplete-eoinput 1 95(defvar icomplete-eoinput 1
45 "Point where minibuffer input ends and completion info begins.") 96 "Point where minibuffer input ends and completion info begins.")
46(make-variable-buffer-local 'icomplete-eoinput) 97(make-variable-buffer-local 'icomplete-eoinput)
47 98;;;_ = icomplete-pre-command-hook
48;;;_ > icomplete-prime-session () 99(defvar icomplete-pre-command-hook nil
100 "Incremental-minibuffer-completion pre-command-hook.
101
102Is run in minibuffer before user input when `icomplete-mode' is non-nil.
103Use `icomplete-mode' function to set it up properly for incremental
104minibuffer completion.")
105(add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
106;;;_ = icomplete-post-command-hook
107(defvar icomplete-post-command-hook nil
108 "Incremental-minibuffer-completion post-command-hook.
109
110Is run in minibuffer after user input when `icomplete-mode' is non-nil.
111Use `icomplete-mode' function to set it up properly for incremental
112minibuffer completion.")
113(add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
114
115;;;_ > icomplete-mode (&optional prefix)
49;;;###autoload 116;;;###autoload
50(defun icomplete-prime-session () 117(defun icomplete-mode (&optional prefix)
51 118 "Activate incremental minibuffer completion for this emacs session,
52 "Prep emacs v 19 for more finely-grained minibuffer completion-feedback. 119or deactivate with negative prefix arg."
53 120 (interactive "p")
54You can inhibit icomplete after loading by setting icomplete-inhibit 121 (or prefix (setq prefix 0))
55non-nil. Set the var back to nil to re-enable icomplete." 122 (cond ((>= prefix 0)
56 123 (setq icomplete-mode t)
57 ;; For emacs v19.18 and later revs, the icomplete key function is 124 ;; The following is not really necessary after first time -
58 ;; installed in 'minibuffer-setup-hook'. Global pre- and post- 125 ;; no great loss.
59 ;; command-hook functions are used in v19.17 and earlier v19 revs." 126 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup))
60 127 (t (setq icomplete-mode nil))))
61 (let* ((v19-rev (and (string-match "^19\\.\\([0-9]+\\)" emacs-version) 128
62 (string-to-int (substring emacs-version 129;;;_ > icomplete-simple-completing-p ()
63 (match-beginning 1) 130(defun icomplete-simple-completing-p ()
64 (match-end 1)))))) 131
65 132 "Non-nil if current window is minibuffer that's doing simple completion.
66 (cond ((and v19-rev ; emacs v 19, some rev, 133
67 (> v19-rev 17)) 134Conditions are:
68 ;; Post v19rev17, has minibuffer-setup-hook, use it: 135 the selected window is a minibuffer,
69 (add-hook 'minibuffer-setup-hook 'icomplete-prime-minibuffer)) 136 and not in the middle of macro execution,
70 (v19-rev 137 and minibuffer-completion-table is not a symbol (which would
71 ;; v19rev17 and prior (including lucid): use global 138 indicate some non-standard, non-simple completion mechansm,
72 ;; pre- and post-command-hooks, instead: 139 like file-name and other custom-func completions)."
73 (add-hook 'pre-command-hook 'icomplete-pre-command-hook 'append) 140
74 (add-hook 'post-command-hook 141 (and (window-minibuffer-p (selected-window))
75 'icomplete-post-command-hook 'append)) 142 (not executing-macro)
76 ((format "icomplete: non v19 emacs, %s - %s" 143 (not (symbolp minibuffer-completion-table))))
77 emacs-version "try elisp-archive icomplete"))))) 144;;;_ > icomplete-minibuffer-setup ()
78 145;;;###autoload
79;;;_ > icomplete-prime-minibuffer () 146(defun icomplete-minibuffer-setup ()
80(defun icomplete-prime-minibuffer () 147
81 "Prep emacs, v 19.18 or later, for icomplete. 148 "Run in minibuffer on activation to establish incremental completion.
82\(In emacs v19.17 and earlier, and in lemacs, icomplete-prime-session 149
83is used, instead to establish global hooks.\) 150Usually run by inclusion in minibuffer-setup-hook."
84 151
85Run via `minibuffer-setup-hook', adds icomplete pre- and post-command 152 (cond ((and icomplete-mode (icomplete-simple-completing-p))
86hooks at the start of each minibuffer." 153 (make-local-variable 'pre-command-hook)
87 154 (setq pre-command-hook (copy-sequence pre-command-hook))
88 ;; Append the hooks to avoid as much as posssible interference from 155 (add-hook 'pre-command-hook
89 ;; other hooks that foul up minibuffer quit. 156 (function (lambda ()
90 (make-local-variable 'pre-command-hook) 157 (run-hooks 'icomplete-pre-command-hook))))
91 (make-local-variable 'post-command-hook) 158 (make-local-variable 'post-command-hook)
92 (setq pre-command-hook (copy-sequence pre-command-hook)) 159 (setq post-command-hook (copy-sequence post-command-hook))
93 (setq post-command-hook (copy-sequence post-command-hook)) 160 (add-hook 'post-command-hook
94 (add-hook 'pre-command-hook 'icomplete-pre-command-hook) 161 (function (lambda ()
95 (add-hook 'post-command-hook 'icomplete-post-command-hook)) 162 (run-hooks 'icomplete-post-command-hook))))
96 163 (run-hooks 'icomplete-minibuffer-setup-hook))))
97;;;_ > icomplete-window-minibuffer-p () 164
98(defmacro icomplete-window-minibuffer-p () 165;;;_* Completion
99 166
100 "Returns non-nil if current window is a minibuffer window. 167;;;_ > icomplete-tidy ()
101 168(defun icomplete-tidy ()
102Trivially equates to '(window-minibuffer-p (selected-window))', with 169 "Remove completions display \(if any) prior to new user input.
103the argument definitely provided for emacsen that require it, eg Lucid." 170
104 171Should be run in on the minibuffer pre-command-hook. See `icomplete-mode'
105 '(window-minibuffer-p (selected-window))) 172and `minibuffer-setup-hook'."
106 173 (if (icomplete-simple-completing-p)
107;;;_ + Completion
108
109;;;_ - Completion feedback hooks
110;;;_ > icomplete-pre-command-hook ()
111(defun icomplete-pre-command-hook ()
112 "Cleanup completions display before user's new command is dealt with."
113 (if (and (icomplete-window-minibuffer-p)
114 (not executing-macro)
115 (not (symbolp minibuffer-completion-table))
116 (not icomplete-inhibit))
117 (if (and (boundp 'icomplete-eoinput) 174 (if (and (boundp 'icomplete-eoinput)
118 icomplete-eoinput) 175 icomplete-eoinput)
176
119 (if (> icomplete-eoinput (point-max)) 177 (if (> icomplete-eoinput (point-max))
120 ;; Oops, got rug pulled out from under us - reinit: 178 ;; Oops, got rug pulled out from under us - reinit:
121 (setq icomplete-eoinput (point-max)) 179 (setq icomplete-eoinput (point-max))
122 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry 180 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
123 (delete-region icomplete-eoinput (point-max)))) 181 (delete-region icomplete-eoinput (point-max))))
182
124 ;; Reestablish the local variable 'cause minibuffer-setup is weird: 183 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
125 (make-local-variable 'icomplete-eoinput) 184 (make-local-variable 'icomplete-eoinput)
126 (setq icomplete-eoinput 1)))) 185 (setq icomplete-eoinput 1))))
127;;;_ > icomplete-post-command-hook () 186;;;_ > icomplete-exhibit ()
128(defun icomplete-post-command-hook ()
129 "Exhibit completions, leaving bookkeeping so pre- hook can tidy up."
130
131 (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
132 (not executing-macro)
133 (not icomplete-inhibit) ; ... not specifically inhibited.
134 ;(sit-for 0) ; ... redisplay and if there's input
135 ; waiting, then don't icomplete
136 ; (stigs suggestion) (too jumpy!)
137 ;; Inhibit for file-name and other custom-func completions:
138 (not (symbolp minibuffer-completion-table))
139 )
140 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
141 (icomplete-exhibit))))
142;;;_ > icomplete-window-setup-hook ()
143(defun icomplete-window-setup-hook ()
144 "Exhibit completions, leaving bookkeeping so pre- hook can tidy up."
145
146 (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
147 )
148 (message "ic ws doing")(sit-for 1)))
149;;;_ > icomplete-exhibit ()
150(defun icomplete-exhibit () 187(defun icomplete-exhibit ()
151 "Insert icomplete completions display." 188 "Insert icomplete completions display.
152 (if (not (symbolp minibuffer-completion-table)) 189
190Should be run via minibuffer post-command-hook. See `icomplete-mode'
191and `minibuffer-setup-hook'."
192 (if (icomplete-simple-completing-p)
153 (let ((contents (buffer-substring (point-min)(point-max))) 193 (let ((contents (buffer-substring (point-min)(point-max)))
154 (buffer-undo-list t)) 194 (buffer-undo-list t))
155 (save-excursion 195 (save-excursion
@@ -164,15 +204,13 @@ the argument definitely provided for emacsen that require it, eg Lucid."
164 ; Insert the match-status information: 204 ; Insert the match-status information:
165 (if (> (point-max) 1) 205 (if (> (point-max) 1)
166 (insert-string 206 (insert-string
167 (icomplete-prompt contents 207 (icomplete-completions contents
168 minibuffer-completion-table 208 minibuffer-completion-table
169 minibuffer-completion-predicate 209 minibuffer-completion-predicate
170 (not 210 (not
171 minibuffer-completion-confirm)))))))) 211 minibuffer-completion-confirm))))))))
172 212;;;_ > icomplete-completions (name candidates predicate require-match)
173;;;_ - Completion feedback producer 213(defun icomplete-completions (name candidates predicate require-match)
174;;;_ > icomplete-prompt (name candidates predicate require-match)
175(defun icomplete-prompt (name candidates predicate require-match)
176 "Identify prospective candidates for minibuffer completion. 214 "Identify prospective candidates for minibuffer completion.
177 215
178The display is updated with each minibuffer keystroke during 216The display is updated with each minibuffer keystroke during
@@ -215,20 +253,21 @@ matches exist."
215 most-is-exact 253 most-is-exact
216 (alternatives 254 (alternatives
217 (apply 255 (apply
218 'concat 256 (function concat)
219 (cdr (apply 'append 257 (cdr (apply
220 (mapcar '(lambda (com) 258 (function nconc)
221 (if (= (length com) most-len) 259 (mapcar '(lambda (com)
222 ;; Most is one exact match, 260 (if (= (length com) most-len)
223 ;; note that and leave out 261 ;; Most is one exact match,
224 ;; for later indication: 262 ;; note that and leave out
225 (progn 263 ;; for later indication:
226 (setq most-is-exact t) 264 (progn
227 ()) 265 (setq most-is-exact t)
228 (list "," 266 ())
229 (substring com 267 (list ","
230 most-len)))) 268 (substring com
231 comps)))))) 269 most-len))))
270 comps))))))
232 (concat (and (> most-len (length name)) 271 (concat (and (> most-len (length name))
233 (concat open-bracket-determined 272 (concat open-bracket-determined
234 (substring most (length name)) 273 (substring most (length name))
@@ -239,25 +278,17 @@ matches exist."
239 alternatives) 278 alternatives)
240 close-bracket-prospects)))))) 279 close-bracket-prospects))))))
241 280
242;;;_ - Initialization 281;;;_ + Initialization
243(icomplete-prime-session) 282;;; If user hasn't setq-default icomplete-mode to nil, then setup for
244 283;;; activation:
245 284(if icomplete-mode
246;;;_ + Local emacs vars. 285 (icomplete-mode))
247'( 286
248Local variables: 287
249eval: (save-excursion 288;;;_* Local emacs vars.
250 (if (not (condition-case err (outline-mode t) 289;;;Local variables:
251 (wrong-number-of-arguments nil))) 290;;;outline-layout: (-2 :)
252 (progn 291;;;End:
253 (message
254 "Allout outline-mode not loaded, not adjusting buffer exposure")
255 (sit-for 1))
256 (message "Adjusting '%s' visibility" (buffer-name))
257 (outline-lead-with-comment-string ";;;_")
258 (goto-char 0)
259 (outline-exposure -1 0)))
260End:)
261 292
262;;; icomplete.el ends here 293;;; icomplete.el ends here
263 294