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