Mercurial > hg > xemacs-beta
comparison lisp/packages/icomplete.el @ 155:43dd3413c7c7 r20-3b4
Import from CVS: tag r20-3b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:39:39 +0200 |
parents | 25f70ba0133c |
children | 489f57a838ef |
comparison
equal
deleted
inserted
replaced
154:94141801dd7e | 155:43dd3413c7c7 |
---|---|
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@python.org> | 5 ;; Author: Ken Manheimer <klm@python.org> |
6 ;; Maintainer: Ken Manheimer <klm@python.org> | 6 ;; Maintainer: Ken Manheimer <klm@python.org> |
7 ;; Version: $Id: icomplete.el,v 1.3 1997/05/29 23:50:06 steve Exp $ | 7 ;; Version: $Id: icomplete.el,v 1.4 1997/06/06 00:57:26 steve Exp $ |
8 ;; Created: Mar 1993 klm@nist.gov - first release to usenet | 8 ;; Created: Mar 1993 klm@nist.gov - first release to usenet |
9 ;; Keywords: help, abbrev | 9 ;; Keywords: help, abbrev |
10 | 10 |
11 ;; This file is part of GNU Emacs. | 11 ;; This file is part of GNU Emacs. |
12 | 12 |
23 ;; You should have received a copy of the GNU General Public License | 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 the | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
26 ;; Boston, MA 02111-1307, USA. | 26 ;; Boston, MA 02111-1307, USA. |
27 | 27 |
28 ;; This file is also part of XEmacs. | 28 ;; This file is also part of GNU XEmacs. |
29 ;; Hacked for XEmacs: David Hughes 7th September 1995 | 29 ;; Hacked for GNU XEmacs: David Hughes 7th September 1995. |
30 ;; With some integration and refinement by Ken Manheimer, May 1997 | 30 ;; Icomplete keybindings display originally by Steve Bauer, with |
31 ;; some integration and refinement by Ken Manheimer. | |
31 | 32 |
32 ;;; Commentary: | 33 ;;; Commentary: |
33 | 34 |
34 ;; Loading this package implements a more fine-grained minibuffer | 35 ;; Loading this package implements a more fine-grained minibuffer |
35 ;; completion feedback scheme. Prospective completions are concisely | 36 ;; completion feedback scheme. Prospective completions are concisely |
49 ;; you can prevent activation of the mode during package load by | 50 ;; you can prevent activation of the mode during package load by |
50 ;; first setting the variable `icomplete-mode' to nil. Icompletion | 51 ;; first setting the variable `icomplete-mode' to nil. Icompletion |
51 ;; can be enabled any time after the package is loaded by invoking | 52 ;; can be enabled any time after the package is loaded by invoking |
52 ;; icomplete-mode without a prefix arg. | 53 ;; icomplete-mode without a prefix arg. |
53 | 54 |
54 ;; This version of icomplete runs on Emacs 19.18 and later. (It | |
55 ;; depends on the incorporation of minibuffer-setup-hook.) The elisp | |
56 ;; archives, ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive, | |
57 ;; probably still has a version that works in GNU Emacs v18. | |
58 | |
59 ;; Thanks to everyone for their suggestions for refinements of this | 55 ;; Thanks to everyone for their suggestions for refinements of this |
60 ;; package. I particularly have to credit Michael Cook, who | 56 ;; package. I particularly have to credit Michael Cook, who |
61 ;; implemented an incremental completion style in his 'iswitch' | 57 ;; implemented an incremental completion style in his 'iswitch' |
62 ;; functions that served as a model for icomplete. Some other | 58 ;; functions that served as a model for icomplete. Some other |
63 ;; contributors: Noah Freidman (restructuring as minor mode), Colin | 59 ;; contributors: Noah Freidman (restructuring as minor mode), Colin |
64 ;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and | 60 ;; Rafferty (lemacs reconciliation), Lars Lindberg, RMS, and others. |
65 ;; others. | |
66 | 61 |
67 ;; klm. | 62 ;; klm. |
68 | 63 |
69 ;;; Code: | 64 ;;; Code: |
70 | 65 |
96 \(setq resize-minibuffer-window-max-height 3)))) | 91 \(setq resize-minibuffer-window-max-height 3)))) |
97 | 92 |
98 will constrain rsz-mini to a maximum minibuffer height of 3 lines when | 93 will constrain rsz-mini to a maximum minibuffer height of 3 lines when |
99 icompletion is occurring.") | 94 icompletion is occurring.") |
100 | 95 |
101 (if (string-match "XEmacs\\|Lucid" emacs-version) | |
102 (add-hook 'icomplete-minibuffer-setup-hook 'icomplete-exhibit)) | |
103 | |
104 ;;;_ + Internal Variables | 96 ;;;_ + Internal Variables |
105 ;;;_ = icomplete-mode | 97 ;;;_ = icomplete-mode |
106 (defvar icomplete-mode t | 98 (defvar icomplete-mode t |
107 "Non-nil enables incremental minibuffer completion, once | 99 "*Nil inhibits activated incremental minibuffer completion.") |
108 `\\[icomplete-mode]' function has set things up.") | |
109 ;;;_ = icomplete-eoinput 1 | 100 ;;;_ = icomplete-eoinput 1 |
110 (defvar icomplete-eoinput 1 | 101 (defvar icomplete-eoinput 1 |
111 "Point where minibuffer input ends and completion info begins.") | 102 "Point where minibuffer input ends and completion info begins.") |
112 (make-variable-buffer-local 'icomplete-eoinput) | 103 (make-variable-buffer-local 'icomplete-eoinput) |
113 ;;;_ = icomplete-pre-command-hook | 104 ;;;_ = icomplete-pre-command-hook |
125 Is run in minibuffer after user input when `icomplete-mode' is non-nil. | 116 Is run in minibuffer after user input when `icomplete-mode' is non-nil. |
126 Use `icomplete-mode' function to set it up properly for incremental | 117 Use `icomplete-mode' function to set it up properly for incremental |
127 minibuffer completion.") | 118 minibuffer completion.") |
128 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit) | 119 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit) |
129 | 120 |
130 ;; XEmacs addition | 121 (defvar icomplete-show-key-bindings t |
131 (defvar icomplete-show-key-bindings (string-match "XEmacs\\|Lucid" | 122 "When non-nil, show key bindings as well as completion for sole matches.") |
132 emacs-version) | |
133 "When non-nil show key bindings as well as completion when matching | |
134 a command. Currently working only for XEmacs - see `icomplete-get-keys'.") | |
135 | 123 |
136 (defun icomplete-get-keys (func-name) | 124 (defun icomplete-get-keys (func-name) |
137 "Return the keys `func-name' is bound to as a string, or nil if none. | 125 "Return strings naming keys bound to `func-name', or nil if none. |
138 NOTE that this depends on `owindow' minbuf setting and `current-local-map' | 126 Examines the prior, not current, buffer, presuming that current buffer |
139 taking arg, both present in XEmacs but not present in mainline GNU Emacs | 127 is minibuffer." |
140 19.34." | 128 (if (commandp func-name) |
141 (when (commandp func-name) | |
142 (save-excursion | 129 (save-excursion |
143 ;; Depends on dynamic scope from read-from-minibuffer :-( | |
144 (let* ((sym (intern func-name)) | 130 (let* ((sym (intern func-name)) |
145 (buf (set-buffer (window-buffer owindow))) | 131 (buf (other-buffer)) |
146 (keys (where-is-internal sym (current-local-map buf)))) | 132 (map (save-excursion (set-buffer buf) (current-local-map))) |
133 (keys (where-is-internal sym map))) | |
147 (if keys | 134 (if keys |
148 (concat "<" | 135 (concat "<" |
149 (mapconcat 'key-description | 136 (mapconcat 'key-description |
150 (sort keys | 137 (sort keys |
151 #'(lambda (x y) | 138 #'(lambda (x y) |
152 (< (length x) (length y)))) | 139 (< (length x) (length y)))) |
153 ", ") | 140 ", ") |
154 ">")))))) | 141 ">")))))) |
155 | 142 |
156 ;;;_ > icomplete-mode (&optional prefix) | 143 ;;;_ > icomplete-mode (&optional prefix) |
157 ;;;###autoload | 144 ;;;###autoload |
158 (defun icomplete-mode (&optional prefix) | 145 (defun icomplete-mode (&optional prefix) |
159 "Activate incremental minibuffer completion for this emacs session, | 146 "Activate incremental minibuffer completion for this emacs session. |
160 or deactivate with negative prefix arg." | 147 Deactivates with negative universal argument." |
161 (interactive "p") | 148 (interactive "p") |
162 (or prefix (setq prefix 0)) | 149 (or prefix (setq prefix 0)) |
163 (cond ((>= prefix 0) | 150 (cond ((>= prefix 0) |
164 (setq icomplete-mode t) | 151 (setq icomplete-mode t) |
165 ;; The following is not really necessary after first time - | 152 ;; The following is not really necessary after first time - |
167 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)) | 154 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup)) |
168 (t (setq icomplete-mode nil)))) | 155 (t (setq icomplete-mode nil)))) |
169 | 156 |
170 ;;;_ > icomplete-simple-completing-p () | 157 ;;;_ > icomplete-simple-completing-p () |
171 (defun icomplete-simple-completing-p () | 158 (defun icomplete-simple-completing-p () |
172 | |
173 "Non-nil if current window is minibuffer that's doing simple completion. | 159 "Non-nil if current window is minibuffer that's doing simple completion. |
174 | 160 |
175 Conditions are: | 161 Conditions are: |
176 the selected window is a minibuffer, | 162 the selected window is a minibuffer, |
177 and not in the middle of macro execution, | 163 and not in the middle of macro execution, |
223 (setq icomplete-eoinput 1)))) | 209 (setq icomplete-eoinput 1)))) |
224 | 210 |
225 ;;;_ > icomplete-exhibit () | 211 ;;;_ > icomplete-exhibit () |
226 (defun icomplete-exhibit () | 212 (defun icomplete-exhibit () |
227 "Insert icomplete completions display. | 213 "Insert icomplete completions display. |
228 | |
229 Should be run via minibuffer `post-command-hook'. See `icomplete-mode' | 214 Should be run via minibuffer `post-command-hook'. See `icomplete-mode' |
230 and `minibuffer-setup-hook'." | 215 and `minibuffer-setup-hook'." |
231 (if (icomplete-simple-completing-p) | 216 (if (icomplete-simple-completing-p) |
232 (let ((contents (buffer-substring (point-min)(point-max))) | 217 (let ((contents (buffer-substring (point-min)(point-max))) |
233 (buffer-undo-list t)) | 218 (buffer-undo-list t)) |
279 \{...} - multiple prospects, separated by commas, are indicated, and | 264 \{...} - multiple prospects, separated by commas, are indicated, and |
280 further input is required to distinguish a single one. | 265 further input is required to distinguish a single one. |
281 | 266 |
282 The displays for unambiguous matches have ` [Matched]' appended | 267 The displays for unambiguous matches have ` [Matched]' appended |
283 \(whether complete or not), or ` \[No matches]', if no eligible | 268 \(whether complete or not), or ` \[No matches]', if no eligible |
284 matches exist. \(In XEmacs, keybindings for matched commands, if any, | 269 matches exist. \(Keybindings for uniquely matched commands are |
285 are exhibited within the square braces.)" | 270 exhibited within the square braces.)" |
286 | 271 |
287 ;; 'all-completions' doesn't like empty | 272 ;; 'all-completions' doesn't like empty |
288 ;; minibuffer-completion-table's (ie: (nil)) | 273 ;; minibuffer-completion-table's (ie: (nil)) |
289 (if (and (listp candidates) (null (car candidates))) | 274 (if (and (listp candidates) (null (car candidates))) |
290 (setq candidates nil)) | 275 (setq candidates nil)) |
361 ;; not unique": | 346 ;; not unique": |
362 (concat "," alternatives) | 347 (concat "," alternatives) |
363 alternatives) | 348 alternatives) |
364 close-bracket-prospects))))))) | 349 close-bracket-prospects))))))) |
365 | 350 |
366 ;;;_ + Initialization | 351 (if (string-match "XEmacs\\|Lucid" emacs-version) |
367 ;;; If user hasn't setq-default icomplete-mode to nil, then setup for | 352 (add-hook 'icomplete-minibuffer-setup-hook 'icomplete-exhibit)) |
368 ;;; activation: | |
369 (if icomplete-mode | |
370 (icomplete-mode)) | |
371 | |
372 | 353 |
373 ;;;_* Local emacs vars. | 354 ;;;_* Local emacs vars. |
374 ;;;Local variables: | 355 ;;;Local variables: |
375 ;;;outline-layout: (-2 :) | 356 ;;;outline-layout: (-2 :) |
376 ;;;End: | 357 ;;;End: |