Mercurial > hg > xemacs-beta
annotate src/minibuf.c @ 5857:6ec4964c1687
Be more careful about echo_buf arithmetic, event-stream.c.
src/ChangeLog addition:
2015-03-12 Aidan Kehoe <kehoea@parhasard.net>
* event-stream.c (lookup_command_event):
Check whether echo_buf_fill_pointer is negative before using it in
arithmetic, avoiding a crash in GC.
Oddly the old code didn't do this check and didn't crash, but its
echo_buf was from malloced memory, not from our string data, so
there may have been more room to manoeuvre.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Thu, 12 Mar 2015 23:31:42 +0000 |
| parents | b79e1e02bf01 |
| children |
| 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" | |
|
5803
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
37 #include "text.h" |
| 872 | 38 #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
|
39 #include "elhash.h" |
| 428 | 40 |
| 41 /* Depth in minibuffer invocations. */ | |
| 42 int minibuf_level; | |
| 43 | |
| 44 Lisp_Object Qcompletion_ignore_case; | |
| 45 | |
| 46 /* Nonzero means completion ignores case. */ | |
| 47 int completion_ignore_case; | |
| 48 | |
| 49 /* List of regexps that should restrict possible completions. */ | |
| 50 Lisp_Object Vcompletion_regexp_list; | |
| 51 | |
| 52 /* The echo area buffer. */ | |
| 53 Lisp_Object Vecho_area_buffer; | |
| 54 | |
| 55 /* Prompt to display in front of the minibuffer contents */ | |
| 56 Lisp_Object Vminibuf_prompt; | |
| 57 | |
| 58 /* Added on 97/3/14 by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */ | |
| 59 /* String to be displayed in front of prompt of the minibuffer contents */ | |
| 60 Lisp_Object Vminibuf_preprompt; | |
| 61 | |
| 62 /* Hook to run just after entry to minibuffer. */ | |
| 63 Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook; | |
| 64 | |
| 65 Lisp_Object Qappend_message, Qcurrent_message_label, | |
| 66 Qclear_message, Qdisplay_message; | |
| 67 | |
| 68 | |
| 69 DEFUN ("minibuffer-depth", Fminibuffer_depth, 0, 0, 0, /* | |
| 70 Return current depth of activations of minibuffer, a nonnegative integer. | |
| 71 */ | |
| 72 ()) | |
| 73 { | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
74 return make_fixnum (minibuf_level); |
| 428 | 75 } |
| 76 | |
| 77 /* The default buffer to use as the window-buffer of minibuffer windows */ | |
| 78 /* Note there is special code in kill-buffer to make this unkillable */ | |
| 79 Lisp_Object Vminibuffer_zero; | |
| 80 | |
| 81 | |
| 82 /* Actual minibuffer invocation. */ | |
| 83 | |
| 84 static Lisp_Object | |
| 85 read_minibuffer_internal_unwind (Lisp_Object unwind_data) | |
| 86 { | |
| 87 Lisp_Object frame; | |
| 88 XWINDOW (minibuf_window)->last_modified[CURRENT_DISP] = Qzero; | |
| 89 XWINDOW (minibuf_window)->last_modified[DESIRED_DISP] = Qzero; | |
| 90 XWINDOW (minibuf_window)->last_modified[CMOTION_DISP] = Qzero; | |
| 91 XWINDOW (minibuf_window)->last_facechange[CURRENT_DISP] = Qzero; | |
| 92 XWINDOW (minibuf_window)->last_facechange[DESIRED_DISP] = Qzero; | |
| 93 XWINDOW (minibuf_window)->last_facechange[CMOTION_DISP] = Qzero; | |
| 94 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
|
95 minibuf_level = XFIXNUM (Felt (unwind_data, make_fixnum (1))); |
| 428 | 96 while (CONSP (unwind_data)) |
| 97 { | |
| 98 Lisp_Object victim = unwind_data; | |
| 99 unwind_data = XCDR (unwind_data); | |
| 853 | 100 free_cons (victim); |
| 428 | 101 } |
| 102 | |
| 103 /* If cursor is on the minibuffer line, | |
| 104 show the user we have exited by putting it in column 0. */ | |
| 105 frame = Fselected_frame (Qnil); | |
| 106 if (!noninteractive | |
| 107 && !NILP (frame) | |
| 108 && !NILP (XFRAME (frame)->minibuffer_window)) | |
| 109 { | |
| 110 struct window *w = XWINDOW (XFRAME (frame)->minibuffer_window); | |
| 111 redisplay_move_cursor (w, 0, 0); | |
| 112 } | |
| 113 | |
| 114 return Qnil; | |
| 115 } | |
| 116 | |
| 117 /* 97/4/13 jhod: Added for input methods */ | |
| 118 DEFUN ("set-minibuffer-preprompt", Fset_minibuffer_preprompt, 1, 1, 0, /* | |
| 119 Set the minibuffer preprompt string to PREPROMPT. This is used by language | |
| 120 input methods to relay state information to the user. | |
| 121 */ | |
| 122 (preprompt)) | |
| 123 { | |
| 124 if (NILP (preprompt)) | |
| 125 { | |
| 126 Vminibuf_preprompt = Qnil; | |
| 127 } | |
| 128 else | |
| 129 { | |
| 130 CHECK_STRING (preprompt); | |
| 131 | |
| 132 Vminibuf_preprompt = LISP_GETTEXT (preprompt); | |
| 133 } | |
| 134 return Qnil; | |
| 135 } | |
| 136 | |
| 2268 | 137 DEFUN_NORETURN ("read-minibuffer-internal", Fread_minibuffer_internal, |
| 138 1, 1, 0, /* | |
| 428 | 139 Lowest-level interface to minibuffers. Don't call this. |
| 140 */ | |
| 141 (prompt)) | |
| 142 { | |
| 143 /* This function can GC */ | |
| 2268 | 144 |
| 145 /* We used to record the specpdl_depth here, but since call_command_loop | |
| 146 never returns, we can never call unbind_to_1. Since we exit via a throw, | |
| 147 we let whoever catches unbind for us. */ | |
| 148 | |
| 428 | 149 CHECK_STRING (prompt); |
| 150 | |
| 151 single_console_state (); | |
| 152 | |
| 153 record_unwind_protect (read_minibuffer_internal_unwind, | |
| 154 noseeum_cons | |
| 155 (Vminibuf_prompt, | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
156 noseeum_cons (make_fixnum (minibuf_level), Qnil))); |
| 428 | 157 Vminibuf_prompt = LISP_GETTEXT (prompt); |
| 158 | |
| 159 /* NOTE: Here (or somewhere around here), in FSFmacs 19.30, | |
| 160 choose_minibuf_frame() is called. This is the only | |
| 161 place in FSFmacs that it's called any more -- there's | |
| 162 also a call in xterm.c, but commented out, and 19.28 | |
| 163 had the calls in different places. | |
| 164 | |
| 165 choose_minibuf_frame() does the following: | |
| 166 | |
| 167 if (!EQ (minibuf_window, selected_frame()->minibuffer_window)) | |
| 168 { | |
| 169 Fset_window_buffer (selected_frame()->minibuffer_window, | |
| 170 XWINDOW (minibuf_window)->buffer); | |
| 171 minibuf_window = selected_frame()->minibuffer_window; | |
| 172 } | |
| 173 | |
| 174 #### Note that we don't do the set-window-buffer. This call is | |
| 175 similar, but not identical, to a set-window-buffer call made | |
| 176 in `read-from-minibuffer' in minibuf.el. I hope it's close | |
| 177 enough, because minibuf_window isn't really exported to Lisp. | |
| 178 | |
| 179 The comment above choose_minibuf_frame() reads: | |
| 180 | |
| 181 Put minibuf on currently selected frame's minibuffer. | |
| 182 We do this whenever the user starts a new minibuffer | |
| 183 or when a minibuffer exits. */ | |
| 184 | |
| 185 minibuf_window = FRAME_MINIBUF_WINDOW (selected_frame ()); | |
| 186 | |
| 187 run_hook (Qminibuffer_setup_hook); | |
| 188 | |
| 189 minibuf_level++; | |
| 190 clear_echo_area (selected_frame (), Qnil, 0); | |
| 191 | |
| 2286 | 192 call_command_loop (Qt); |
| 428 | 193 |
| 2286 | 194 RETURN_NOT_REACHED (Qnil); |
| 428 | 195 } |
| 196 | |
| 197 | |
| 198 | |
| 199 /* Completion hair */ | |
| 200 | |
| 201 /* Compare exactly LEN chars of strings at S1 and S2, | |
| 202 ignoring case if appropriate. | |
| 203 Return -1 if strings match, | |
| 204 else number of chars that match at the beginning. */ | |
| 205 | |
| 206 /* Note that this function works in Charcounts, unlike most functions. | |
| 207 This is necessary for many reasons, one of which is that two | |
| 208 strings may match even if they have different numbers of bytes, | |
| 209 if IGNORE_CASE is true. */ | |
| 210 | |
| 211 Charcount | |
| 867 | 212 scmp_1 (const Ibyte *s1, const Ibyte *s2, Charcount len, |
| 428 | 213 int ignore_case) |
| 214 { | |
| 215 Charcount l = len; | |
| 216 | |
| 217 if (ignore_case) | |
| 218 { | |
| 219 while (l) | |
| 220 { | |
|
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
221 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
|
222 Ichar c2 = CANONCASE (0, itext_ichar (s2)); |
| 428 | 223 |
| 224 if (c1 == c2) | |
| 225 { | |
| 226 l--; | |
| 867 | 227 INC_IBYTEPTR (s1); |
| 228 INC_IBYTEPTR (s2); | |
| 428 | 229 } |
| 230 else | |
| 231 break; | |
| 232 } | |
| 233 } | |
| 234 else | |
| 235 { | |
| 867 | 236 while (l && itext_ichar (s1) == itext_ichar (s2)) |
| 428 | 237 { |
| 238 l--; | |
| 867 | 239 INC_IBYTEPTR (s1); |
| 240 INC_IBYTEPTR (s2); | |
| 428 | 241 } |
| 242 } | |
| 243 | |
| 244 if (l == 0) | |
| 245 return -1; | |
| 246 else return len - l; | |
| 247 } | |
| 248 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
249 /* 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
|
250 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
|
251 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
|
252 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
|
253 static void |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
254 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
|
255 void *extra_arg) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
256 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
257 Lisp_Object eltstring; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
258 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
259 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
|
260 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
261 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
|
262 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
|
263 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
264 XUNGCPRO (elt); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
265 return; |
|
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 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
268 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
|
269 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
270 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
271 static void |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
272 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
|
273 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
|
274 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
275 if (LISTP (collection)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
276 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
277 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
|
278 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
279 else if (VECTORP (collection)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
280 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
281 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
|
282 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
283 else if (NILP (predicate)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
284 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
285 /* 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
|
286 table entries. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
287 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
|
288 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
289 else |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
290 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
291 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
|
292 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
293 } |
| 428 | 294 |
| 295 int | |
| 867 | 296 regexp_ignore_completion_p (const Ibyte *nonreloc, |
| 428 | 297 Lisp_Object reloc, Bytecount offset, |
| 298 Bytecount length) | |
| 299 { | |
| 300 /* Ignore this element if it fails to match all the regexps. */ | |
| 301 if (!NILP (Vcompletion_regexp_list)) | |
| 302 { | |
| 2367 | 303 EXTERNAL_LIST_LOOP_2 (re, Vcompletion_regexp_list) |
| 428 | 304 { |
| 305 CHECK_STRING (re); | |
| 306 if (fast_string_match (re, nonreloc, reloc, offset, | |
| 307 length, 0, ERROR_ME, 0) < 0) | |
| 308 return 1; | |
| 309 } | |
| 310 } | |
| 311 return 0; | |
| 312 } | |
| 313 | |
| 314 /* Callers should GCPRO, since this may call eval */ | |
| 315 static int | |
| 316 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
|
317 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
|
318 Boolint hash_tablep) |
| 428 | 319 { |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
320 Lisp_Object tem; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
321 |
| 428 | 322 if (regexp_ignore_completion_p (0, completion_string, 0, -1)) |
| 323 return 1; | |
| 324 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
325 if (NILP (pred)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
326 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
327 return 0; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
330 /* 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
|
331 like it. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
332 if (hash_tablep) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
333 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
334 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
|
335 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
336 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
|
337 { |
| 428 | 338 tem = Fcommandp (completion); |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
339 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
340 else |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
341 { |
| 428 | 342 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
|
343 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
344 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
345 return NILP (tem); |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
348 struct try_completion_closure |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
349 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
350 Lisp_Object string; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
351 Charcount slength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
352 Lisp_Object predicate; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
353 Lisp_Object bestmatch; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
354 Charcount blength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
355 Charcount bestmatchsize; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
356 Boolint hash_tablep; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
357 int matchcount; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
360 static int |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
361 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
|
362 void *arg) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
363 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
364 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
|
365 Charcount eltlength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
366 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
367 if (SYMBOLP (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
368 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
369 eltstring = XSYMBOL_NAME (eltstring); |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
372 if (!STRINGP (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
373 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
374 return 0; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
377 /* 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
|
378 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
|
379 if (tcc->slength <= eltlength |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
380 && (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
|
381 tcc->slength))) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
382 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
383 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
|
384 int loser; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
385 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
|
386 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
|
387 tcc->hash_tablep); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
388 UNGCPRO; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
389 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
|
390 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
391 return 0; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
394 /* 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
|
395 match */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
396 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
397 tcc->matchcount++; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
398 if (NILP (tcc->bestmatch)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
399 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
400 tcc->bestmatch = eltstring; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
401 tcc->blength = eltlength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
402 tcc->bestmatchsize = eltlength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
403 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
404 else |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
405 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
406 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
|
407 Charcount matchsize = |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
408 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
|
409 compare); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
410 if (matchsize < 0) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
411 matchsize = compare; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
412 if (completion_ignore_case) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
413 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
414 /* 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
|
415 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
|
416 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
|
417 actual match. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
418 if ((matchsize == eltlength |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
419 && matchsize < tcc->blength) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
420 || |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
421 /* 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
|
422 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
|
423 prefer that one. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
424 /* 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
|
425 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
|
426 the input. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
427 ((matchsize == eltlength) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
428 == |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
429 (matchsize == tcc->blength) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
430 && 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
|
431 XSTRING_DATA (tcc->string), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
432 tcc->slength, 0) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
433 && 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
|
434 XSTRING_DATA (tcc->string), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
435 tcc->slength, 0))) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
436 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
437 tcc->bestmatch = eltstring; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
438 tcc->blength = eltlength; |
|
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 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
441 tcc->bestmatchsize = matchsize; |
|
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 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
444 |
| 428 | 445 return 0; |
| 446 } | |
| 447 | |
| 448 DEFUN ("try-completion", Ftry_completion, 2, 3, 0, /* | |
| 444 | 449 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
|
450 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
|
451 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 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
|
456 match, t is returned. |
| 428 | 457 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
458 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
|
459 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
|
460 \(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
|
461 completions. |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
462 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
463 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
|
464 are the possible completions. |
| 428 | 465 |
| 444 | 466 If COLLECTION is an obarray, the names of all symbols in the obarray |
| 467 are the possible completions. | |
| 468 | |
| 469 If COLLECTION is a function, it is called with three arguments: the | |
| 470 values STRING, PREDICATE and nil. Whatever it returns becomes the | |
| 471 value of `try-completion'. | |
| 428 | 472 |
| 444 | 473 If optional third argument PREDICATE is non-nil, it is used to test |
| 474 each possible match. The match is a candidate only if PREDICATE | |
| 475 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
|
476 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
|
477 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
|
478 table entry. |
| 428 | 479 */ |
| 444 | 480 (string, collection, predicate)) |
| 428 | 481 { |
| 482 /* 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
|
483 struct try_completion_closure tcc; |
| 428 | 484 |
| 485 CHECK_STRING (string); | |
| 486 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
487 if (!NILP (Ffunctionp (collection))) |
| 428 | 488 { |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
489 return call3 (collection, string, predicate, Qnil); |
| 428 | 490 } |
| 491 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
492 if (!(LISTP (collection) || VECTORP (collection) || HASH_TABLEP (collection))) |
| 428 | 493 { |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
494 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
|
495 "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
|
496 collection); |
| 428 | 497 } |
| 498 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
499 tcc.string = string; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
500 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
|
501 tcc.bestmatch = Qnil; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
502 tcc.blength = 0; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
503 tcc.bestmatchsize = 0; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
504 tcc.predicate = predicate; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
505 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
|
506 tcc.matchcount = 0; |
| 428 | 507 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
508 map_completion (try_completion_mapper, collection, &tcc, predicate); |
| 428 | 509 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
510 if (NILP (tcc.bestmatch)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
511 return Qnil; /* No completions found */ |
| 428 | 512 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
513 /* 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
|
514 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
|
515 user typed. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
516 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
|
517 && tcc.blength > tcc.bestmatchsize) |
| 428 | 518 return string; |
| 519 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
520 /* 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
|
521 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
|
522 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
|
523 && 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
|
524 tcc.bestmatchsize, 0)) |
| 428 | 525 return Qt; |
| 526 | |
| 527 /* 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
|
528 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
|
529 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
530 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
531 struct all_completions_closure |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
532 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
533 Lisp_Object string; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
534 Charcount slength; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
535 Lisp_Object predicate; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
536 Lisp_Object allmatches; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
537 Boolint hash_tablep; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
540 static int |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
541 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
|
542 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
543 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
|
544 /* 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
|
545 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
546 if (SYMBOLP (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
547 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
548 eltstring = XSYMBOL_NAME (eltstring); |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
551 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
|
552 /* 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
|
553 starts with space. */ |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
554 && ((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
|
555 || string_ichar (eltstring, 0) != ' ') |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
556 && (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
|
557 acc->slength))) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
558 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
559 /* 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
|
560 struct gcpro gcpro1, gcpro2; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
561 int loser; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
562 GCPRO2 (eltstring, acc->string); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
563 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
|
564 acc->hash_tablep); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
565 UNGCPRO; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
566 if (!loser) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
567 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
568 /* 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
|
569 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
|
570 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
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
574 return 0; |
| 428 | 575 } |
| 576 | |
| 577 DEFUN ("all-completions", Fall_completions, 2, 3, 0, /* | |
| 444 | 578 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
|
579 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
|
580 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
581 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
|
582 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
|
583 COLLECTION that match. |
| 444 | 584 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
585 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
|
586 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
|
587 \(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
|
588 completions. |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
589 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
590 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
|
591 are the possible completions. |
| 444 | 592 |
| 593 If COLLECTION is an obarray, the names of all symbols in the obarray | |
| 594 are the possible completions. | |
| 428 | 595 |
| 444 | 596 If COLLECTION is a function, it is called with three arguments: the |
| 597 values STRING, PREDICATE and t. Whatever it returns becomes the | |
| 598 value of `all-completions'. | |
| 428 | 599 |
| 444 | 600 If optional third argument PREDICATE is non-nil, it is used to test |
| 601 each possible match. The match is a candidate only if PREDICATE | |
| 602 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
|
603 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
|
604 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
|
605 table entry. |
| 428 | 606 */ |
| 444 | 607 (string, collection, predicate)) |
| 428 | 608 { |
| 609 /* 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
|
610 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
|
611 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
|
612 struct gcpro gcpro1; |
| 428 | 613 |
| 614 CHECK_STRING (string); | |
| 615 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
616 if (!NILP (Ffunctionp (collection))) |
| 428 | 617 { |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
618 return call3 (collection, string, predicate, Qt); |
| 428 | 619 } |
| 620 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
621 if (!(LISTP (collection) || VECTORP (collection) || HASH_TABLEP (collection))) |
| 428 | 622 { |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
623 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
|
624 "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
|
625 collection); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
626 } |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
627 GCPRO1 (allmatches); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
628 acc.string = string; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
629 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
|
630 acc.predicate = predicate; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
631 acc.allmatches = allmatches; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
632 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
|
633 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
634 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
|
635 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
636 acc.allmatches = XCDR (allmatches); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
637 free_cons (allmatches); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
638 UNGCPRO; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
639 return acc.allmatches; |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
642 struct test_completion_closure |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
643 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
644 Lisp_Object string; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
645 Lisp_Object predicate; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
646 Lisp_Object result; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
647 Boolint hash_tablep; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
648 }; |
| 428 | 649 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
650 static int |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
651 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
|
652 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
653 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
|
654 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
655 if (SYMBOLP (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
656 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
657 eltstring = XSYMBOL_NAME (eltstring); |
|
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 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
660 if (!STRINGP (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
661 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
662 return 0; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
663 } |
| 428 | 664 |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
665 if (completion_ignore_case ? |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
666 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
|
667 XSTRING_LENGTH (tcc->string), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
668 XSTRING_DATA (eltstring), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
669 XSTRING_LENGTH (eltstring)) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
670 : 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
|
671 XSTRING_LENGTH (tcc->string), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
672 XSTRING_DATA (eltstring), |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
673 XSTRING_LENGTH (eltstring))) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
674 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
675 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
|
676 int loser; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
677 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
|
678 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
|
679 tcc->hash_tablep); |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
680 UNGCPRO; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
681 if (!loser) |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
682 { |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
683 tcc->result = Qt; |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
684 return 1; |
| 428 | 685 } |
| 686 } | |
| 687 | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
688 return 0; |
| 428 | 689 } |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
690 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
691 DEFUN ("test-completion", Ftest_completion, 2, 3, 0, /* |
|
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
692 Return non-nil if STRING is an exact completion in COLLECTION. |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
693 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
694 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
|
695 |
|
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
696 Each string (or symbol) in COLLECTION is tested to see if it (or its |
|
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
697 name) begins with STRING, until a valid, exact completion is found. |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
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 |
|
5666
daf5accfe973
Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5634
diff
changeset
|
758 tables, except, both symbol and string keys are valid |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
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 */ | |
| 440 | 846 /* There is an inlining bug in egcs-20000131 c++ that can be worked |
| 847 around as follows: */ | |
| 848 #if defined (__GNUC__) && defined (__cplusplus) | |
| 849 alloca (4); | |
| 850 #endif | |
| 851 | |
| 428 | 852 /* some callers pass in a null string as a way of clearing the echo area. |
| 853 check for length == 0 now; if this case, neither nonreloc nor reloc | |
| 854 may be valid. */ | |
| 855 if (length == 0) | |
| 856 return; | |
| 857 | |
| 858 fixup_internal_substring (nonreloc, reloc, offset, &length); | |
| 859 | |
| 860 /* also check it here, in case the string was really blank. */ | |
| 861 if (length == 0) | |
| 862 return; | |
| 863 | |
|
5803
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
864 if (!UNBOUNDP (XSYMBOL_FUNCTION (Qappend_message))) |
| 428 | 865 { |
|
5803
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
866 Lisp_Object obj |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
867 = STRINGP (reloc) ? reloc : make_string (nonreloc + offset, length); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
868 Lisp_Object args[] = { Qappend_message, label, obj, wrap_frame (f), |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
869 EQ (label, Qprint) ? Qt : Qnil, Q_start, Qzero, |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
870 Q_end, Qnil }; |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
871 struct gcpro gcpro1; |
| 428 | 872 |
|
5803
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
873 if (STRINGP (reloc) |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
874 && (offset != 0 || length != XSTRING_LENGTH (reloc))) |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
875 { |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
876 assert (EQ (args[5], Q_start)); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
877 args[6] = make_fixnum (string_index_byte_to_char (reloc, offset)); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
878 assert (EQ (args[7], Q_end)); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
879 args[8] |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
880 = make_fixnum (string_index_byte_to_char (reloc, offset + length)); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
881 } |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
882 GCPRO1 (args[0]); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
883 gcpro1.nvars = countof (args); |
|
b79e1e02bf01
Preserve extent information in the command builder code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5666
diff
changeset
|
884 Ffuncall (countof (args), args); |
| 428 | 885 UNGCPRO; |
| 886 } | |
| 887 else | |
| 888 { | |
| 889 if (STRINGP (reloc)) | |
| 890 nonreloc = XSTRING_DATA (reloc); | |
| 826 | 891 write_string_1 (Qexternal_debugging_output, nonreloc + offset, length); |
| 428 | 892 } |
| 893 } | |
| 894 | |
| 895 void | |
| 867 | 896 echo_area_message (struct frame *f, const Ibyte *nonreloc, |
| 428 | 897 Lisp_Object reloc, Bytecount offset, Bytecount length, |
| 898 Lisp_Object label) | |
| 899 { | |
| 900 /* This function can call lisp */ | |
| 901 clear_echo_area (f, label, 1); | |
| 902 echo_area_append (f, nonreloc, reloc, offset, length, label); | |
| 903 } | |
| 904 | |
| 905 int | |
| 2286 | 906 echo_area_active (struct frame *UNUSED (f)) |
| 428 | 907 { |
| 908 /* By definition, the echo area is active if the echo-area buffer | |
| 909 is not empty. No need to call Lisp code. (Anyway, this function | |
| 910 is called from redisplay.) */ | |
| 911 struct buffer *echo_buffer = XBUFFER (Vecho_area_buffer); | |
| 912 return BUF_BEGV (echo_buffer) != BUF_ZV (echo_buffer); | |
| 913 } | |
| 914 | |
| 915 Lisp_Object | |
| 916 echo_area_status (struct frame *f) | |
| 917 { | |
| 918 /* This function can call lisp */ | |
| 919 if (!NILP (Ffboundp (Qcurrent_message_label))) | |
| 920 { | |
| 793 | 921 Lisp_Object frame = wrap_frame (f); |
| 428 | 922 |
| 923 return call1 (Qcurrent_message_label, frame); | |
| 924 } | |
| 925 else | |
| 926 return stdout_needs_newline ? Qmessage : Qnil; | |
| 927 } | |
| 928 | |
| 929 Lisp_Object | |
| 2286 | 930 echo_area_contents (struct frame *UNUSED (f)) |
| 428 | 931 { |
| 932 /* See above. By definition, the contents of the echo-area buffer | |
| 933 are the contents of the echo area. */ | |
| 934 return Fbuffer_substring (Qnil, Qnil, Vecho_area_buffer); | |
| 935 } | |
| 936 | |
| 937 /* Dump an informative message to the echo area. This function takes a | |
| 938 string in internal format. */ | |
| 939 void | |
| 867 | 940 message_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
| 428 | 941 Bytecount offset, Bytecount length) |
| 942 { | |
| 943 /* This function can call lisp */ | |
| 944 if (NILP (Vexecuting_macro)) | |
| 945 echo_area_message (selected_frame (), nonreloc, reloc, offset, length, | |
| 946 Qmessage); | |
| 947 } | |
| 948 | |
| 949 void | |
| 867 | 950 message_append_internal (const Ibyte *nonreloc, Lisp_Object reloc, |
| 428 | 951 Bytecount offset, Bytecount length) |
| 952 { | |
| 953 /* This function can call lisp */ | |
| 954 if (NILP (Vexecuting_macro)) | |
| 955 echo_area_append (selected_frame (), nonreloc, reloc, offset, length, | |
| 956 Qmessage); | |
| 957 } | |
| 958 | |
| 959 /* The next three functions are interfaces to message_internal() that | |
| 960 take strings in external format. message() does I18N3 translating | |
| 961 on the format string; message_no_translate() does not. */ | |
| 962 | |
| 963 static void | |
| 867 | 964 message_1 (const CIbyte *fmt, va_list args) |
| 428 | 965 { |
| 966 /* This function can call lisp */ | |
| 967 if (fmt) | |
| 968 { | |
| 969 struct gcpro gcpro1; | |
| 970 /* message_internal() might GC, e.g. if there are after-change-hooks | |
| 971 on the echo area buffer */ | |
| 771 | 972 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
| 428 | 973 GCPRO1 (obj); |
| 974 message_internal (0, obj, 0, -1); | |
| 975 UNGCPRO; | |
| 976 } | |
| 977 else | |
| 978 message_internal (0, Qnil, 0, 0); | |
| 979 } | |
| 980 | |
| 981 static void | |
| 867 | 982 message_append_1 (const CIbyte *fmt, va_list args) |
| 428 | 983 { |
| 984 /* This function can call lisp */ | |
| 985 if (fmt) | |
| 986 { | |
| 987 struct gcpro gcpro1; | |
| 988 /* message_internal() might GC, e.g. if there are after-change-hooks | |
| 989 on the echo area buffer */ | |
| 771 | 990 Lisp_Object obj = emacs_vsprintf_string (fmt, args); |
| 428 | 991 GCPRO1 (obj); |
| 992 message_append_internal (0, obj, 0, -1); | |
| 993 UNGCPRO; | |
| 994 } | |
| 995 else | |
| 996 message_append_internal (0, Qnil, 0, 0); | |
| 997 } | |
| 998 | |
| 999 void | |
| 1000 clear_message (void) | |
| 1001 { | |
| 1002 /* This function can call lisp */ | |
| 1003 message_internal (0, Qnil, 0, 0); | |
| 1004 } | |
| 1005 | |
| 1006 void | |
| 442 | 1007 message (const char *fmt, ...) |
| 428 | 1008 { |
| 1009 /* This function can call lisp */ | |
| 1010 /* I think it's OK to pass the data of Lisp strings as arguments to | |
| 1011 this function. No GC'ing will occur until the data has already | |
| 1012 been copied. */ | |
| 1013 va_list args; | |
| 1014 | |
| 1015 va_start (args, fmt); | |
| 1016 if (fmt) | |
| 1017 fmt = GETTEXT (fmt); | |
| 1018 message_1 (fmt, args); | |
| 1019 va_end (args); | |
| 1020 } | |
| 1021 | |
| 1022 void | |
| 442 | 1023 message_append (const char *fmt, ...) |
| 428 | 1024 { |
| 1025 /* This function can call lisp */ | |
| 1026 va_list args; | |
| 1027 | |
| 1028 va_start (args, fmt); | |
| 1029 if (fmt) | |
| 1030 fmt = GETTEXT (fmt); | |
| 1031 message_append_1 (fmt, args); | |
| 1032 va_end (args); | |
| 1033 } | |
| 1034 | |
| 1035 void | |
| 442 | 1036 message_no_translate (const char *fmt, ...) |
| 428 | 1037 { |
| 1038 /* This function can call lisp */ | |
| 1039 /* I think it's OK to pass the data of Lisp strings as arguments to | |
| 1040 this function. No GC'ing will occur until the data has already | |
| 1041 been copied. */ | |
| 1042 va_list args; | |
| 1043 | |
| 1044 va_start (args, fmt); | |
| 1045 message_1 (fmt, args); | |
| 1046 va_end (args); | |
| 1047 } | |
| 1048 | |
| 1049 | |
| 1050 /************************************************************************/ | |
| 1051 /* initialization */ | |
| 1052 /************************************************************************/ | |
| 1053 | |
| 1054 void | |
| 1055 syms_of_minibuf (void) | |
| 1056 { | |
| 563 | 1057 DEFSYMBOL (Qminibuffer_setup_hook); |
| 428 | 1058 |
| 563 | 1059 DEFSYMBOL (Qcompletion_ignore_case); |
| 428 | 1060 |
| 1061 DEFSUBR (Fminibuffer_depth); | |
| 1062 #if 0 | |
| 1063 DEFSUBR (Fminibuffer_prompt); | |
| 1064 DEFSUBR (Fminibuffer_prompt_width); | |
| 1065 #endif | |
| 1066 DEFSUBR (Fset_minibuffer_preprompt); | |
| 1067 DEFSUBR (Fread_minibuffer_internal); | |
| 1068 | |
| 1069 DEFSUBR (Ftry_completion); | |
| 1070 DEFSUBR (Fall_completions); | |
|
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
1071 DEFSUBR (Ftest_completion); |
| 428 | 1072 |
| 563 | 1073 DEFSYMBOL (Qappend_message); |
| 1074 DEFSYMBOL (Qclear_message); | |
| 1075 DEFSYMBOL (Qdisplay_message); | |
| 1076 DEFSYMBOL (Qcurrent_message_label); | |
| 428 | 1077 } |
| 1078 | |
| 1079 void | |
| 1080 reinit_vars_of_minibuf (void) | |
| 1081 { | |
| 1082 minibuf_level = 0; | |
| 1083 } | |
| 1084 | |
| 1085 void | |
| 1086 vars_of_minibuf (void) | |
| 1087 { | |
| 1088 staticpro (&Vminibuf_prompt); | |
| 1089 Vminibuf_prompt = Qnil; | |
| 1090 | |
| 1091 /* Added by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */ | |
| 1092 staticpro (&Vminibuf_preprompt); | |
| 1093 Vminibuf_preprompt = Qnil; | |
| 1094 | |
| 1095 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook /* | |
| 1096 Normal hook run just after entry to minibuffer. | |
| 1097 */ ); | |
| 1098 Vminibuffer_setup_hook = Qnil; | |
| 1099 | |
| 1100 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case /* | |
| 1101 Non-nil means don't consider case significant in completion. | |
| 1102 */ ); | |
| 1103 completion_ignore_case = 0; | |
| 1104 | |
| 1105 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list /* | |
| 1106 List of regexps that should restrict possible completions. | |
| 1107 Each completion has to match all regexps in this list. | |
| 1108 */ ); | |
| 1109 Vcompletion_regexp_list = Qnil; | |
| 1110 } | |
| 1111 | |
| 1112 void | |
| 1113 reinit_complex_vars_of_minibuf (void) | |
| 1114 { | |
| 1115 /* This function can GC */ | |
| 1116 #ifdef I18N3 | |
| 1117 /* #### This needs to be fixed up so that the gettext() gets called | |
| 1118 at runtime instead of at load time. */ | |
| 1119 #endif | |
| 1120 Vminibuffer_zero | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1121 = Fget_buffer_create (build_ascstring (" *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
|
1122 staticpro_nodump (&Vminibuffer_zero); |
| 428 | 1123 Vecho_area_buffer |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4704
diff
changeset
|
1124 = 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
|
1125 staticpro_nodump (&Vecho_area_buffer); |
| 428 | 1126 } |
| 1127 | |
| 1128 void | |
| 1129 complex_vars_of_minibuf (void) | |
| 1130 { | |
| 1131 reinit_complex_vars_of_minibuf (); | |
| 1132 } |
