Mercurial > hg > xemacs-beta
annotate src/minibuf.c @ 5652:cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
lisp/ChangeLog addition:
2012-05-01 Aidan Kehoe <kehoea@parhasard.net>
Avoid #'delq in core code, for the sake of style and a (very
slightly) smaller binary.
* behavior.el (disable-behavior):
* behavior.el (compute-behavior-group-children):
* buff-menu.el (buffers-tab-items):
* byte-optimize.el (byte-optimize-delay-constants-math):
* byte-optimize.el (byte-optimize-logmumble):
* byte-optimize.el (byte-decompile-bytecode-1):
* byte-optimize.el (byte-optimize-lapcode):
* bytecomp.el:
* bytecomp.el (byte-compile-arglist-warn):
* bytecomp.el (byte-compile-warn-about-unresolved-functions):
* bytecomp.el (byte-compile-lambda):
* bytecomp.el (byte-compile-out-toplevel):
* bytecomp.el (byte-compile-insert):
* bytecomp.el (byte-compile-defalias-warn):
* cl-macs.el (cl-upcase-arg):
* cl-macs.el (cl-transform-lambda):
* cl-macs.el (cl-do-proclaim):
* cl-macs.el (defstruct):
* cl-macs.el (cl-make-type-test):
* cl-macs.el (define-compiler-macro):
* cl-macs.el (delete-duplicates):
* cus-edit.el (widget-face-value-delete):
* cus-edit.el (face-history):
* easymenu.el (easy-menu-remove):
* files.el (files-fetch-hook-value):
* files.el (file-expand-wildcards):
* font-lock.el (font-lock-update-removed-keyword-alist):
* font-lock.el (font-lock-remove-keywords):
* frame.el (frame-initialize):
* frame.el (frame-notice-user-settings):
* frame.el (set-frame-font):
* frame.el (delete-other-frames):
* frame.el (get-frame-for-buffer-noselect):
* gnuserv.el (gnuserv-kill-buffer-function):
* gnuserv.el (gnuserv-check-device):
* gnuserv.el (gnuserv-kill-client):
* gnuserv.el (gnuserv-buffer-done-1):
* gtk-font-menu.el (gtk-reset-device-font-menus):
* gutter-items.el (buffers-tab-items):
* gutter.el (set-gutter-element-visible-p):
* info.el (Info-find-file-node):
* info.el (Info-history-add):
* info.el (Info-build-annotation-completions):
* info.el (Info-index):
* info.el (Info-reannotate-node):
* itimer.el (delete-itimer):
* itimer.el (start-itimer):
* lib-complete.el (lib-complete:cache-completions):
* loadhist.el (unload-feature):
* menubar-items.el (build-buffers-menu-internal):
* menubar.el (delete-menu-item):
* menubar.el (relabel-menu-item):
* msw-font-menu.el (mswindows-reset-device-font-menus):
* mule/make-coding-system.el (fixed-width-generate-helper):
* next-error.el (next-error-find-buffer):
* obsolete.el:
* obsolete.el (find-non-ascii-charset-string):
* obsolete.el (find-non-ascii-charset-region):
* occur.el (multi-occur-by-filename-regexp):
* occur.el (occur-1):
* packages.el (packages-package-hierarchy-directory-names):
* packages.el (package-get-key-1):
* process.el (setenv):
* simple.el (undo):
* simple.el (handle-pre-motion-command-current-command-is-motion):
* sound.el (load-sound-file):
* wid-edit.el (widget-field-value-delete):
* wid-edit.el (widget-checklist-match-inline):
* wid-edit.el (widget-checklist-match-find):
* wid-edit.el (widget-editable-list-delete-at):
* wid-edit.el (widget-editable-list-entry-create):
* window.el (quit-window):
* x-font-menu.el (x-reset-device-font-menus-core):
1. Replace (delq nil (mapcar ....)) with analogous (mapcan ...)
forms; this is in non-dumped files, it was done previously in
dumped files.
2. Replace (delq FOO (copy-sequence BAR)) with (remove* FOO BAR),
where #'eq and #'eql are equivalent
3. Replace (delq FOO BAR) with (delete* FOO BAR), where FOO is not
a non-fixnum number. Saves a little space in the dumped file
(since the compiler macro adds :test #'eq to the delete* call if
it's not clear that FOO is not a non-fixnum number).
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 01 May 2012 16:17:42 +0100 |
parents | 2014ff433daf |
children | daf5accfe973 |
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, /* |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
691 Return non-nil if STRING is a valid completion in COLLECTION. |
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 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
696 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
|
697 COLLECTION that match. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
698 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
699 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
|
700 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
|
701 \(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
|
702 completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
703 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
704 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
|
705 are the possible completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
706 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
707 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
|
708 are the possible completions. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
709 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 table entry. |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
720 */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
721 (string, collection, predicate)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
722 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
723 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
|
724 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
725 CHECK_STRING (string); |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
726 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
727 if (!NILP (Ffunctionp (collection))) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
728 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
729 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
|
730 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
731 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
732 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
|
733 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
734 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
|
735 "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
|
736 collection); |
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 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
739 tcc.string = string; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
740 tcc.predicate = predicate; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
741 tcc.result = Qnil; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
742 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
|
743 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
744 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
|
745 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
746 /* 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
|
747 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
|
748 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
749 if (ZEROP (lookup)) |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
750 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
751 return Qnil; |
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 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
754 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
|
755 lookup, 0) ? Qnil : Qt; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
756 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
757 /* It would be reasonable to do something similar for the hash |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
758 tables, except, both symbol and string keys are vaild |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
759 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
|
760 (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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 complexity. */ |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
766 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
767 else |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
768 { |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
769 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
|
770 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
771 |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
772 return tcc.result; |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
773 } |
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
774 |
428 | 775 |
776 /* Useless FSFmacs functions */ | |
777 /* More than useless. I've nuked minibuf_prompt_width so they won't | |
778 function at all in XEmacs at the moment. They are used to | |
779 implement some braindamage in FSF which we aren't including. --cet */ | |
780 | |
781 #if 0 | |
826 | 782 DEFUN ("minibuffer-prompt", Fminibuffer_prompt, 0, 0, 0, /* |
428 | 783 Return the prompt string of the currently-active minibuffer. |
784 If no minibuffer is active, return nil. | |
785 */ | |
786 ()) | |
787 { | |
788 return Fcopy_sequence (Vminibuf_prompt); | |
789 } | |
790 | |
826 | 791 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width, 0, 0, 0, /* |
428 | 792 Return the display width of the minibuffer prompt. |
793 */ | |
794 ()) | |
795 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
796 return make_fixnum (minibuf_prompt_width); |
428 | 797 } |
798 #endif /* 0 */ | |
799 | |
800 | |
801 /************************************************************************/ | |
802 /* echo area */ | |
803 /************************************************************************/ | |
804 | |
805 extern int stdout_needs_newline; | |
806 | |
807 static Lisp_Object | |
808 clear_echo_area_internal (struct frame *f, Lisp_Object label, int from_print, | |
809 int no_restore) | |
810 { | |
811 /* This function can call lisp */ | |
812 if (!NILP (Ffboundp (Qclear_message))) | |
813 { | |
793 | 814 Lisp_Object frame = wrap_frame (f); |
428 | 815 |
816 return call4 (Qclear_message, label, frame, from_print ? Qt : Qnil, | |
817 no_restore ? Qt : Qnil); | |
818 } | |
819 else | |
820 { | |
771 | 821 stderr_out ("\n"); |
428 | 822 return Qnil; |
823 } | |
824 } | |
825 | |
826 Lisp_Object | |
827 clear_echo_area (struct frame *f, Lisp_Object label, int no_restore) | |
828 { | |
829 /* This function can call lisp */ | |
830 return clear_echo_area_internal (f, label, 0, no_restore); | |
831 } | |
832 | |
833 Lisp_Object | |
834 clear_echo_area_from_print (struct frame *f, Lisp_Object label, int no_restore) | |
835 { | |
836 /* This function can call lisp */ | |
837 return clear_echo_area_internal (f, label, 1, no_restore); | |
838 } | |
839 | |
840 void | |
867 | 841 echo_area_append (struct frame *f, const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 842 Bytecount offset, Bytecount length, |
843 Lisp_Object label) | |
844 { | |
845 /* This function can call lisp */ | |
846 Lisp_Object obj; | |
847 struct gcpro gcpro1; | |
848 Lisp_Object frame; | |
849 | |
440 | 850 /* There is an inlining bug in egcs-20000131 c++ that can be worked |
851 around as follows: */ | |
852 #if defined (__GNUC__) && defined (__cplusplus) | |
853 alloca (4); | |
854 #endif | |
855 | |
428 | 856 /* some callers pass in a null string as a way of clearing the echo area. |
857 check for length == 0 now; if this case, neither nonreloc nor reloc | |
858 may be valid. */ | |
859 if (length == 0) | |
860 return; | |
861 | |
862 fixup_internal_substring (nonreloc, reloc, offset, &length); | |
863 | |
864 /* also check it here, in case the string was really blank. */ | |
865 if (length == 0) | |
866 return; | |
867 | |
868 if (!NILP (Ffboundp (Qappend_message))) | |
869 { | |
870 if (STRINGP (reloc) && offset == 0 && length == XSTRING_LENGTH (reloc)) | |
871 obj = reloc; | |
872 else | |
873 { | |
874 if (STRINGP (reloc)) | |
875 nonreloc = XSTRING_DATA (reloc); | |
876 obj = make_string (nonreloc + offset, length); | |
877 } | |
878 | |
793 | 879 frame = wrap_frame (f); |
428 | 880 GCPRO1 (obj); |
881 call4 (Qappend_message, label, obj, frame, | |
882 EQ (label, Qprint) ? Qt : Qnil); | |
883 UNGCPRO; | |
884 } | |
885 else | |
886 { | |
887 if (STRINGP (reloc)) | |
888 nonreloc = XSTRING_DATA (reloc); | |
826 | 889 write_string_1 (Qexternal_debugging_output, nonreloc + offset, length); |
428 | 890 } |
891 } | |
892 | |
893 void | |
867 | 894 echo_area_message (struct frame *f, const Ibyte *nonreloc, |
428 | 895 Lisp_Object reloc, Bytecount offset, Bytecount length, |
896 Lisp_Object label) | |
897 { | |
898 /* This function can call lisp */ | |
899 clear_echo_area (f, label, 1); | |
900 echo_area_append (f, nonreloc, reloc, offset, length, label); | |
901 } | |
902 | |
903 int | |
2286 | 904 echo_area_active (struct frame *UNUSED (f)) |
428 | 905 { |
906 /* By definition, the echo area is active if the echo-area buffer | |
907 is not empty. No need to call Lisp code. (Anyway, this function | |
908 is called from redisplay.) */ | |
909 struct buffer *echo_buffer = XBUFFER (Vecho_area_buffer); | |
910 return BUF_BEGV (echo_buffer) != BUF_ZV (echo_buffer); | |
911 } | |
912 | |
913 Lisp_Object | |
914 echo_area_status (struct frame *f) | |
915 { | |
916 /* This function can call lisp */ | |
917 if (!NILP (Ffboundp (Qcurrent_message_label))) | |
918 { | |
793 | 919 Lisp_Object frame = wrap_frame (f); |
428 | 920 |
921 return call1 (Qcurrent_message_label, frame); | |
922 } | |
923 else | |
924 return stdout_needs_newline ? Qmessage : Qnil; | |
925 } | |
926 | |
927 Lisp_Object | |
2286 | 928 echo_area_contents (struct frame *UNUSED (f)) |
428 | 929 { |
930 /* See above. By definition, the contents of the echo-area buffer | |
931 are the contents of the echo area. */ | |
932 return Fbuffer_substring (Qnil, Qnil, Vecho_area_buffer); | |
933 } | |
934 | |
935 /* Dump an informative message to the echo area. This function takes a | |
936 string in internal format. */ | |
937 void | |
867 | 938 message_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 939 Bytecount offset, Bytecount length) |
940 { | |
941 /* This function can call lisp */ | |
942 if (NILP (Vexecuting_macro)) | |
943 echo_area_message (selected_frame (), nonreloc, reloc, offset, length, | |
944 Qmessage); | |
945 } | |
946 | |
947 void | |
867 | 948 message_append_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
428 | 949 Bytecount offset, Bytecount length) |
950 { | |
951 /* This function can call lisp */ | |
952 if (NILP (Vexecuting_macro)) | |
953 echo_area_append (selected_frame (), nonreloc, reloc, offset, length, | |
954 Qmessage); | |
955 } | |
956 | |
957 /* The next three functions are interfaces to message_internal() that | |
958 take strings in external format. message() does I18N3 translating | |
959 on the format string; message_no_translate() does not. */ | |
960 | |
961 static void | |
867 | 962 message_1 (const CIbyte *fmt, va_list args) |
428 | 963 { |
964 /* This function can call lisp */ | |
965 if (fmt) | |
966 { | |
967 struct gcpro gcpro1; | |
968 /* message_internal() might GC, e.g. if there are after-change-hooks | |
969 on the echo area buffer */ | |
771 | 970 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
428 | 971 GCPRO1 (obj); |
972 message_internal (0, obj, 0, -1); | |
973 UNGCPRO; | |
974 } | |
975 else | |
976 message_internal (0, Qnil, 0, 0); | |
977 } | |
978 | |
979 static void | |
867 | 980 message_append_1 (const CIbyte *fmt, va_list args) |
428 | 981 { |
982 /* This function can call lisp */ | |
983 if (fmt) | |
984 { | |
985 struct gcpro gcpro1; | |
986 /* message_internal() might GC, e.g. if there are after-change-hooks | |
987 on the echo area buffer */ | |
771 | 988 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
428 | 989 GCPRO1 (obj); |
990 message_append_internal (0, obj, 0, -1); | |
991 UNGCPRO; | |
992 } | |
993 else | |
994 message_append_internal (0, Qnil, 0, 0); | |
995 } | |
996 | |
997 void | |
998 clear_message (void) | |
999 { | |
1000 /* This function can call lisp */ | |
1001 message_internal (0, Qnil, 0, 0); | |
1002 } | |
1003 | |
1004 void | |
442 | 1005 message (const char *fmt, ...) |
428 | 1006 { |
1007 /* This function can call lisp */ | |
1008 /* I think it's OK to pass the data of Lisp strings as arguments to | |
1009 this function. No GC'ing will occur until the data has already | |
1010 been copied. */ | |
1011 va_list args; | |
1012 | |
1013 va_start (args, fmt); | |
1014 if (fmt) | |
1015 fmt = GETTEXT (fmt); | |
1016 message_1 (fmt, args); | |
1017 va_end (args); | |
1018 } | |
1019 | |
1020 void | |
442 | 1021 message_append (const char *fmt, ...) |
428 | 1022 { |
1023 /* This function can call lisp */ | |
1024 va_list args; | |
1025 | |
1026 va_start (args, fmt); | |
1027 if (fmt) | |
1028 fmt = GETTEXT (fmt); | |
1029 message_append_1 (fmt, args); | |
1030 va_end (args); | |
1031 } | |
1032 | |
1033 void | |
442 | 1034 message_no_translate (const char *fmt, ...) |
428 | 1035 { |
1036 /* This function can call lisp */ | |
1037 /* I think it's OK to pass the data of Lisp strings as arguments to | |
1038 this function. No GC'ing will occur until the data has already | |
1039 been copied. */ | |
1040 va_list args; | |
1041 | |
1042 va_start (args, fmt); | |
1043 message_1 (fmt, args); | |
1044 va_end (args); | |
1045 } | |
1046 | |
1047 | |
1048 /************************************************************************/ | |
1049 /* initialization */ | |
1050 /************************************************************************/ | |
1051 | |
1052 void | |
1053 syms_of_minibuf (void) | |
1054 { | |
563 | 1055 DEFSYMBOL (Qminibuffer_setup_hook); |
428 | 1056 |
563 | 1057 DEFSYMBOL (Qcompletion_ignore_case); |
428 | 1058 |
1059 DEFSUBR (Fminibuffer_depth); | |
1060 #if 0 | |
1061 DEFSUBR (Fminibuffer_prompt); | |
1062 DEFSUBR (Fminibuffer_prompt_width); | |
1063 #endif | |
1064 DEFSUBR (Fset_minibuffer_preprompt); | |
1065 DEFSUBR (Fread_minibuffer_internal); | |
1066 | |
1067 DEFSUBR (Ftry_completion); | |
1068 DEFSUBR (Fall_completions); | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
1069 DEFSUBR (Ftest_completion); |
428 | 1070 |
563 | 1071 DEFSYMBOL (Qappend_message); |
1072 DEFSYMBOL (Qclear_message); | |
1073 DEFSYMBOL (Qdisplay_message); | |
1074 DEFSYMBOL (Qcurrent_message_label); | |
428 | 1075 } |
1076 | |
1077 void | |
1078 reinit_vars_of_minibuf (void) | |
1079 { | |
1080 minibuf_level = 0; | |
1081 } | |
1082 | |
1083 void | |
1084 vars_of_minibuf (void) | |
1085 { | |
1086 staticpro (&Vminibuf_prompt); | |
1087 Vminibuf_prompt = Qnil; | |
1088 | |
1089 /* Added by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */ | |
1090 staticpro (&Vminibuf_preprompt); | |
1091 Vminibuf_preprompt = Qnil; | |
1092 | |
1093 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook /* | |
1094 Normal hook run just after entry to minibuffer. | |
1095 */ ); | |
1096 Vminibuffer_setup_hook = Qnil; | |
1097 | |
1098 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case /* | |
1099 Non-nil means don't consider case significant in completion. | |
1100 */ ); | |
1101 completion_ignore_case = 0; | |
1102 | |
1103 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list /* | |
1104 List of regexps that should restrict possible completions. | |
1105 Each completion has to match all regexps in this list. | |
1106 */ ); | |
1107 Vcompletion_regexp_list = Qnil; | |
1108 } | |
1109 | |
1110 void | |
1111 reinit_complex_vars_of_minibuf (void) | |
1112 { | |
1113 /* This function can GC */ | |
1114 #ifdef I18N3 | |
1115 /* #### This needs to be fixed up so that the gettext() gets called | |
1116 at runtime instead of at load time. */ | |
1117 #endif | |
1118 Vminibuffer_zero | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1119 = 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
|
1120 staticpro_nodump (&Vminibuffer_zero); |
428 | 1121 Vecho_area_buffer |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1122 = 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
|
1123 staticpro_nodump (&Vecho_area_buffer); |
428 | 1124 } |
1125 | |
1126 void | |
1127 complex_vars_of_minibuf (void) | |
1128 { | |
1129 reinit_complex_vars_of_minibuf (); | |
1130 } |