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