Mercurial > hg > xemacs-beta
annotate src/minibuf.c @ 5802:236e4afc565d
Autoload within #'keymapp, as documented.
src/ChangeLog addition:
2014-07-02 Aidan Kehoe <kehoea@parhasard.net>
* keymap.c (Fkeymapp):
Autoload within this, as documented. Our callers are not prepared
to do the intelligent thing if a symbol that is fboundp to an
autoloaded keymap, is not itself #'keymapp.
lisp/ChangeLog addition:
2014-07-02 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
#'keymapp is not side-effect-free, it can autoload.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 02 Jul 2014 17:45:49 +0100 |
parents | daf5accfe973 |
children | b79e1e02bf01 |
rev | line source |
---|---|
428 | 1 /* Minibuffer input and completion. |
2 Copyright (C) 1985, 1986, 1992-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
5139
a48ef26d87ee
Clean up prototypes for Lisp variables/symbols. Put decls for them with
Ben Wing <ben@xemacs.org>
parents:
5089
diff
changeset
|
4 Copyright (C) 2002, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5139
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
428 | 9 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5139
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5139
diff
changeset
|
11 option) any later version. |
428 | 12 |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5139
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 20 |
21 /* Synched up with: Mule 2.0, FSF 19.28. Mule-ized except as noted. | |
22 Substantially different from FSF. */ | |
23 | |
24 /* #### dmoore - All sorts of things in here can call lisp, like message. | |
25 Track all this stuff. */ | |
26 | |
27 #include <config.h> | |
28 #include "lisp.h" | |
29 | |
30 #include "buffer.h" | |
31 #include "commands.h" | |
32 #include "console-stream.h" | |
33 #include "events.h" | |
872 | 34 #include "frame-impl.h" |
428 | 35 #include "insdel.h" |
36 #include "redisplay.h" | |
872 | 37 #include "window-impl.h" |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
38 #include "elhash.h" |
428 | 39 |
40 /* Depth in minibuffer invocations. */ | |
41 int minibuf_level; | |
42 | |
43 Lisp_Object Qcompletion_ignore_case; | |
44 | |
45 /* Nonzero means completion ignores case. */ | |
46 int completion_ignore_case; | |
47 | |
48 /* List of regexps that should restrict possible completions. */ | |
49 Lisp_Object Vcompletion_regexp_list; | |
50 | |
51 /* The echo area buffer. */ | |
52 Lisp_Object Vecho_area_buffer; | |
53 | |
54 /* Prompt to display in front of the minibuffer contents */ | |
55 Lisp_Object Vminibuf_prompt; | |
56 | |
57 /* Added on 97/3/14 by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */ | |
58 /* String to be displayed in front of prompt of the minibuffer contents */ | |
59 Lisp_Object Vminibuf_preprompt; | |
60 | |
61 /* Hook to run just after entry to minibuffer. */ | |
62 Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook; | |
63 | |
64 Lisp_Object Qappend_message, Qcurrent_message_label, | |
65 Qclear_message, Qdisplay_message; | |
66 | |
67 | |
68 DEFUN ("minibuffer-depth", Fminibuffer_depth, 0, 0, 0, /* | |
69 Return current depth of activations of minibuffer, a nonnegative integer. | |
70 */ | |
71 ()) | |
72 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
73 return make_fixnum (minibuf_level); |
428 | 74 } |
75 | |
76 /* The default buffer to use as the window-buffer of minibuffer windows */ | |
77 /* Note there is special code in kill-buffer to make this unkillable */ | |
78 Lisp_Object Vminibuffer_zero; | |
79 | |
80 | |
81 /* Actual minibuffer invocation. */ | |
82 | |
83 static Lisp_Object | |
84 read_minibuffer_internal_unwind (Lisp_Object unwind_data) | |
85 { | |
86 Lisp_Object frame; | |
87 XWINDOW (minibuf_window)->last_modified[CURRENT_DISP] = Qzero; | |
88 XWINDOW (minibuf_window)->last_modified[DESIRED_DISP] = Qzero; | |
89 XWINDOW (minibuf_window)->last_modified[CMOTION_DISP] = Qzero; | |
90 XWINDOW (minibuf_window)->last_facechange[CURRENT_DISP] = Qzero; | |
91 XWINDOW (minibuf_window)->last_facechange[DESIRED_DISP] = Qzero; | |
92 XWINDOW (minibuf_window)->last_facechange[CMOTION_DISP] = Qzero; | |
93 Vminibuf_prompt = Felt (unwind_data, Qzero); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
94 minibuf_level = XFIXNUM (Felt (unwind_data, make_fixnum (1))); |
428 | 95 while (CONSP (unwind_data)) |
96 { | |
97 Lisp_Object victim = unwind_data; | |
98 unwind_data = XCDR (unwind_data); | |
853 | 99 free_cons (victim); |
428 | 100 } |
101 | |
102 /* If cursor is on the minibuffer line, | |
103 show the user we have exited by putting it in column 0. */ | |
104 frame = Fselected_frame (Qnil); | |
105 if (!noninteractive | |
106 && !NILP (frame) | |
107 && !NILP (XFRAME (frame)->minibuffer_window)) | |
108 { | |
109 struct window *w = XWINDOW (XFRAME (frame)->minibuffer_window); | |
110 redisplay_move_cursor (w, 0, 0); | |
111 } | |
112 | |
113 return Qnil; | |
114 } | |
115 | |
116 /* 97/4/13 jhod: Added for input methods */ | |
117 DEFUN ("set-minibuffer-preprompt", Fset_minibuffer_preprompt, 1, 1, 0, /* | |
118 Set the minibuffer preprompt string to PREPROMPT. This is used by language | |
119 input methods to relay state information to the user. | |
120 */ | |
121 (preprompt)) | |
122 { | |
123 if (NILP (preprompt)) | |
124 { | |
125 Vminibuf_preprompt = Qnil; | |
126 } | |
127 else | |
128 { | |
129 CHECK_STRING (preprompt); | |
130 | |
131 Vminibuf_preprompt = LISP_GETTEXT (preprompt); | |
132 } | |
133 return Qnil; | |
134 } | |
135 | |
2268 | 136 DEFUN_NORETURN ("read-minibuffer-internal", Fread_minibuffer_internal, |
137 1, 1, 0, /* | |
428 | 138 Lowest-level interface to minibuffers. Don't call this. |
139 */ | |
140 (prompt)) | |
141 { | |
142 /* This function can GC */ | |
2268 | 143 |
144 /* We used to record the specpdl_depth here, but since call_command_loop | |
145 never returns, we can never call unbind_to_1. Since we exit via a throw, | |
146 we let whoever catches unbind for us. */ | |
147 | |
428 | 148 CHECK_STRING (prompt); |
149 | |
150 single_console_state (); | |
151 | |
152 record_unwind_protect (read_minibuffer_internal_unwind, | |
153 noseeum_cons | |
154 (Vminibuf_prompt, | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
155 noseeum_cons (make_fixnum (minibuf_level), Qnil))); |
428 | 156 Vminibuf_prompt = LISP_GETTEXT (prompt); |
157 | |
158 /* NOTE: Here (or somewhere around here), in FSFmacs 19.30, | |
159 choose_minibuf_frame() is called. This is the only | |
160 place in FSFmacs that it's called any more -- there's | |
161 also a call in xterm.c, but commented out, and 19.28 | |
162 had the calls in different places. | |
163 | |
164 choose_minibuf_frame() does the following: | |
165 | |
166 if (!EQ (minibuf_window, selected_frame()->minibuffer_window)) | |
167 { | |
168 Fset_window_buffer (selected_frame()->minibuffer_window, | |
169 XWINDOW (minibuf_window)->buffer); | |
170 minibuf_window = selected_frame()->minibuffer_window; | |
171 } | |
172 | |
173 #### Note that we don't do the set-window-buffer. This call is | |
174 similar, but not identical, to a set-window-buffer call made | |
175 in `read-from-minibuffer' in minibuf.el. I hope it's close | |
176 enough, because minibuf_window isn't really exported to Lisp. | |
177 | |
178 The comment above choose_minibuf_frame() reads: | |
179 | |
180 Put minibuf on currently selected frame's minibuffer. | |
181 We do this whenever the user starts a new minibuffer | |
182 or when a minibuffer exits. */ | |
183 | |
184 minibuf_window = FRAME_MINIBUF_WINDOW (selected_frame ()); | |
185 | |
186 run_hook (Qminibuffer_setup_hook); | |
187 | |
188 minibuf_level++; | |
189 clear_echo_area (selected_frame (), Qnil, 0); | |
190 | |
2286 | 191 call_command_loop (Qt); |
428 | 192 |
2286 | 193 RETURN_NOT_REACHED (Qnil); |
428 | 194 } |
195 | |
196 | |
197 | |
198 /* Completion hair */ | |
199 | |
200 /* Compare exactly LEN chars of strings at S1 and S2, | |
201 ignoring case if appropriate. | |
202 Return -1 if strings match, | |
203 else number of chars that match at the beginning. */ | |
204 | |
205 /* Note that this function works in Charcounts, unlike most functions. | |
206 This is necessary for many reasons, one of which is that two | |
207 strings may match even if they have different numbers of bytes, | |
208 if IGNORE_CASE is true. */ | |
209 | |
210 Charcount | |
867 | 211 scmp_1 (const Ibyte *s1, const Ibyte *s2, Charcount len, |
428 | 212 int ignore_case) |
213 { | |
214 Charcount l = len; | |
215 | |
216 if (ignore_case) | |
217 { | |
218 while (l) | |
219 { | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
220 Ichar c1 = CANONCASE (0, itext_ichar (s1)); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
221 Ichar c2 = CANONCASE (0, itext_ichar (s2)); |
428 | 222 |
223 if (c1 == c2) | |
224 { | |
225 l--; | |
867 | 226 INC_IBYTEPTR (s1); |
227 INC_IBYTEPTR (s2); | |
428 | 228 } |
229 else | |
230 break; | |
231 } | |
232 } | |
233 else | |
234 { | |
867 | 235 while (l && itext_ichar (s1) == itext_ichar (s2)) |
428 | 236 { |
237 l--; | |
867 | 238 INC_IBYTEPTR (s1); |
239 INC_IBYTEPTR (s2); | |
428 | 240 } |
241 } | |
242 | |
243 if (l == 0) | |
244 return -1; | |
245 else return len - l; | |
246 } | |
247 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
248 /* Map FUNCTION, a C function, across LISZT, a pseudo-alist, calling |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
249 it with three args, ELTSTRING (the car of the element if a cons, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
250 otherwise the element itself), ELT (the element, always) and |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
251 EXTRA_ARG. Stop if FUNCTION returns non-zero. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
252 static void |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
253 map_completion_list (maphash_function_t function, Lisp_Object liszt, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
254 void *extra_arg) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
255 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
256 Lisp_Object eltstring; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
257 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
258 GC_EXTERNAL_LIST_LOOP_2 (elt, liszt) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
259 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
260 eltstring = CONSP (elt) ? XCAR (elt) : elt; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
261 if (function (eltstring, elt, extra_arg)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
262 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
263 XUNGCPRO (elt); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
264 return; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
265 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
266 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
267 END_GC_EXTERNAL_LIST_LOOP (elt); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
268 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
269 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
270 static void |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
271 map_completion (maphash_function_t function, Lisp_Object collection, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
272 void *extra_arg, Lisp_Object predicate) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
273 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
274 if (LISTP (collection)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
275 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
276 map_completion_list (function, collection, extra_arg); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
277 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
278 else if (VECTORP (collection)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
279 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
280 map_obarray (collection, function, extra_arg); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
281 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
282 else if (NILP (predicate)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
283 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
284 /* This can't call Lisp, no need to copy and compress the hash |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
285 table entries. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
286 elisp_maphash_unsafe (function, collection, extra_arg); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
287 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
288 else |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
289 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
290 elisp_maphash (function, collection, extra_arg); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
291 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
292 } |
428 | 293 |
294 int | |
867 | 295 regexp_ignore_completion_p (const Ibyte *nonreloc, |
428 | 296 Lisp_Object reloc, Bytecount offset, |
297 Bytecount length) | |
298 { | |
299 /* Ignore this element if it fails to match all the regexps. */ | |
300 if (!NILP (Vcompletion_regexp_list)) | |
301 { | |
2367 | 302 EXTERNAL_LIST_LOOP_2 (re, Vcompletion_regexp_list) |
428 | 303 { |
304 CHECK_STRING (re); | |
305 if (fast_string_match (re, nonreloc, reloc, offset, | |
306 length, 0, ERROR_ME, 0) < 0) | |
307 return 1; | |
308 } | |
309 } | |
310 return 0; | |
311 } | |
312 | |
313 /* Callers should GCPRO, since this may call eval */ | |
314 static int | |
315 ignore_completion_p (Lisp_Object completion_string, | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
316 Lisp_Object pred, Lisp_Object completion, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
317 Boolint hash_tablep) |
428 | 318 { |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
319 Lisp_Object tem; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
320 |
428 | 321 if (regexp_ignore_completion_p (0, completion_string, 0, -1)) |
322 return 1; | |
323 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
324 if (NILP (pred)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
325 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
326 return 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
327 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
328 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
329 /* Ignore this element if there is a predicate and the predicate doesn't |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
330 like it. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
331 if (hash_tablep) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
332 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
333 tem = call2 (pred, completion_string, completion); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
334 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
335 else if (EQ (pred, Qcommandp)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
336 { |
428 | 337 tem = Fcommandp (completion); |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
338 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
339 else |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
340 { |
428 | 341 tem = call1 (pred, completion); |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
342 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
343 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
344 return NILP (tem); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
345 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
346 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
347 struct try_completion_closure |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
348 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
349 Lisp_Object string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
350 Charcount slength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
351 Lisp_Object predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
352 Lisp_Object bestmatch; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
353 Charcount blength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
354 Charcount bestmatchsize; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
355 Boolint hash_tablep; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
356 int matchcount; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
357 }; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
358 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
359 static int |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
360 try_completion_mapper (Lisp_Object eltstring, Lisp_Object value, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
361 void *arg) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
362 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
363 struct try_completion_closure *tcc = (struct try_completion_closure *) arg; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
364 Charcount eltlength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
365 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
366 if (SYMBOLP (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
367 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
368 eltstring = XSYMBOL_NAME (eltstring); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
369 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
370 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
371 if (!STRINGP (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
372 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
373 return 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
374 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
375 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
376 /* Is this element a possible completion? */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
377 eltlength = string_char_length (eltstring); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
378 if (tcc->slength <= eltlength |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
379 && (0 > scmp (XSTRING_DATA (eltstring), XSTRING_DATA (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
380 tcc->slength))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
381 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
382 struct gcpro gcpro1, gcpro2, gcpro3; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
383 int loser; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
384 GCPRO3 (tcc->string, eltstring, tcc->bestmatch); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
385 loser = ignore_completion_p (eltstring, tcc->predicate, value, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
386 tcc->hash_tablep); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
387 UNGCPRO; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
388 if (loser) /* reject this one */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
389 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
390 return 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
391 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
392 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
393 /* Update computation of how much all possible completions |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
394 match */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
395 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
396 tcc->matchcount++; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
397 if (NILP (tcc->bestmatch)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
398 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
399 tcc->bestmatch = eltstring; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
400 tcc->blength = eltlength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
401 tcc->bestmatchsize = eltlength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
402 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
403 else |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
404 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
405 Charcount compare = min (tcc->bestmatchsize, eltlength); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
406 Charcount matchsize = |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
407 scmp (XSTRING_DATA (tcc->bestmatch), XSTRING_DATA (eltstring), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
408 compare); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
409 if (matchsize < 0) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
410 matchsize = compare; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
411 if (completion_ignore_case) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
412 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
413 /* If this is an exact match except for case, use it as |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
414 the best match rather than one that is not an exact |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
415 match. This way, we get the case pattern of the |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
416 actual match. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
417 if ((matchsize == eltlength |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
418 && matchsize < tcc->blength) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
419 || |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
420 /* If there is more than one exact match ignoring |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
421 case, and one of them is exact including case, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
422 prefer that one. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
423 /* If there is no exact match ignoring case, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
424 prefer a match that does not change the case of |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
425 the input. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
426 ((matchsize == eltlength) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
427 == |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
428 (matchsize == tcc->blength) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
429 && 0 > scmp_1 (XSTRING_DATA (eltstring), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
430 XSTRING_DATA (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
431 tcc->slength, 0) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
432 && 0 <= scmp_1 (XSTRING_DATA (tcc->bestmatch), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
433 XSTRING_DATA (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
434 tcc->slength, 0))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
435 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
436 tcc->bestmatch = eltstring; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
437 tcc->blength = eltlength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
438 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
439 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
440 tcc->bestmatchsize = matchsize; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
441 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
442 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
443 |
428 | 444 return 0; |
445 } | |
446 | |
447 DEFUN ("try-completion", Ftry_completion, 2, 3, 0, /* | |
444 | 448 Return common substring of all completions of STRING in COLLECTION. |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
449 COLLECTION must be a list, a hash table, an obarray, or a function. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
450 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
451 Each string (or symbol) in COLLECTION is tested to see if it (or its |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
452 name) begins with STRING. All that match are compared together; the |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
453 longest initial sequence common to all matches is returned as a |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
454 string. If there is no match at all, nil is returned. For an exact |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
455 match, t is returned. |
428 | 456 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
457 If COLLECTION is a list, the elements of the list that are not cons |
4704
44c9d1005ce2
Bring `try-completion''s interface closer to GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
2367
diff
changeset
|
458 cells and the cars of the elements of the list that are cons cells |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
459 \(which must be strings or symbols) form the set of possible |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
460 completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
461 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
462 If COLLECTION is a hash table, all the keys that are strings or symbols |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
463 are the possible completions. |
428 | 464 |
444 | 465 If COLLECTION is an obarray, the names of all symbols in the obarray |
466 are the possible completions. | |
467 | |
468 If COLLECTION is a function, it is called with three arguments: the | |
469 values STRING, PREDICATE and nil. Whatever it returns becomes the | |
470 value of `try-completion'. | |
428 | 471 |
444 | 472 If optional third argument PREDICATE is non-nil, it is used to test |
473 each possible match. The match is a candidate only if PREDICATE | |
474 returns non-nil. The argument given to PREDICATE is the alist element | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
475 or the symbol from the obarray. If COLLECTION is a hash table, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
476 PREDICATE is passed two arguments, the key and the value of the hash |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
477 table entry. |
428 | 478 */ |
444 | 479 (string, collection, predicate)) |
428 | 480 { |
481 /* This function can GC */ | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
482 struct try_completion_closure tcc; |
428 | 483 |
484 CHECK_STRING (string); | |
485 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
486 if (!NILP (Ffunctionp (collection))) |
428 | 487 { |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
488 return call3 (collection, string, predicate, Qnil); |
428 | 489 } |
490 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
491 if (!(LISTP (collection) || VECTORP (collection) || HASH_TABLEP (collection))) |
428 | 492 { |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
493 signal_error (Qwrong_type_argument, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
494 "must be a list, vector, hash table or function", |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
495 collection); |
428 | 496 } |
497 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
498 tcc.string = string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
499 tcc.slength = string_char_length (string); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
500 tcc.bestmatch = Qnil; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
501 tcc.blength = 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
502 tcc.bestmatchsize = 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
503 tcc.predicate = predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
504 tcc.hash_tablep = HASH_TABLEP (collection); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
505 tcc.matchcount = 0; |
428 | 506 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
507 map_completion (try_completion_mapper, collection, &tcc, predicate); |
428 | 508 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
509 if (NILP (tcc.bestmatch)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
510 return Qnil; /* No completions found */ |
428 | 511 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
512 /* If we are ignoring case, and there is no exact match, and no |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
513 additional text was supplied, don't change the case of what the |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
514 user typed. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
515 if (completion_ignore_case && tcc.bestmatchsize == tcc.slength |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
516 && tcc.blength > tcc.bestmatchsize) |
428 | 517 return string; |
518 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
519 /* Return t if the supplied string is an exact match (counting |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
520 case); it does not require any change to be made. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
521 if (tcc.matchcount == 1 && tcc.bestmatchsize == tcc.slength |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
522 && 0 > scmp_1 (XSTRING_DATA (tcc.bestmatch), XSTRING_DATA (tcc.string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
523 tcc.bestmatchsize, 0)) |
428 | 524 return Qt; |
525 | |
526 /* Else extract the part in which all completions agree */ | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
527 return Fsubseq (tcc.bestmatch, Qzero, make_fixnum (tcc.bestmatchsize)); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
528 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
529 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
530 struct all_completions_closure |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
531 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
532 Lisp_Object string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
533 Charcount slength; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
534 Lisp_Object predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
535 Lisp_Object allmatches; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
536 Boolint hash_tablep; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
537 }; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
538 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
539 static int |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
540 all_completions_mapper (Lisp_Object eltstring, Lisp_Object value, void *arg) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
541 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
542 struct all_completions_closure *acc = (struct all_completions_closure *) arg; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
543 /* Is this element a possible completion? */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
544 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
545 if (SYMBOLP (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
546 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
547 eltstring = XSYMBOL_NAME (eltstring); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
548 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
549 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
550 if (STRINGP (eltstring) && (acc->slength <= string_char_length (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
551 /* Reject alternatives that start with space unless the input |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
552 starts with space. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
553 && ((acc->slength > 0 && string_ichar (acc->string, 0) == ' ') |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
554 || string_ichar (eltstring, 0) != ' ') |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
555 && (0 > scmp (XSTRING_DATA (eltstring), XSTRING_DATA (acc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
556 acc->slength))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
557 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
558 /* Yes. Now check whether predicate likes it. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
559 struct gcpro gcpro1, gcpro2; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
560 int loser; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
561 GCPRO2 (eltstring, acc->string); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
562 loser = ignore_completion_p (eltstring, acc->predicate, value, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
563 acc->hash_tablep); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
564 UNGCPRO; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
565 if (!loser) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
566 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
567 /* Ok => put it on the list. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
568 XSETCDR (acc->allmatches, Fcons (eltstring, Qnil)); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
569 acc->allmatches = XCDR (acc->allmatches); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
570 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
571 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
572 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
573 return 0; |
428 | 574 } |
575 | |
576 DEFUN ("all-completions", Fall_completions, 2, 3, 0, /* | |
444 | 577 Search for partial matches to STRING in COLLECTION. |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
578 COLLECTION must be an list, a hash table, an obarray, or a function. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
579 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
580 Each string (or symbol) in COLLECTION is tested to see if it (or its |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
581 name) begins with STRING. The value is a list of all the strings from |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
582 COLLECTION that match. |
444 | 583 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
584 If COLLECTION is a list, the elements of the list that are not cons |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
585 cells and the cars of the elements of the list that are cons cells |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
586 \(which must be strings or symbols) form the set of possible |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
587 completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
588 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
589 If COLLECTION is a hash-table, all the keys that are strings or symbols |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
590 are the possible completions. |
444 | 591 |
592 If COLLECTION is an obarray, the names of all symbols in the obarray | |
593 are the possible completions. | |
428 | 594 |
444 | 595 If COLLECTION is a function, it is called with three arguments: the |
596 values STRING, PREDICATE and t. Whatever it returns becomes the | |
597 value of `all-completions'. | |
428 | 598 |
444 | 599 If optional third argument PREDICATE is non-nil, it is used to test |
600 each possible match. The match is a candidate only if PREDICATE | |
601 returns non-nil. The argument given to PREDICATE is the alist element | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
602 or the symbol from the obarray. If COLLECTION is a hash table, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
603 PREDICATE is passed two arguments, the key and the value of the hash |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
604 table entry. |
428 | 605 */ |
444 | 606 (string, collection, predicate)) |
428 | 607 { |
608 /* This function can GC */ | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
609 struct all_completions_closure acc; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
610 Lisp_Object allmatches = noseeum_cons (Qnil, Qnil); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
611 struct gcpro gcpro1; |
428 | 612 |
613 CHECK_STRING (string); | |
614 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
615 if (!NILP (Ffunctionp (collection))) |
428 | 616 { |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
617 return call3 (collection, string, predicate, Qt); |
428 | 618 } |
619 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
620 if (!(LISTP (collection) || VECTORP (collection) || HASH_TABLEP (collection))) |
428 | 621 { |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
622 signal_error (Qwrong_type_argument, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
623 "must be a list, vector, hash table or function", |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
624 collection); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
625 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
626 GCPRO1 (allmatches); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
627 acc.string = string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
628 acc.slength = string_char_length (string); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
629 acc.predicate = predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
630 acc.allmatches = allmatches; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
631 acc.hash_tablep = HASH_TABLEP (collection); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
632 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
633 map_completion (all_completions_mapper, collection, &acc, predicate); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
634 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
635 acc.allmatches = XCDR (allmatches); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
636 free_cons (allmatches); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
637 UNGCPRO; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
638 return acc.allmatches; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
639 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
640 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
641 struct test_completion_closure |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
642 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
643 Lisp_Object string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
644 Lisp_Object predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
645 Lisp_Object result; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
646 Boolint hash_tablep; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
647 }; |
428 | 648 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
649 static int |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
650 test_completion_mapper (Lisp_Object eltstring, Lisp_Object value, void *arg) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
651 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
652 struct test_completion_closure *tcc = (struct test_completion_closure *) arg; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
653 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
654 if (SYMBOLP (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
655 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
656 eltstring = XSYMBOL_NAME (eltstring); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
657 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
658 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
659 if (!STRINGP (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
660 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
661 return 0; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
662 } |
428 | 663 |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
664 if (completion_ignore_case ? |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
665 0 == qxetextcasecmp (XSTRING_DATA (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
666 XSTRING_LENGTH (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
667 XSTRING_DATA (eltstring), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
668 XSTRING_LENGTH (eltstring)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
669 : 0 == qxememcmp4 (XSTRING_DATA (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
670 XSTRING_LENGTH (tcc->string), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
671 XSTRING_DATA (eltstring), |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
672 XSTRING_LENGTH (eltstring))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
673 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
674 struct gcpro gcpro1, gcpro2, gcpro3; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
675 int loser; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
676 GCPRO3 (eltstring, tcc->string, tcc->predicate); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
677 loser = ignore_completion_p (eltstring, tcc->predicate, value, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
678 tcc->hash_tablep); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
679 UNGCPRO; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
680 if (!loser) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
681 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
682 tcc->result = Qt; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
683 return 1; |
428 | 684 } |
685 } | |
686 | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
687 return 0; |
428 | 688 } |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
689 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
690 DEFUN ("test-completion", Ftest_completion, 2, 3, 0, /* |
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
691 Return non-nil if STRING is an exact completion in COLLECTION. |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
692 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
693 COLLECTION must be a list, a hash table, an obarray, or a function. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
694 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
695 Each string (or symbol) in COLLECTION is tested to see if it (or its |
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
696 name) begins with STRING, until a valid, exact completion is found. |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
697 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
698 If COLLECTION is a list, the elements of the list that are not cons |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
699 cells and the cars of the elements of the list that are cons cells |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
700 \(which must be strings or symbols) form the set of possible |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
701 completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
702 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
703 If COLLECTION is a hash-table, all the keys that are strings or symbols |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
704 are the possible completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
705 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
706 If COLLECTION is an obarray, the names of all symbols in the obarray |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
707 are the possible completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
708 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
709 If COLLECTION is a function, it is called with three arguments: the |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
710 values STRING, PREDICATE and the symbol `lambda'. Whatever it returns |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
711 is passed back by `test-completion'. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
712 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
713 If optional third argument PREDICATE is non-nil, it is used to test |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
714 for possible matches. The match is a candidate only if PREDICATE |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
715 returns non-nil. The argument given to PREDICATE is the alist element |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
716 or the symbol from the obarray. If COLLECTION is a hash table, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
717 PREDICATE is passed two arguments, the key and the value of the hash |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
718 table entry. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
719 */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
720 (string, collection, predicate)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
721 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
722 struct test_completion_closure tcc; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
723 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
724 CHECK_STRING (string); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
725 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
726 if (!NILP (Ffunctionp (collection))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
727 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
728 return call3 (collection, string, predicate, Qlambda); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
729 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
730 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
731 if (!(LISTP (collection) || VECTORP (collection) || HASH_TABLEP (collection))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
732 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
733 signal_error (Qwrong_type_argument, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
734 "must be a list, vector, hash table or function", |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
735 collection); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
736 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
737 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
738 tcc.string = string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
739 tcc.predicate = predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
740 tcc.result = Qnil; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
741 tcc.hash_tablep = HASH_TABLEP (collection); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
742 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
743 if (VECTORP (collection) && !completion_ignore_case) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
744 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
745 /* We're case sensitive -> no need for a linear search. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
746 Lisp_Object lookup = Fintern_soft (string, collection, Qzero); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
747 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
748 if (ZEROP (lookup)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
749 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
750 return Qnil; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
751 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
752 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
753 return ignore_completion_p (XSYMBOL_NAME (lookup), tcc.predicate, |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
754 lookup, 0) ? Qnil : Qt; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
755 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
756 /* It would be reasonable to do something similar for the hash |
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
757 tables, except, both symbol and string keys are valid |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
758 completions there. So a negative #'gethash for the string |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
759 (with #'equal as the hash table tests) still means you have |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
760 to do the linear search, for any symbols with that string |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
761 name, which hash very differently; returning t is a little |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
762 quicker, but returning nil is just as slow, so our average |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
763 performance barely changes, at the cost of code |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
764 complexity. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
765 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
766 else |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
767 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
768 map_completion (test_completion_mapper, collection, &tcc, predicate); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
769 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
770 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
771 return tcc.result; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
772 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
773 |
428 | 774 |
775 /* Useless FSFmacs functions */ | |
776 /* More than useless. I've nuked minibuf_prompt_width so they won't | |
777 function at all in XEmacs at the moment. They are used to | |
778 implement some braindamage in FSF which we aren't including. --cet */ | |
779 | |
780 #if 0 | |
826 | 781 DEFUN ("minibuffer-prompt", Fminibuffer_prompt, 0, 0, 0, /* |
428 | 782 Return the prompt string of the currently-active minibuffer. |
783 If no minibuffer is active, return nil. | |
784 */ | |
785 ()) | |
786 { | |
787 return Fcopy_sequence (Vminibuf_prompt); | |
788 } | |
789 | |
826 | 790 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width, 0, 0, 0, /* |
428 | 791 Return the display width of the minibuffer prompt. |
792 */ | |
793 ()) | |
794 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
795 return make_fixnum (minibuf_prompt_width); |
428 | 796 } |
797 #endif /* 0 */ | |
798 | |
799 | |
800 /************************************************************************/ | |
801 /* echo area */ | |
802 /************************************************************************/ | |
803 | |
804 extern int stdout_needs_newline; | |
805 | |
806 static Lisp_Object | |
807 clear_echo_area_internal (struct frame *f, Lisp_Object label, int from_print, | |
808 int no_restore) | |
809 { | |
810 /* This function can call lisp */ | |
811 if (!NILP (Ffboundp (Qclear_message))) | |
812 { | |
793 | 813 Lisp_Object frame = wrap_frame (f); |
428 | 814 |
815 return call4 (Qclear_message, label, frame, from_print ? Qt : Qnil, | |
816 no_restore ? Qt : Qnil); | |
817 } | |
818 else | |
819 { | |
771 | 820 stderr_out ("\n"); |
428 | 821 return Qnil; |
822 } | |
823 } | |
824 | |
825 Lisp_Object | |
826 clear_echo_area (struct frame *f, Lisp_Object label, int no_restore) | |
827 { | |
828 /* This function can call lisp */ | |
829 return clear_echo_area_internal (f, label, 0, no_restore); | |
830 } | |
831 | |
832 Lisp_Object | |
833 clear_echo_area_from_print (struct frame *f, Lisp_Object label, int no_restore) | |
834 { | |
835 /* This function can call lisp */ | |
836 return clear_echo_area_internal (f, label, 1, no_restore); | |
837 } | |
838 | |
839 void | |
867 | 840 echo_area_append (struct frame *f, const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 841 Bytecount offset, Bytecount length, |
842 Lisp_Object label) | |
843 { | |
844 /* This function can call lisp */ | |
845 Lisp_Object obj; | |
846 struct gcpro gcpro1; | |
847 Lisp_Object frame; | |
848 | |
440 | 849 /* There is an inlining bug in egcs-20000131 c++ that can be worked |
850 around as follows: */ | |
851 #if defined (__GNUC__) && defined (__cplusplus) | |
852 alloca (4); | |
853 #endif | |
854 | |
428 | 855 /* some callers pass in a null string as a way of clearing the echo area. |
856 check for length == 0 now; if this case, neither nonreloc nor reloc | |
857 may be valid. */ | |
858 if (length == 0) | |
859 return; | |
860 | |
861 fixup_internal_substring (nonreloc, reloc, offset, &length); | |
862 | |
863 /* also check it here, in case the string was really blank. */ | |
864 if (length == 0) | |
865 return; | |
866 | |
867 if (!NILP (Ffboundp (Qappend_message))) | |
868 { | |
869 if (STRINGP (reloc) && offset == 0 && length == XSTRING_LENGTH (reloc)) | |
870 obj = reloc; | |
871 else | |
872 { | |
873 if (STRINGP (reloc)) | |
874 nonreloc = XSTRING_DATA (reloc); | |
875 obj = make_string (nonreloc + offset, length); | |
876 } | |
877 | |
793 | 878 frame = wrap_frame (f); |
428 | 879 GCPRO1 (obj); |
880 call4 (Qappend_message, label, obj, frame, | |
881 EQ (label, Qprint) ? Qt : Qnil); | |
882 UNGCPRO; | |
883 } | |
884 else | |
885 { | |
886 if (STRINGP (reloc)) | |
887 nonreloc = XSTRING_DATA (reloc); | |
826 | 888 write_string_1 (Qexternal_debugging_output, nonreloc + offset, length); |
428 | 889 } |
890 } | |
891 | |
892 void | |
867 | 893 echo_area_message (struct frame *f, const Ibyte *nonreloc, |
428 | 894 Lisp_Object reloc, Bytecount offset, Bytecount length, |
895 Lisp_Object label) | |
896 { | |
897 /* This function can call lisp */ | |
898 clear_echo_area (f, label, 1); | |
899 echo_area_append (f, nonreloc, reloc, offset, length, label); | |
900 } | |
901 | |
902 int | |
2286 | 903 echo_area_active (struct frame *UNUSED (f)) |
428 | 904 { |
905 /* By definition, the echo area is active if the echo-area buffer | |
906 is not empty. No need to call Lisp code. (Anyway, this function | |
907 is called from redisplay.) */ | |
908 struct buffer *echo_buffer = XBUFFER (Vecho_area_buffer); | |
909 return BUF_BEGV (echo_buffer) != BUF_ZV (echo_buffer); | |
910 } | |
911 | |
912 Lisp_Object | |
913 echo_area_status (struct frame *f) | |
914 { | |
915 /* This function can call lisp */ | |
916 if (!NILP (Ffboundp (Qcurrent_message_label))) | |
917 { | |
793 | 918 Lisp_Object frame = wrap_frame (f); |
428 | 919 |
920 return call1 (Qcurrent_message_label, frame); | |
921 } | |
922 else | |
923 return stdout_needs_newline ? Qmessage : Qnil; | |
924 } | |
925 | |
926 Lisp_Object | |
2286 | 927 echo_area_contents (struct frame *UNUSED (f)) |
428 | 928 { |
929 /* See above. By definition, the contents of the echo-area buffer | |
930 are the contents of the echo area. */ | |
931 return Fbuffer_substring (Qnil, Qnil, Vecho_area_buffer); | |
932 } | |
933 | |
934 /* Dump an informative message to the echo area. This function takes a | |
935 string in internal format. */ | |
936 void | |
867 | 937 message_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 938 Bytecount offset, Bytecount length) |
939 { | |
940 /* This function can call lisp */ | |
941 if (NILP (Vexecuting_macro)) | |
942 echo_area_message (selected_frame (), nonreloc, reloc, offset, length, | |
943 Qmessage); | |
944 } | |
945 | |
946 void | |
867 | 947 message_append_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 948 Bytecount offset, Bytecount length) |
949 { | |
950 /* This function can call lisp */ | |
951 if (NILP (Vexecuting_macro)) | |
952 echo_area_append (selected_frame (), nonreloc, reloc, offset, length, | |
953 Qmessage); | |
954 } | |
955 | |
956 /* The next three functions are interfaces to message_internal() that | |
957 take strings in external format. message() does I18N3 translating | |
958 on the format string; message_no_translate() does not. */ | |
959 | |
960 static void | |
867 | 961 message_1 (const CIbyte *fmt, va_list args) |
428 | 962 { |
963 /* This function can call lisp */ | |
964 if (fmt) | |
965 { | |
966 struct gcpro gcpro1; | |
967 /* message_internal() might GC, e.g. if there are after-change-hooks | |
968 on the echo area buffer */ | |
771 | 969 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
428 | 970 GCPRO1 (obj); |
971 message_internal (0, obj, 0, -1); | |
972 UNGCPRO; | |
973 } | |
974 else | |
975 message_internal (0, Qnil, 0, 0); | |
976 } | |
977 | |
978 static void | |
867 | 979 message_append_1 (const CIbyte *fmt, va_list args) |
428 | 980 { |
981 /* This function can call lisp */ | |
982 if (fmt) | |
983 { | |
984 struct gcpro gcpro1; | |
985 /* message_internal() might GC, e.g. if there are after-change-hooks | |
986 on the echo area buffer */ | |
771 | 987 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
428 | 988 GCPRO1 (obj); |
989 message_append_internal (0, obj, 0, -1); | |
990 UNGCPRO; | |
991 } | |
992 else | |
993 message_append_internal (0, Qnil, 0, 0); | |
994 } | |
995 | |
996 void | |
997 clear_message (void) | |
998 { | |
999 /* This function can call lisp */ | |
1000 message_internal (0, Qnil, 0, 0); | |
1001 } | |
1002 | |
1003 void | |
442 | 1004 message (const char *fmt, ...) |
428 | 1005 { |
1006 /* This function can call lisp */ | |
1007 /* I think it's OK to pass the data of Lisp strings as arguments to | |
1008 this function. No GC'ing will occur until the data has already | |
1009 been copied. */ | |
1010 va_list args; | |
1011 | |
1012 va_start (args, fmt); | |
1013 if (fmt) | |
1014 fmt = GETTEXT (fmt); | |
1015 message_1 (fmt, args); | |
1016 va_end (args); | |
1017 } | |
1018 | |
1019 void | |
442 | 1020 message_append (const char *fmt, ...) |
428 | 1021 { |
1022 /* This function can call lisp */ | |
1023 va_list args; | |
1024 | |
1025 va_start (args, fmt); | |
1026 if (fmt) | |
1027 fmt = GETTEXT (fmt); | |
1028 message_append_1 (fmt, args); | |
1029 va_end (args); | |
1030 } | |
1031 | |
1032 void | |
442 | 1033 message_no_translate (const char *fmt, ...) |
428 | 1034 { |
1035 /* This function can call lisp */ | |
1036 /* I think it's OK to pass the data of Lisp strings as arguments to | |
1037 this function. No GC'ing will occur until the data has already | |
1038 been copied. */ | |
1039 va_list args; | |
1040 | |
1041 va_start (args, fmt); | |
1042 message_1 (fmt, args); | |
1043 va_end (args); | |
1044 } | |
1045 | |
1046 | |
1047 /************************************************************************/ | |
1048 /* initialization */ | |
1049 /************************************************************************/ | |
1050 | |
1051 void | |
1052 syms_of_minibuf (void) | |
1053 { | |
563 | 1054 DEFSYMBOL (Qminibuffer_setup_hook); |
428 | 1055 |
563 | 1056 DEFSYMBOL (Qcompletion_ignore_case); |
428 | 1057 |
1058 DEFSUBR (Fminibuffer_depth); | |
1059 #if 0 | |
1060 DEFSUBR (Fminibuffer_prompt); | |
1061 DEFSUBR (Fminibuffer_prompt_width); | |
1062 #endif | |
1063 DEFSUBR (Fset_minibuffer_preprompt); | |
1064 DEFSUBR (Fread_minibuffer_internal); | |
1065 | |
1066 DEFSUBR (Ftry_completion); | |
1067 DEFSUBR (Fall_completions); | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
1068 DEFSUBR (Ftest_completion); |
428 | 1069 |
563 | 1070 DEFSYMBOL (Qappend_message); |
1071 DEFSYMBOL (Qclear_message); | |
1072 DEFSYMBOL (Qdisplay_message); | |
1073 DEFSYMBOL (Qcurrent_message_label); | |
428 | 1074 } |
1075 | |
1076 void | |
1077 reinit_vars_of_minibuf (void) | |
1078 { | |
1079 minibuf_level = 0; | |
1080 } | |
1081 | |
1082 void | |
1083 vars_of_minibuf (void) | |
1084 { | |
1085 staticpro (&Vminibuf_prompt); | |
1086 Vminibuf_prompt = Qnil; | |
1087 | |
1088 /* Added by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */ | |
1089 staticpro (&Vminibuf_preprompt); | |
1090 Vminibuf_preprompt = Qnil; | |
1091 | |
1092 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook /* | |
1093 Normal hook run just after entry to minibuffer. | |
1094 */ ); | |
1095 Vminibuffer_setup_hook = Qnil; | |
1096 | |
1097 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case /* | |
1098 Non-nil means don't consider case significant in completion. | |
1099 */ ); | |
1100 completion_ignore_case = 0; | |
1101 | |
1102 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list /* | |
1103 List of regexps that should restrict possible completions. | |
1104 Each completion has to match all regexps in this list. | |
1105 */ ); | |
1106 Vcompletion_regexp_list = Qnil; | |
1107 } | |
1108 | |
1109 void | |
1110 reinit_complex_vars_of_minibuf (void) | |
1111 { | |
1112 /* This function can GC */ | |
1113 #ifdef I18N3 | |
1114 /* #### This needs to be fixed up so that the gettext() gets called | |
1115 at runtime instead of at load time. */ | |
1116 #endif | |
1117 Vminibuffer_zero | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1118 = Fget_buffer_create (build_ascstring (" *Minibuf-0*")); |
5139
a48ef26d87ee
Clean up prototypes for Lisp variables/symbols. Put decls for them with
Ben Wing <ben@xemacs.org>
parents:
5089
diff
changeset
|
1119 staticpro_nodump (&Vminibuffer_zero); |
428 | 1120 Vecho_area_buffer |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1121 = Fget_buffer_create (build_ascstring (" *Echo Area*")); |
5139
a48ef26d87ee
Clean up prototypes for Lisp variables/symbols. Put decls for them with
Ben Wing <ben@xemacs.org>
parents:
5089
diff
changeset
|
1122 staticpro_nodump (&Vecho_area_buffer); |
428 | 1123 } |
1124 | |
1125 void | |
1126 complex_vars_of_minibuf (void) | |
1127 { | |
1128 reinit_complex_vars_of_minibuf (); | |
1129 } |