annotate lisp/icomplete.el @ 8434:36da3d480ccd

(icomplete-prime-minibuffer): Copy the hook lists after making them local.
author Richard M. Stallman <rms@gnu.org>
date Wed, 03 Aug 1994 21:23:30 +0000
parents 0e30cf7aa525
children 299cfe0a6069
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; icomplete.el - minibuffer completion incremental feedback
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
2 ;;; This package is in the public domain.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;;; Author: Ken Manheimer <klm@nist.gov>
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;;; Maintainer: Ken Manheimer <klm@nist.gov>
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
6 ;;; Version: icomplete.el,v 3.3 1993/12/11 11:27:35 klm Exp klm
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;;; Created: Mar 1993 klm@nist.gov - first release to usenet
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;;; Keywords: help, abbrev
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;;; Commentary:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;;; Loading this package implements a more finely-grained completion
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;;; feedback scheme, indicating, within the minibuffer, the
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;;; prospective minibuffer completion candidates, as you type. See
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;;; the documentation string for 'icomplete-prompt' for a specific
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;;; description of icompletion.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
18 ;;; It should run on most version of Emacs 19 (including Lucid emacs
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
19 ;;; 19 - thanks to the efforts of Colin Rafferty (craffert@lehman.com)
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
20 ;;; - thanks, Colin!) This version of icomplete will *not* work on
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
21 ;;; Emacs 18 versions - the elisp archives, at
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
22 ;;; archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive, probably
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
23 ;;; still has a version that works in GNU Emacs v18.
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
24
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
25 ;;; Thanks to Colin Rafferty for assistance reconciling for lemacs,
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
26 ;;; and to Michael Cook, who implemented an incremental completion
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
27 ;;; style in his 'iswitch' functions that served as the basis for
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
28 ;;; icomplete.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Code:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
32 ;;;_* (Allout outline root topic. Please leave this in.)
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
33
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;;_ + Provide
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (provide 'icomplete)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;;_ + User Customization variables
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;;_ = icomplete-inhibit
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (defvar icomplete-inhibit nil
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 "*Set this variable to t at any time to inhibit icomplete.")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
42 ;;;_ + Internal Variables
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
43 ;;;_ = icomplete-eoinput 1
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (defvar icomplete-eoinput 1
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 "Point where minibuffer input ends and completion info begins.")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (make-variable-buffer-local 'icomplete-eoinput)
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
47
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
48 ;;;_ > icomplete-prime-session ()
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
49 ;;;###autoload
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defun icomplete-prime-session ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
52 "Prep emacs v 19 for more finely-grained minibuffer completion-feedback.
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
53
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
54 You can inhibit icomplete after loading by setting icomplete-inhibit
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
55 non-nil. Set the var back to nil to re-enable icomplete."
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
57 ;; For emacs v19.18 and later revs, the icomplete key function is
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
58 ;; installed in 'minibuffer-setup-hook'. Global pre- and post-
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
59 ;; command-hook functions are used in v19.17 and earlier v19 revs."
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
60
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
61 (let* ((v19-rev (and (string-match "^19\\.\\([0-9]+\\)" emacs-version)
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (string-to-int (substring emacs-version
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (match-beginning 1)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (match-end 1))))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
66 (cond ((and v19-rev ; emacs v 19, some rev,
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
67 (> v19-rev 17))
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
68 ;; Post v19rev17, has minibuffer-setup-hook, use it:
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
69 (add-hook 'minibuffer-setup-hook 'icomplete-prime-minibuffer))
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
70 (v19-rev
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
71 ;; v19rev17 and prior (including lucid): use global
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
72 ;; pre- and post-command-hooks, instead:
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
73 (add-hook 'pre-command-hook 'icomplete-pre-command-hook 'append)
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
74 (add-hook 'post-command-hook
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
75 'icomplete-post-command-hook 'append))
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
76 ((format "icomplete: non v19 emacs, %s - %s"
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
77 emacs-version "try elisp-archive icomplete")))))
8434
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
78
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
79 ;;;_ > icomplete-prime-minibuffer ()
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (defun icomplete-prime-minibuffer ()
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
81 "Prep emacs, v 19.18 or later, for icomplete.
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
82 \(In emacs v19.17 and earlier, and in lemacs, icomplete-prime-session
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
83 is used, instead to establish global hooks.\)
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
8434
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
85 Run via `minibuffer-setup-hook', adds icomplete pre- and post-command
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
86 hooks at the start of each minibuffer."
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
87
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
88 ;; Append the hooks to avoid as much as posssible interference from
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
89 ;; other hooks that foul up minibuffer quit.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (make-local-variable 'pre-command-hook)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (make-local-variable 'post-command-hook)
8434
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
92 (setq pre-command-hook (copy-sequence pre-command-hook))
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
93 (setq post-command-hook (copy-sequence post-command-hook))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (add-hook 'pre-command-hook 'icomplete-pre-command-hook)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (add-hook 'post-command-hook 'icomplete-post-command-hook))
8434
36da3d480ccd (icomplete-prime-minibuffer): Copy the hook lists after making them local.
Richard M. Stallman <rms@gnu.org>
parents: 5375
diff changeset
96
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
97 ;;;_ > icomplete-window-minibuffer-p ()
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defmacro icomplete-window-minibuffer-p ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "Returns non-nil if current window is a minibuffer window.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
102 Trivially equates to '(window-minibuffer-p (selected-window))', with
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
103 the argument definitely provided for emacsen that require it, eg Lucid."
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
104
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
105 '(window-minibuffer-p (selected-window)))
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;;_ + Completion
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
108
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;;_ - Completion feedback hooks
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;;;_ > icomplete-pre-command-hook ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun icomplete-pre-command-hook ()
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
112 "Cleanup completions display before user's new command is dealt with."
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (if (and (icomplete-window-minibuffer-p)
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
114 (not executing-macro)
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (not (symbolp minibuffer-completion-table))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (not icomplete-inhibit))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (if (and (boundp 'icomplete-eoinput)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 icomplete-eoinput)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (if (> icomplete-eoinput (point-max))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; Oops, got rug pulled out from under us - reinit:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (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
122 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (delete-region 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
124 ;; Reestablish the local variable 'cause minibuffer-setup is weird:
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (make-local-variable 'icomplete-eoinput)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (setq icomplete-eoinput 1))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;;;_ > icomplete-post-command-hook ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (defun icomplete-post-command-hook ()
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
129 "Exhibit completions, leaving bookkeeping so pre- hook can tidy up."
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
130
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
132 (not executing-macro)
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (not icomplete-inhibit) ; ... not specifically inhibited.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;(sit-for 0) ; ... redisplay and if there's input
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ; waiting, then don't icomplete
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ; (stigs suggestion) (too jumpy!)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; Inhibit for file-name and other custom-func completions:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (not (symbolp minibuffer-completion-table))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 )
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (icomplete-exhibit))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;;;_ > icomplete-window-setup-hook ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defun icomplete-window-setup-hook ()
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
144 "Exhibit completions, leaving bookkeeping so pre- hook can tidy up."
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
145
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if (and (icomplete-window-minibuffer-p) ; ... in a minibuffer.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 )
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (message "ic ws doing")(sit-for 1)))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;;;_ > icomplete-exhibit ()
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (defun icomplete-exhibit ()
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
151 "Insert icomplete completions display."
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (not (symbolp minibuffer-completion-table))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (let ((contents (buffer-substring (point-min)(point-max)))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (buffer-undo-list t))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (save-excursion
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (goto-char (point-max))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ; Register the end of input, so we
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ; know where the extra stuff
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ; (match-status info) begins:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (if (not (boundp 'icomplete-eoinput))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; In case it got wiped out by major mode business:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (make-local-variable 'icomplete-eoinput))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (setq icomplete-eoinput (point))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ; Insert the match-status information:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (if (> (point-max) 1)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (insert-string
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (icomplete-prompt contents
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 minibuffer-completion-table
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 minibuffer-completion-predicate
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (not
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 minibuffer-completion-confirm))))))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;;;_ - Completion feedback producer
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;;;_ > icomplete-prompt (name candidates predicate require-match)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (defun icomplete-prompt (name candidates predicate require-match)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 "Identify prospective candidates for minibuffer completion.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
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 The display is updated with each minibuffer keystroke during
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 minibuffer completion.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 Prospective completion suffixes (if any) are displayed, bracketed by
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 one of \(), \[], or \{} pairs. The choice of brackets is as follows:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 \(...) - a single prospect is identified and matching is enforced,
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 \[...] - a single prospect is identified but matching is optional, or
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 \{...} - multiple prospects, separated by commas, are indicated, and
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 further input is required to distingish a single one.
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 The displays for disambiguous matches have \" [Matched]\" appended
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 \(whether complete or not), or \" \[No matches]\", if no eligible
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 matches exist."
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (let ((comps (all-completions name candidates predicate))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ; "-determined" - only one candidate
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (open-bracket-determined (if require-match "(" "["))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (close-bracket-determined (if require-match ")" "]"))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;"-prospects" - more than one candidate
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (open-bracket-prospects "{")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (close-bracket-prospects "}")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 )
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (cond ((null comps) (format " %sNo matches%s"
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 open-bracket-determined
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 close-bracket-determined))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ((null (cdr comps)) ;one match
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (concat (if (and (> (length (car comps))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (length name)))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (concat open-bracket-determined
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (substring (car comps) (length name))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 close-bracket-determined)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 " [Matched]"))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (t ;multiple matches
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (let* ((most (try-completion name candidates predicate))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (most-len (length most))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 most-is-exact
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (alternatives
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (apply
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 'concat
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (cdr (apply 'append
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (mapcar '(lambda (com)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (if (= (length com) most-len)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; Most is one exact match,
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; note that and leave out
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; for later indication:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (progn
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (setq most-is-exact t)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ())
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (list ","
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (substring com
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 most-len))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 comps))))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (concat (and (> most-len (length name))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (concat open-bracket-determined
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (substring most (length name))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 close-bracket-determined))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 open-bracket-prospects
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (if most-is-exact
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (concat "," alternatives)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 alternatives)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 close-bracket-prospects))))))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
242 ;;;_ - Initialization
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (icomplete-prime-session)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
5375
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
245
0e30cf7aa525 (icomplete-pre-command-hook): Reconciled with keyboard macro operation.
Richard M. Stallman <rms@gnu.org>
parents: 5147
diff changeset
246 ;;;_ + Local emacs vars.
5147
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 '(
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 Local variables:
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 eval: (save-excursion
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (if (not (condition-case err (outline-mode t)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (wrong-number-of-arguments nil)))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (progn
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (message
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "Allout outline-mode not loaded, not adjusting buffer exposure")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (sit-for 1))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (message "Adjusting '%s' visibility" (buffer-name))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (outline-lead-with-comment-string ";;;_")
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (goto-char 0)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (outline-exposure -1 0)))
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 End:)
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
54b3438dfc7f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 ;;; 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
263