annotate lisp/ilisp/completer.el @ 119:d101af7320b8

Added tag r20-1b11 for changeset 7d55a9ba150c
author cvs
date Mon, 13 Aug 2007 09:24:19 +0200
parents 360340f9fd5f
children
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 ;;; -*-Emacs-Lisp-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;;%Header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Rcs_Info: completer.el,v 3.23 1993/09/03 02:05:07 ivan Rel $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Partial completion mechanism for GNU Emacs. Version 3.03
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Copyright (C) 1990, 1991, 1992 Chris McConnell, ccm@cs.cmu.edu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Thanks to Bjorn Victor for suggestions, testing, and patches for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; file completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; but WITHOUT ANY WARRANTY. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; unless he says so in writing. Refer to the GNU Emacs General Public
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; License for full details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; GNU Emacs General Public License. A copy of this license is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; supposed to have been given to you along with GNU Emacs so you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; can know your rights and responsibilities. It should be in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; file named COPYING. Among other things, the copyright notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; When loaded, this file extends the standard completion mechanisms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; so that they perform pattern matching completions. There is also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; an interface that allows it to be used by other programs. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; completion rules are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; 1) If what has been typed matches any possibility, do normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; 2) Otherwise, generate a regular expression such that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; completer-words delimit words and generate all possible matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; The variable completer-any-delimiter can be set to a character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; that matches any delimiter. If it were " ", then "by d" would be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; byte-recompile-directory. If completer-use-words is T, a match is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; unique if it is the only one with the same number of words. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; completer-use-words is NIL, a match is unique if it is the only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; possibility. If you ask the completer to use its best guess, it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; will be the shortest match of the possibilities unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; completer-exact is T.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; 3) For filenames, if completer-complete-filenames is T, each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; pathname component will be individually completed, otherwise only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; the final component will be completed. If you are using a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; distributed file system like afs, you may want to set up a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; symbolic link in your home directory or add pathname components to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; completer-file-skip so that the pathname components that go across
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; machines do not get expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; SPACE, TAB, LFD, RET, and ? do normal completion if possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; otherwise they do partial completion. In addition, C-DEL will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; undo the last partial expansion or contraction. M-RET will always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; complete to the current match before returning. This is useful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; when any string is possible, but you want to complete to a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; as when calling find-file. The bindings can be changed by using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; completer-load-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; Modes that use comint-dynamic-complete (like cmushell and ilisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; will also do partial completion as will M-tab in Emacs LISP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; Examples:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; a-f auto-fill-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; b--d *beginning-of-defun or byte-recompile-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; by d *byte-recompile-directory if completer-any-delimiter is " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; ~/i.e *~/ilisp.el or ~/il-el.el or ~/ilisp.elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; /u/mi/ /usr/misc/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
73
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
74 (require 'cl)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
75
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;;%Globals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;;%%Switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar completer-load-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "Hook called when minibuffer partial completion is loaded.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar completer-disable nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "*If T, turn off partial completion. Use the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 \\[completer-toggle] to set this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defvar completer-complete-filenames t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "*If T, then each component of a filename will be completed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 otherwise just the final component will be completed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defvar completer-use-words nil ; jwz: this is HATEFUL!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "*If T, then prefer completions with the same number of words as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 pattern.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defvar completer-words "---. <"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "*Delimiters used in partial completions. It should be a set of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 characters suitable for inclusion in a [] regular expression.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar completer-any-delimiter nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "*If a character, then a delimiter in the pattern that matches the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 character will match any delimiter in completer-words.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defvar completer-file-skip "^cs/$\\|@sys\\|.edu/$\\|.gov/$\\|.com/$\\|:/$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "*Regular expression for pathname components to not complete.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defvar completer-exact nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "*If T, then you must have an exact match. Otherwise, the shortest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 string that matches the pattern will be used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defvar completer-cache-size 100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "*Size of cache to use for partially completed pathnames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defvar completer-use-cache t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "*Set to nil to disable the partially completed pathname cache.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;;%%Internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvar completer-last-pattern ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "The last pattern expanded.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defvar completer-message nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "T if temporary message was just displayed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defvar completer-path-cache nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 "Cache of (path . choices) for completer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defvar completer-string nil "Last completer string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defvar completer-table nil "Last completer table.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defvar completer-pred nil "Last completer pred.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar completer-mode nil "Last completer mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defvar completer-result nil "Last completer result.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
130 (eval-when (eval load compile)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
131 (if (not (fboundp 'completion-display-completion-list-function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
132 (setf completion-display-completion-list-function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
133 'display-completion-list)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
134
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
135
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;;%Utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun completer-message (message &optional point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Display MESSAGE at optional POINT for two seconds."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq point (or point (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 completer-message t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (let ((end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (insert message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (delete-region point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (if (and quit-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;(not (eq 'lucid-19 ilisp-emacs-version-id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (not (string-match "Lucid" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq quit-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 unread-command-char 7))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defun completer-deleter (regexp choices &optional keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 "Destructively remove strings that match REGEXP in CHOICES and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 return the modified list. If optional KEEP, then keep entries that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 match regexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let* ((choiceb choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 choicep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if keep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (while (and choiceb (not (string-match regexp (car choiceb))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq choiceb (cdr choiceb)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq choicep choiceb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (while (cdr choicep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (if (string-match regexp (car (cdr choicep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq choicep (cdr choicep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (rplacd choicep (cdr (cdr choicep))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (while (and choiceb (string-match regexp (car choiceb)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (setq choiceb (cdr choiceb)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq choicep choiceb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (while (cdr choicep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (string-match regexp (car (cdr choicep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (rplacd choicep (cdr (cdr choicep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq choicep (cdr choicep)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 choiceb))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;;%%Regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defun completer-regexp (string delimiters any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Convert STRING into a regexp with words delimited by characters in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 DELIMITERS. Any delimiter in STRING that is the same as ANY will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 match any delimiter."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (let* ((delimiter-reg (concat "[" delimiters "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (limit (length string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (regexp "^"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (while (and (< pos limit) (string-match delimiter-reg string pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let* ((begin (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (delimiter (substring string begin end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (anyp (eq (elt string begin) any)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (format "%s%s[^%s]*%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (regexp-quote (substring string pos begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if anyp delimiters delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if anyp delimiter-reg (regexp-quote delimiter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 pos end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if (<= pos limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (setq regexp (concat regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (regexp-quote (substring string pos limit)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun completer-words (regexp string &optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Return the number of words matching REGEXP in STRING up to LIMIT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq limit (or limit 1000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (pos 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (while (and (string-match regexp string pos) (<= count limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq count (1+ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 pos (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;;%Matcher
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun completer-matches (string choices delimiters any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Return STRING's matches in CHOICES using DELIMITERS and wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ANY to segment the strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let* ((regexp (concat "[" delimiters "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (from nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (to 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (len (length string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (matches nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 sub sublen choice word wordlen pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; Segment pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (while (< (or from 0) len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq to (or (string-match regexp string (if from (1+ from))) len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if (eq (elt string (or from 0)) completer-any-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq sub (substring string (if from (1+ from) 0) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 sublen (- (length sub)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq sub (substring string (or from 0) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 sublen (length sub)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq pattern (cons (cons sub sublen) pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq pattern (reverse pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; Find choices that match patterns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq regexp (concat "[" delimiters "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (while choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (setq choice (car choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 word pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 from 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (while (and word from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (let* (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (< (setq wordlen (cdr (setq pat (car word)))) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq begin (1+ from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 end (+ begin (- wordlen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq begin from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 end (+ begin wordlen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (and (<= end (length choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (or (zerop wordlen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (car pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (substring choice begin end))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq from (string-match regexp choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if (and (zerop from) (zerop wordlen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (1+ from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 word (cdr word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (if (not word) (setq matches (cons choice matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (setq choices (cdr choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 matches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defun completer-choice (string choices delimiters use-words)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 "Return the best match of STRING in CHOICES with DELIMITERS between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 words and T if it is unique. A match is unique if it is the only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 possibility or when USE-WORDS the only possibility with the same
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
271 number of words. The shortest string of multiple possibilities will be
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 the best match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (or (if (null (cdr choices)) (cons (car choices) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (let* ((regexp (concat "[^" delimiters "]*[" delimiters "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (words (if use-words (completer-words regexp string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (choice choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (unique-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (match nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (match-count nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (match-len 1000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (while choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (let* ((current (car choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (length (length current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if match-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if (= (completer-words regexp current words) words)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq unique-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (< length match-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq match current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 match-len length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (if (and use-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (= (completer-words regexp current words) words))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq match current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 match-len length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 match-count t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 unique-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (if (< length match-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq match current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 match-len length)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq choice (cdr choice)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (cons match unique-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;;;%Completer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;;%%Utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun completer-region (delimiters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Return the completion region bounded by characters in DELIMITERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 for the current buffer assuming that point is in it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (cons (save-excursion (skip-chars-backward delimiters) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (save-excursion (skip-chars-forward delimiters) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defun completer-last-component (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 "Return the start of the last filename component in STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (let ((last (1- (length string)) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (match 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (while (and (setq match (string-match "/" string end)) (< match last))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (setq end (1+ match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defun completer-match-record (string matches delimiters any dir mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 "Return (match lcs choices unique) for STRING in MATCHES with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 DELIMITERS or ANY wildcards and DIR if a filename when in MODE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (let ((pattern (if dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (substring string (completer-last-component string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (setq matches (completer-matches pattern matches delimiters any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 match (try-completion pattern (mapcar 'list matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; If try-completion produced an exact match for an element in 'matches',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; then remove any partial matches from 'matches' and set the unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; match flag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (and (stringp match) (member match matches) (setq matches (list match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if (cdr matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (let ((lcs (concat dir (try-completion "" (mapcar 'list matches)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setq match (if (not completer-exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (completer-choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 pattern matches delimiters completer-use-words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (list (if match (concat dir (car match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 lcs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (cdr match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (if matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (progn (setq match (concat dir (car matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (list match match matches t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (list nil nil nil nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;;;%%Complete file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (defun completer-extension-regexp (extensions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 "Return a regexp that matches to a string that ends with any string from EXTENSIONS list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (concat "\\(" (mapconcat 'regexp-quote extensions "\\|") "\\)\\'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (defun completer-flush ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 "Flush completer's pathname cache."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq completer-path-cache nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defun completer-cache (path pred words any mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 "Check to see if PATH is in path cache with PRED, WORDS, ANY and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 MODE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (let* ((last nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (ptr completer-path-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (size 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (if completer-use-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (while ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (let ((current (car (car ptr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (if (string-equal current path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (if last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (rplacd last (cdr ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (rplacd ptr completer-path-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (setq completer-path-cache ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (setq result (cdr (car ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ptr nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (cdr ptr) (setq last ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (setq size (1+ size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ptr (cdr ptr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (or result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (let* ((choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (completer path 'read-file-name-internal pred words any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 mode t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if (and (or (car (cdr (cdr (cdr choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (string= path (car choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (eq (elt (car choices) (1- (length (car choices)))) ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if (>= size completer-cache-size) (rplacd last nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (setq completer-path-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (cons (cons path choices) completer-path-cache))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (defun completer-file (string pred words any mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 "Return (match common-substring matches unique-p) for STRING using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 read-file-name-internal for choices that pass PRED using WORDS to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 delimit words. Optional ANY is a delimiter that matches any of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 delimiters in WORD. If optional MODE is nil or 'help then possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 matches will always be returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (let* ((case-fold-search completion-ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (last (and (eq mode 'exit-ok) (completer-last-component string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ;; Special hack for CMU RFS filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (if (string-match "^/\\.\\./[^/]*/" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (string-match "[^~/]" string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (new (substring string 0 position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (user (if (string= new "~")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (setq new (file-name-directory (expand-file-name new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (words (concat words "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (len (length string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (choices nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (old-choices (list nil nil nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (while position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (let* ((begin (string-match "/" string position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (exact-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq end (if begin (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Ends with a /, so check files in directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (if (and (memq mode '(nil help)) (= position len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (completer-match-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;; This assumes that .. and . come at the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let* ((choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (all-completions new 'read-file-name-internal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (choicep choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (if (string= (car choicep) "../")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (cdr (cdr choicep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (while (cdr choicep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (string= (car (cdr choicep)) "../")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (rplacd choicep nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq choicep (cdr choicep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 words any new mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (if (eq position last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let ((new (concat new (substring string position))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (list new new nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (let ((component (substring string position end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if (and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (string-match completer-file-skip component))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; Assume component is complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (list (concat new component)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (concat new component)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (completer-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (concat new component)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 pred words any mode))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; Keep going if unique or we match exactly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (if (or (car (cdr (cdr (cdr choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (setq exact-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (string= (concat new (substring string position end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (car choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (setq old-choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (let* ((lcs (car (cdr choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (matches (car (cdr (cdr choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (slash (and lcs (string-match "/$" lcs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if slash (substring lcs 0 slash) lcs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (if (and (cdr matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (or (eq mode 'help) (not exact-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 new (car choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 position end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; Its ok to not match user names because they may be in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; different root directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (and (= position 1) (= (elt string 0) ?~))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (setq new (substring string 0 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 choices (list new new (list new) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 user nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 position end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq position nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (not (car choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (setq choices old-choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (if (and (car choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (not (eq mode 'help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (not (car (cdr (cdr (cdr choices))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; Try removing completion ignored extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (let* ((extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (completer-extension-regexp completion-ignored-extensions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (choiceb (car (cdr (cdr choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (choicep choiceb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (isext nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (noext nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (while choicep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if (string-match extensions (car choicep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq isext t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setq noext t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if (and isext noext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;; There are matches besides extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (setq choiceb (completer-deleter extensions choiceb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 choicep nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (setq choicep (cdr choicep))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if (and isext noext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (setq choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (completer-match-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (if end (substring string end) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 choiceb words any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (file-name-directory (car (cdr choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 mode)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (if user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (let ((match (car choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (lcs (car (cdr choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (len (length user)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setq choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (cons (if match (concat "~" (substring match len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (cons (if lcs (concat "~" (substring lcs len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (cdr (cdr choices)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;;;%Exported program interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;;;%%Completer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defun completer (string table pred words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 &optional any mode file-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 "Return (match common-substring matches unique-p) for STRING in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 TABLE for choices that pass PRED using WORDS to delimit words. If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 flag completer-complete-filenames is T and the table is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 read-file-name-internal, then filename components will be individually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 expanded. Optional ANY is a delimiter that can match any delimiter in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 WORDS. Optional MODE is nil for complete, 'help for help and 'exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 for exit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (and (stringp completer-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (string= string completer-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (eq table completer-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (eq pred completer-pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (not file-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (or (eq mode completer-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (not (memq table '(read-file-name-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 read-directory-name-internal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 completer-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 completer-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 completer-table table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 completer-pred pred
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 completer-mode mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 completer-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (if (and completer-complete-filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (not file-p) (eq table 'read-file-name-internal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (completer-file string pred words any mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (let* ((file-p (or file-p (eq table 'read-file-name-internal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (case-fold-search completion-ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (pattern (concat "[" words "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (component (if file-p (completer-last-component string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (dir (if component (substring string 0 component)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (string (if dir (substring string component) string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (has-words (or (string-match pattern string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (length string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if (and file-p (string-match "^\\$" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; Handle environment variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (let ((match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (getenv (substring string 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (string-match "/" string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (if match (setq match (concat match "/")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (list match match (list match) match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (let* ((choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (concat dir (substring string 0 has-words))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 table pred))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (regexp (completer-regexp string words any)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (completer-match-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (completer-deleter regexp choices t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 words any dir mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (list nil nil nil nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 completer-string string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 completer-result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;;;%%Display choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (defun completer-display-choices (choices &optional match message end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 "Display the list of possible CHOICES with optional MATCH, MESSAGE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 END and DISPLAY. If MATCH is non-nil, it will be flagged as the best
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 guess. If there are no choices, display MESSAGE. END is where to put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 temporary messages. If DISPLAY is present then it will be called on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 each possible completion and should return a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (if choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (if (cdr choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (funcall completion-display-completion-list-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (if display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (let ((old choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (new nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (while old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (setq new (cons (funcall display (car old)) new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 old (cdr old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (copy-sequence choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (string-lessp (or (car-safe x) x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (or (car-safe y) y)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (if match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (set-buffer "*Completions*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (insert "Guess = " match (if (cdr choices) ", " "") "\n")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (completer-message (or message " (No completions)") end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;;;%%Goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (defun completer-goto (match lcs choices unique delimiters words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 &optional mode display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 "MATCH is the best match, LCS is the longest common substring of all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 of the matches. CHOICES is a list of the possibilities, UNIQUE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 indicates if MATCH is unique. DELIMITERS are possible bounding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 characters for the completion region. WORDS are the characters that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 delimit the words for partial matches. Replace the region bounded by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 delimiters with the match if unique and the lcs otherwise unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 optional MODE is 'help. Then go to the part of the string that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 disambiguates choices using WORDS to separate words and display the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 possibilities if the string was not extended. If optional DISPLAY is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 present then it will be called on each possible completion and should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 return a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (setq completer-message nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (let* ((region (completer-region delimiters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (start (car region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (end (cdr region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (string (buffer-substring start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (file-p (string-match "[^ ]*\\(~\\|/\\|$\\)" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (no-insert (eq mode 'help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (message t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (new (not (string= (buffer-substring start (point)) lcs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (if unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (if no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (completer-display-choices choices match nil end display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (if (string= string match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (if (not file-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (progn (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (completer-message " (Sole completion)" end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (completer-insert match delimiters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;;Not unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (if lcs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (let* ((regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (concat "[" words (if file-p "/") "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (words (completer-words regexp lcs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; Go to where its ambiguous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (not no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (insert lcs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (setq completer-last-pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (list string delimiters (current-buffer) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 end (+ end (length lcs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; Skip to the first delimiter in the original string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; beyond the ambiguous point and keep from there on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (if (re-search-forward regexp end 'move words)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (if (and (not no-insert) match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (let ((delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (string-match (regexp-quote lcs) match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (substring match (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (1+ (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (if (string-match regexp delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (insert delimiter))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (forward-char -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (if (not no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (setq end (- end (- (point) start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (delete-region start (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (if choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (if (or no-insert (not new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (completer-display-choices choices match nil end display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (if file-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (if (not (= (point) end)) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (if (not (save-excursion (re-search-forward "/" end t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (goto-char end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (if message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (completer-message (if no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 " (No completions)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 " (No match)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 end)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;;;%Exported buffer interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;;;%%Complete and go
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (defun completer-complete-goto (delimiters words table pred
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 &optional no-insert display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 "Complete the string bound by DELIMITERS using WORDS to bound words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 for partial matches in TABLE with PRED and then insert the longest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 common substring unless optional NO-INSERT and go to the point of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ambiguity. If optional DISPLAY, it will be called on each match when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 possible completions are shown and should return a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (let* ((region (completer-region delimiters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (apply 'completer-goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (append (completer (buffer-substring (car region) (cdr region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 table pred words completer-any-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (list delimiters words no-insert display)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ;;;%%Undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (defun completer-insert (match delimiters &optional buffer undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 "Replace the region bounded with characters in DELIMITERS by MATCH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 and save it so that it can be restored by completer-undo."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (let* ((region (completer-region delimiters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (start (car region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (end (cdr region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (if (and undo (or (not (= start undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (not (eq (current-buffer) buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (error "No previous pattern")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (setq completer-last-pattern (list (buffer-substring start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (insert match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (defun completer-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 "Swap the last expansion and the last match pattern."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (if completer-last-pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (apply 'completer-insert completer-last-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (error "No previous pattern")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;;;%Minibuffer specific code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;;;%%Utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (defun completer-minibuf-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 "Remove dead filename specs from the minibuffer as delimited by //
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 or ~ or $ and return the resulting string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (re-search-backward "//\\|/~\\|.\\$" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (delete-region (point-min) (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (buffer-substring (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (defun completer-minibuf-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 "Exit the minibuffer and clear completer-last-pattern."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (setq completer-last-pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (defun completer-new-cmd (cmd)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
750 "Return T if we can't execute the old minibuffer version of CMD."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (if (or completer-disable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (let ((string (completer-minibuf-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (not (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (concat "[" completer-words "/~]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (let ((completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (try-completion string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 minibuffer-completion-predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (if (eq minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 'read-file-name-internal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; Directories complete as themselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (and completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (or (not (string= string completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (file-exists-p completion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (error nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (funcall cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (defun completer-minibuf (&optional mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 "Partial completion of minibuffer expressions. Optional MODE is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 'help for help and 'exit for exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 If what has been typed so far matches any possibility normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 completion will be done. Otherwise, the string is considered to be a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 pattern with words delimited by the characters in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 completer-words. If completer-exact is T, the best match will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 the shortest one with the same number of words as the pattern if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 possible and otherwise the shortest matching expression. If called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 with a prefix, caching will be temporarily disabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 Examples:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 a-f auto-fill-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 r-e rmail-expunge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 b--d *begining-of-defun or byte-recompile-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 by d *byte-recompile-directory if completer-any-delimiter is \" \"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ~/i.e *~/ilisp.el or ~/il-el.el or ~/ilisp.elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 /u/mi/ /usr/misc/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (let ((completer-use-cache (not (or (not completer-use-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (completer (completer-minibuf-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 minibuffer-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 minibuffer-completion-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 completer-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 completer-any-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (list "^" completer-words mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;;;%%Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (defun completer-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 "Turn partial completion on or off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (setq completer-disable (not completer-disable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (message (if completer-disable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 "Partial completion OFF"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 "Partial completion ON")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (defvar completer-old-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (lookup-key minibuffer-local-must-match-map "?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 "Old binding of ? in minibuffer completion map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (defun completer-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 "Partial completion minibuffer-completion-help.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 See completer-minibuf for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (if (completer-new-cmd completer-old-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (apply 'completer-goto (completer-minibuf 'help))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (defvar completer-old-completer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (lookup-key minibuffer-local-must-match-map "\t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 "Old binding of TAB in minibuffer completion map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (defun completer-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 "Partial completion minibuffer-complete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 See completer-minibuf for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (if (completer-new-cmd completer-old-completer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (apply 'completer-goto (completer-minibuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (defvar completer-old-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (lookup-key minibuffer-local-must-match-map " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 "Old binding of SPACE in minibuffer completion map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defun completer-word ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 "Partial completion minibuffer-complete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 See completer-minibuf for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (if (eq completer-any-delimiter ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (insert ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (if (completer-new-cmd completer-old-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (apply 'completer-goto (completer-minibuf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (defvar completer-old-exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (lookup-key minibuffer-local-must-match-map "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 "Old binding of RET in minibuffer completion map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defun completer-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 "Partial completion minibuffer-complete-and-exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 See completer-minibuf for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (if (completer-new-cmd completer-old-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (let* ((completions (completer-minibuf 'exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (match (car completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (unique-p (car (cdr (cdr (cdr completions))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (apply 'completer-goto completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (if unique-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (completer-minibuf-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (if match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (progn (completer-insert match "^")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (if minibuffer-completion-confirm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (completer-message " (Confirm)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (completer-minibuf-exit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (if (not completer-message) (beep)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (defun completer-match-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 "Exit the minibuffer with the current best match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (let* ((completions (completer-minibuf 'exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (guess (car completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if (not guess)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;; OK if last filename component doesn't match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (setq completions (completer-minibuf 'exit-ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 guess (car completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (if guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (insert guess)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (apply 'completer-goto completions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;;;%%Keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;this interferes with normal undo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;(define-key minibuffer-local-completion-map "\C-_" 'completer-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (define-key minibuffer-local-completion-map "\t" 'completer-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (define-key minibuffer-local-completion-map " " 'completer-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (define-key minibuffer-local-completion-map "?" 'completer-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (define-key minibuffer-local-completion-map "\n" 'completer-minibuf-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (define-key minibuffer-local-completion-map "\r" 'completer-minibuf-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (define-key minibuffer-local-completion-map "\M-\n" 'completer-match-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (define-key minibuffer-local-completion-map "\M-\r" 'completer-match-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 ;this interferes with normal undo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 ;(define-key minibuffer-local-must-match-map "\C-_" 'completer-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (define-key minibuffer-local-must-match-map "\t" 'completer-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (define-key minibuffer-local-must-match-map " " 'completer-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (define-key minibuffer-local-must-match-map "\n" 'completer-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (define-key minibuffer-local-must-match-map "\r" 'completer-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (define-key minibuffer-local-must-match-map "?" 'completer-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (define-key minibuffer-local-must-match-map "\M-\n" 'completer-match-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (define-key minibuffer-local-must-match-map "\M-\r" 'completer-match-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;;;%comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (defun completer-comint-dynamic-list-completions (completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 "List in help buffer sorted COMPLETIONS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 Typing SPC flushes the help buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (completer-comint-dynamic-complete-1 nil 'help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (defun completer-comint-dynamic-complete-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 "Dynamically complete the filename at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (completer-comint-dynamic-complete-1 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (defun completer-comint-dynamic-complete-1 (&optional undo mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 "Complete the previous filename or display possibilities if done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 twice in a row. If called with a prefix, undo the last completion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (completer-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ;; added by jwz: don't cache completions in shell buffer!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (setq completer-string nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (let ((conf (current-window-configuration)));; lemacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (completer-complete-goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 "^ \t\n\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 completer-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 'read-file-name-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;; lemacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (if (eq mode 'help) (comint-restore-window-config conf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;(fset 'comint-dynamic-complete 'completer-comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (fset 'comint-dynamic-complete-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 'completer-comint-dynamic-complete-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (fset 'comint-dynamic-list-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 'completer-comint-dynamic-list-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;;; Set the functions again if comint is loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (setq comint-load-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (cons (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;; (fset 'comint-dynamic-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ;; 'completer-comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (fset 'comint-dynamic-complete-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 'completer-comint-dynamic-complete-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (fset 'comint-dynamic-list-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 'completer-comint-dynamic-list-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (if (and (boundp 'comint-load-hook) comint-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (if (consp comint-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (if (eq (car comint-load-hook) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (list comint-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 comint-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (list comint-load-hook)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ;;;%lisp-complete-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (defun lisp-complete-symbol (&optional mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 "Perform partial completion on Lisp symbol preceding point. That
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 symbol is compared against the symbols that exist and any additional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 characters determined by what is there are inserted. If the symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 starts just after an open-parenthesis, only symbols with function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 definitions are considered. Otherwise, all symbols with function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 definitions, values or properties are considered. If called with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 negative prefix, the last completion will be undone."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (if (< (prefix-numeric-value mode) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (completer-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (let* ((end (save-excursion (skip-chars-forward "^ \t\n)]}\"") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (beg (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (while (= (char-syntax (following-char)) ?\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (pattern (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (if (eq (char-after (1- beg)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 'fboundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (function (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (or (boundp sym) (fboundp sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (symbol-plist sym))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (completion (try-completion pattern obarray predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (cond ((eq completion t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (completer-complete-goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 "^ \t\n\(\)[]{}'`" completer-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 obarray predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (if (not (eq predicate 'fboundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (function (lambda (choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (if (fboundp (intern choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (list choice " <f>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 choice))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ((not (string= pattern completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (insert completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (message "Making completion list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (let ((list (all-completions pattern obarray predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (or (eq predicate 'fboundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (let (new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (setq new (cons (if (fboundp (intern (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (list (car list) " <f>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (setq list (nreverse new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (funcall completion-display-completion-list-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (sort list (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (string-lessp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (or (car-safe x) x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (or (car-safe y) y))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (message "Making completion list...%s" "done"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;;;%Hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (provide 'completer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (run-hooks 'completer-load-hook)