annotate lisp/packages/icomplete.el @ 10:49a24b4fd526 r19-15b6

Import from CVS: tag r19-15b6
author cvs
date Mon, 13 Aug 2007 08:47:52 +0200
parents b82b59fe008d
children e04119814345
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>
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
7 ;;; Version: $Id: icomplete.el,v 1.1.1.3 1996/12/18 03:53:27 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
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
94 (if (string-match "XEmacs\\|Lucid" emacs-version)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
95 (add-hook 'icomplete-minibuffer-setup-hook 'icomplete-exhibit))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
96
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;;_ + Internal Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;_ = icomplete-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defvar icomplete-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "Non-nil enables incremental minibuffer completion, once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 `\\[icomplete-mode]' function has set things up.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;;_ = icomplete-eoinput 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defvar icomplete-eoinput 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Point where minibuffer input ends and completion info begins.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (make-variable-buffer-local 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;;_ = icomplete-pre-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defvar icomplete-pre-command-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "Incremental-minibuffer-completion pre-command-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Is run in minibuffer before user input when `icomplete-mode' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Use `icomplete-mode' function to set it up properly for incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 minibuffer completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;;_ = icomplete-post-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvar icomplete-post-command-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Incremental-minibuffer-completion post-command-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Is run in minibuffer after user input when `icomplete-mode' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 Use `icomplete-mode' function to set it up properly for incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 minibuffer completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
123 ;; XEmacs addition
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
124 (defvar icomplete-show-key-bindings t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
125 "When non-nil show key bindings as well as completion when matching
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
126 a command.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
128 ;; XEmacs addition
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
129 (defun icomplete-get-keys (func-name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 "Return the keys `func-name' is bound to as a string."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
131 (when (commandp func-name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
132 (let* ((sym (intern func-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 (keys (where-is-internal sym)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
134 (concat "<"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
135 (if keys
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 (mapconcat 'key-description
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137 (sort '([next] [kp_next] [(control v)])
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
138 #'(lambda (x y)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
139 (< (length x) (length y))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
140 ", ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
141 "Unbound")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
142 ">"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;;_ > icomplete-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defun icomplete-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "Activate incremental minibuffer completion for this emacs session,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 or deactivate with negative prefix arg."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (or prefix (setq prefix 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (cond ((>= prefix 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq icomplete-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; The following is not really necessary after first time -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; no great loss.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (add-hook 'minibuffer-setup-hook 'icomplete-minibuffer-setup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (t (setq icomplete-mode nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;;_ > icomplete-simple-completing-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun icomplete-simple-completing-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 "Non-nil if current window is minibuffer that's doing simple completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 Conditions are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 the selected window is a minibuffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 and not in the middle of macro execution,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 and minibuffer-completion-table is not a symbol (which would
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
167 indicate some non-standard, non-simple completion mechanism,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 like file-name and other custom-func completions)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (and (window-minibuffer-p (selected-window))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
171 (not executing-kbd-macro)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (not (symbolp minibuffer-completion-table))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
173
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;;_ > icomplete-minibuffer-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defun icomplete-minibuffer-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Run in minibuffer on activation to establish incremental completion.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
178 Usually run by inclusion in `minibuffer-setup-hook'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (cond ((and icomplete-mode (icomplete-simple-completing-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (make-local-hook 'pre-command-hook)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
181 (add-hook 'pre-command-hook
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
182 (function (lambda ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
183 (run-hooks 'icomplete-pre-command-hook)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
184 nil t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (make-local-hook 'post-command-hook)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
186 (add-hook 'post-command-hook
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
187 (function (lambda ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
188 (run-hooks 'icomplete-post-command-hook)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
189 nil t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (run-hooks 'icomplete-minibuffer-setup-hook))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
191
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;;_* Completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;;_ > icomplete-tidy ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defun icomplete-tidy ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "Remove completions display \(if any) prior to new user input.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
197 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
198 and `minibuffer-setup-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (icomplete-simple-completing-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (and (boundp 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (> icomplete-eoinput (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; Oops, got rug pulled out from under us - reinit:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (setq icomplete-eoinput (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (delete-region icomplete-eoinput (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (make-local-variable 'icomplete-eoinput)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq icomplete-eoinput 1))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
212
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;;;_ > icomplete-exhibit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defun icomplete-exhibit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "Insert icomplete completions display.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 and `minibuffer-setup-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if (icomplete-simple-completing-p)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 (let ((contents (buffer-substring (point-min)(point-max)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
220 (buffer-undo-list t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ; Register the end of input, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ; know where the extra stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ; (match-status info) begins:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (not (boundp 'icomplete-eoinput))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; In case it got wiped out by major mode business:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (make-local-variable 'icomplete-eoinput))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (setq icomplete-eoinput (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ; Insert the match-status information:
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
231 (if (> (point-max) 1)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (insert-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (icomplete-completions contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 minibuffer-completion-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 minibuffer-completion-confirm))))))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
238
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;;;_ > icomplete-completions (name candidates predicate require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun icomplete-completions (name candidates predicate require-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Identify prospective candidates for 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 The display is updated with each minibuffer keystroke during
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 minibuffer completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Prospective completion suffixes (if any) are displayed, bracketed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 one of \(), \[], or \{} pairs. The choice of brackets is as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 \(...) - a single prospect is identified and matching is enforced,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 \[...] - a single prospect is identified but matching is optional, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 \{...} - multiple prospects, separated by commas, are indicated, and
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
252 further input is required to distinguish a single one.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
254 The displays for unambiguous matches have ` [Matched]' appended
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
255 \(whether complete or not), or ` \[No matches]', if no eligible
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 matches exist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (let ((comps (all-completions name candidates predicate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ; "-determined" - only one candidate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (open-bracket-determined (if require-match "(" "["))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (close-bracket-determined (if require-match ")" "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;"-prospects" - more than one candidate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (open-bracket-prospects "{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (close-bracket-prospects "}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 )
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
266 (cond ((null comps) (format " %sNo matches%s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
267 open-bracket-determined
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
268 close-bracket-determined))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
269 ((null (cdr comps)) ;one match
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
270 (concat (if (and (> (length (car comps))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
271 (length name)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
272 (concat open-bracket-determined
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
273 (substring (car comps) (length name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
274 close-bracket-determined)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
275 "")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
276 " [Matched]"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
277 ;; XEmacs
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
278 (if (and icomplete-show-key-bindings
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
279 (commandp (intern-soft (car comps))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
280 (icomplete-get-keys (car comps))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
281 "")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
282 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
283 (t ;multiple matches
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
284 (let* ((most (try-completion name candidates predicate))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
285 (most-len (length most))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
286 most-is-exact
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
287 (alternatives
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
288 (apply
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
289 (function concat)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 (cdr (apply
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
291 (function nconc)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
292 (mapcar '(lambda (com)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
293 (if (= (length com) most-len)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
294 ;; Most is one exact match,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
295 ;; note that and leave out
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
296 ;; for later indication:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
297 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
298 (setq most-is-exact t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
299 ())
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
300 (list ","
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
301 (substring com
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
302 most-len))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
303 comps))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
304 (concat (and (> most-len (length name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
305 (concat open-bracket-determined
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
306 (substring most (length name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 close-bracket-determined))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
308 open-bracket-prospects
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
309 (if most-is-exact
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
310 (concat "," alternatives)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
311 alternatives)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
312 close-bracket-prospects))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;;;_ + Initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;;; If user hasn't setq-default icomplete-mode to nil, then setup for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;;; activation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (if icomplete-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (icomplete-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;;;_* Local emacs vars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;;;Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;;;outline-layout: (-2 :)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;;;End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;;; icomplete.el ends here