annotate lisp/packages/icomplete.el @ 2:ac2d302a0011 r19-15b2

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