comparison src/minibuf.c @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 47e79133c28a
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
129 129
130 Lisp_Object Qminibuffer_default; 130 Lisp_Object Qminibuffer_default;
131 131
132 Lisp_Object Qcurrent_input_method, Qactivate_input_method; 132 Lisp_Object Qcurrent_input_method, Qactivate_input_method;
133 133
134 Lisp_Object Qcase_fold_search;
135
134 extern Lisp_Object Qmouse_face; 136 extern Lisp_Object Qmouse_face;
135 137
136 extern Lisp_Object Qfield; 138 extern Lisp_Object Qfield;
137 139
138 /* Put minibuf on currently selected frame's minibuffer. 140 /* Put minibuf on currently selected frame's minibuffer.
187 } 189 }
188 190
189 DEFUN ("set-minibuffer-window", Fset_minibuffer_window, 191 DEFUN ("set-minibuffer-window", Fset_minibuffer_window,
190 Sset_minibuffer_window, 1, 1, 0, 192 Sset_minibuffer_window, 1, 1, 0,
191 doc: /* Specify which minibuffer window to use for the minibuffer. 193 doc: /* Specify which minibuffer window to use for the minibuffer.
192 This effects where the minibuffer is displayed if you put text in it 194 This affects where the minibuffer is displayed if you put text in it
193 without invoking the usual minibuffer commands. */) 195 without invoking the usual minibuffer commands. */)
194 (window) 196 (window)
195 Lisp_Object window; 197 Lisp_Object window;
196 { 198 {
197 CHECK_WINDOW (window); 199 CHECK_WINDOW (window);
319 } 321 }
320 322
321 DEFUN ("minibufferp", Fminibufferp, 323 DEFUN ("minibufferp", Fminibufferp,
322 Sminibufferp, 0, 1, 0, 324 Sminibufferp, 0, 1, 0,
323 doc: /* Return t if BUFFER is a minibuffer. 325 doc: /* Return t if BUFFER is a minibuffer.
324 No argument or nil as argument means use current buffer as BUFFER.*/) 326 No argument or nil as argument means use current buffer as BUFFER.
327 BUFFER can be a buffer or a buffer name. */)
325 (buffer) 328 (buffer)
326 Lisp_Object buffer; 329 Lisp_Object buffer;
327 { 330 {
328 Lisp_Object tem; 331 Lisp_Object tem;
329 332
402 if (PT < prompt_end) 405 if (PT < prompt_end)
403 error ("Cannot do completion in the prompt"); 406 error ("Cannot do completion in the prompt");
404 return make_buffer_string (prompt_end, PT, 1); 407 return make_buffer_string (prompt_end, PT, 1);
405 } 408 }
406 409
407 /* Read from the minibuffer using keymap MAP, initial contents INITIAL 410 /* Read from the minibuffer using keymap MAP and initial contents INITIAL,
408 (a string), putting point minus BACKUP_N bytes from the end of INITIAL, 411 putting point minus BACKUP_N bytes from the end of INITIAL,
409 prompting with PROMPT (a string), using history list HISTVAR 412 prompting with PROMPT (a string), using history list HISTVAR
410 with initial position HISTPOS. (BACKUP_N should be <= 0.) 413 with initial position HISTPOS. INITIAL should be a string or a
414 cons of a string and an integer. BACKUP_N should be <= 0, or
415 Qnil, which is equivalent to 0. If INITIAL is a cons, BACKUP_N is
416 ignored and replaced with an integer that puts point at one-indexed
417 position N in INITIAL, where N is the CDR of INITIAL, or at the
418 beginning of INITIAL if N <= 0.
411 419
412 Normally return the result as a string (the text that was read), 420 Normally return the result as a string (the text that was read),
413 but if EXPFLAG is nonzero, read it and return the object read. 421 but if EXPFLAG is nonzero, read it and return the object read.
414 If HISTVAR is given, save the value read on that history only if it doesn't 422 If HISTVAR is given, save the value read on that history only if it doesn't
415 match the front of that history list exactly. The value is pushed onto 423 match the front of that history list exactly. The value is pushed onto
417 425
418 DEFALT specifies the default value for the sake of history commands. 426 DEFALT specifies the default value for the sake of history commands.
419 427
420 If ALLOW_PROPS is nonzero, we do not throw away text properties. 428 If ALLOW_PROPS is nonzero, we do not throw away text properties.
421 429
422 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the 430 if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the
423 current input method. */ 431 current input method. */
424 432
425 static Lisp_Object 433 static Lisp_Object
426 read_minibuf (map, initial, prompt, backup_n, expflag, 434 read_minibuf (map, initial, prompt, backup_n, expflag,
427 histvar, histpos, defalt, allow_props, inherit_input_method) 435 histvar, histpos, defalt, allow_props, inherit_input_method)
439 Lisp_Object val; 447 Lisp_Object val;
440 int count = SPECPDL_INDEX (); 448 int count = SPECPDL_INDEX ();
441 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; 449 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
442 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 450 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
443 Lisp_Object enable_multibyte; 451 Lisp_Object enable_multibyte;
452 int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0;
444 453
445 /* String to add to the history. */ 454 /* String to add to the history. */
446 Lisp_Object histstring; 455 Lisp_Object histstring;
447 456
448 extern Lisp_Object Qfront_sticky; 457 extern Lisp_Object Qfront_sticky;
454 #ifdef HAVE_X_WINDOWS 463 #ifdef HAVE_X_WINDOWS
455 if (display_hourglass_p) 464 if (display_hourglass_p)
456 cancel_hourglass (); 465 cancel_hourglass ();
457 #endif 466 #endif
458 467
468 if (!NILP (initial))
469 {
470 if (CONSP (initial))
471 {
472 backup_n = Fcdr (initial);
473 initial = Fcar (initial);
474 CHECK_STRING (initial);
475 if (!NILP (backup_n))
476 {
477 CHECK_NUMBER (backup_n);
478 /* Convert to distance from end of input. */
479 if (XINT (backup_n) < 1)
480 /* A number too small means the beginning of the string. */
481 pos = - SCHARS (initial);
482 else
483 pos = XINT (backup_n) - 1 - SCHARS (initial);
484 }
485 }
486 else
487 CHECK_STRING (initial);
488 }
459 val = Qnil; 489 val = Qnil;
460 ambient_dir = current_buffer->directory; 490 ambient_dir = current_buffer->directory;
461 input_method = Qnil; 491 input_method = Qnil;
462 enable_multibyte = Qnil; 492 enable_multibyte = Qnil;
463 493
480 build_string ("Command attempted to use minibuffer while in minibuffer")); 510 build_string ("Command attempted to use minibuffer while in minibuffer"));
481 } 511 }
482 512
483 if (noninteractive) 513 if (noninteractive)
484 { 514 {
485 val = read_minibuf_noninteractive (map, initial, prompt, backup_n, 515 val = read_minibuf_noninteractive (map, initial, prompt,
516 make_number (pos),
486 expflag, histvar, histpos, defalt, 517 expflag, histvar, histpos, defalt,
487 allow_props, inherit_input_method); 518 allow_props, inherit_input_method);
488 UNGCPRO; 519 UNGCPRO;
489 return unbind_to (count, val); 520 return unbind_to (count, val);
490 } 521 }
631 662
632 /* Put in the initial input. */ 663 /* Put in the initial input. */
633 if (!NILP (initial)) 664 if (!NILP (initial))
634 { 665 {
635 Finsert (1, &initial); 666 Finsert (1, &initial);
636 if (INTEGERP (backup_n)) 667 Fforward_char (make_number (pos));
637 Fforward_char (backup_n);
638 } 668 }
639 669
640 clear_message (1, 1); 670 clear_message (1, 1);
641 current_buffer->keymap = map; 671 current_buffer->keymap = map;
642 672
864 } 894 }
865 895
866 896
867 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0, 897 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
868 doc: /* Read a string from the minibuffer, prompting with string PROMPT. 898 doc: /* Read a string from the minibuffer, prompting with string PROMPT.
869 If optional second arg INITIAL-CONTENTS is non-nil, it is a string 899 The optional second arg INITIAL-CONTENTS is an obsolete alternative to
870 to be inserted into the minibuffer before reading input. 900 DEFAULT-VALUE. It normally should be nil in new code, except when
871 If INITIAL-CONTENTS is (STRING . POSITION), the initial input 901 HIST is a cons. It is discussed in more detail below.
872 is STRING, but point is placed at position POSITION in the minibuffer.
873 Third arg KEYMAP is a keymap to use whilst reading; 902 Third arg KEYMAP is a keymap to use whilst reading;
874 if omitted or nil, the default is `minibuffer-local-map'. 903 if omitted or nil, the default is `minibuffer-local-map'.
875 If fourth arg READ is non-nil, then interpret the result as a Lisp object 904 If fourth arg READ is non-nil, then interpret the result as a Lisp object
876 and return that object: 905 and return that object:
877 in other words, do `(car (read-from-string INPUT-STRING))' 906 in other words, do `(car (read-from-string INPUT-STRING))'
878 Fifth arg HIST, if non-nil, specifies a history list 907 Fifth arg HIST, if non-nil, specifies a history list and optionally
879 and optionally the initial position in the list. 908 the initial position in the list. It can be a symbol, which is the
880 It can be a symbol, which is the history list variable to use, 909 history list variable to use, or it can be a cons cell
881 or it can be a cons cell (HISTVAR . HISTPOS). 910 (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable
882 In that case, HISTVAR is the history list variable to use, 911 to use, and HISTPOS is the initial position for use by the minibuffer
883 and HISTPOS is the initial position (the position in the list 912 history commands. For consistency, you should also specify that
884 which INITIAL-CONTENTS corresponds to). 913 element of the history as the value of INITIAL-CONTENTS. Positions
885 Positions are counted starting from 1 at the beginning of the list. 914 are counted starting from 1 at the beginning of the list.
886 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available 915 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available
887 for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE 916 for history commands; but, unless READ is non-nil, `read-from-minibuffer'
888 if the user enters empty input! It returns the empty string. 917 does NOT return DEFAULT-VALUE if the user enters empty input! It returns
918 the empty string.
889 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits 919 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
890 the current input method and the setting of `enable-multibyte-characters'. 920 the current input method and the setting of `enable-multibyte-characters'.
891 If the variable `minibuffer-allow-text-properties' is non-nil, 921 If the variable `minibuffer-allow-text-properties' is non-nil,
892 then the string which is returned includes whatever text properties 922 then the string which is returned includes whatever text properties
893 were present in the minibuffer. Otherwise the value has no text properties. */) 923 were present in the minibuffer. Otherwise the value has no text properties.
924
925 The remainder of this documentation string describes the
926 INITIAL-CONTENTS argument in more detail. It is only relevant when
927 studying existing code, or when HIST is a cons. If non-nil,
928 INITIAL-CONTENTS is a string to be inserted into the minibuffer before
929 reading input. Normally, point is put at the end of that string.
930 However, if INITIAL-CONTENTS is \(STRING . POSITION), the initial
931 input is STRING, but point is placed at _one-indexed_ position
932 POSITION in the minibuffer. Any integer value less than or equal to
933 one puts point at the beginning of the string. *Note* that this
934 behavior differs from the way such arguments are used in `completing-read'
935 and some related functions, which use zero-indexing for POSITION. */)
894 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method) 936 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
895 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; 937 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value;
896 Lisp_Object inherit_input_method; 938 Lisp_Object inherit_input_method;
897 { 939 {
898 int pos = 0; 940 Lisp_Object histvar, histpos, val;
899 Lisp_Object histvar, histpos, position, val;
900 struct gcpro gcpro1; 941 struct gcpro gcpro1;
901 942
902 position = Qnil;
903
904 CHECK_STRING (prompt); 943 CHECK_STRING (prompt);
905 if (!NILP (initial_contents))
906 {
907 if (CONSP (initial_contents))
908 {
909 position = Fcdr (initial_contents);
910 initial_contents = Fcar (initial_contents);
911 }
912 CHECK_STRING (initial_contents);
913 if (!NILP (position))
914 {
915 CHECK_NUMBER (position);
916 /* Convert to distance from end of input. */
917 if (XINT (position) < 1)
918 /* A number too small means the beginning of the string. */
919 pos = - SCHARS (initial_contents);
920 else
921 pos = XINT (position) - 1 - SCHARS (initial_contents);
922 }
923 }
924
925 if (NILP (keymap)) 944 if (NILP (keymap))
926 keymap = Vminibuffer_local_map; 945 keymap = Vminibuffer_local_map;
927 else 946 else
928 keymap = get_keymap (keymap, 1, 0); 947 keymap = get_keymap (keymap, 1, 0);
929 948
942 if (NILP (histpos)) 961 if (NILP (histpos))
943 XSETFASTINT (histpos, 0); 962 XSETFASTINT (histpos, 0);
944 963
945 GCPRO1 (default_value); 964 GCPRO1 (default_value);
946 val = read_minibuf (keymap, initial_contents, prompt, 965 val = read_minibuf (keymap, initial_contents, prompt,
947 make_number (pos), !NILP (read), 966 Qnil, !NILP (read),
948 histvar, histpos, default_value, 967 histvar, histpos, default_value,
949 minibuffer_allow_text_properties, 968 minibuffer_allow_text_properties,
950 !NILP (inherit_input_method)); 969 !NILP (inherit_input_method));
951 UNGCPRO; 970 UNGCPRO;
952 return val; 971 return val;
953 } 972 }
954 973
955 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, 974 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
956 doc: /* Return a Lisp object read using the minibuffer. 975 doc: /* Return a Lisp object read using the minibuffer, unevaluated.
957 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 976 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
958 is a string to insert in the minibuffer before reading. */) 977 is a string to insert in the minibuffer before reading.
978 \(INITIAL-CONTENTS can also be a cons of a string and an integer. Such
979 arguments are used as in `read-from-minibuffer') */)
959 (prompt, initial_contents) 980 (prompt, initial_contents)
960 Lisp_Object prompt, initial_contents; 981 Lisp_Object prompt, initial_contents;
961 { 982 {
962 CHECK_STRING (prompt); 983 CHECK_STRING (prompt);
963 if (!NILP (initial_contents))
964 CHECK_STRING (initial_contents);
965 return read_minibuf (Vminibuffer_local_map, initial_contents, 984 return read_minibuf (Vminibuffer_local_map, initial_contents,
966 prompt, Qnil, 1, Qminibuffer_history, 985 prompt, Qnil, 1, Qminibuffer_history,
967 make_number (0), Qnil, 0, 0); 986 make_number (0), Qnil, 0, 0);
968 } 987 }
969 988
970 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, 989 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
971 doc: /* Return value of Lisp expression read using the minibuffer. 990 doc: /* Return value of Lisp expression read using the minibuffer.
972 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 991 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
973 is a string to insert in the minibuffer before reading. */) 992 is a string to insert in the minibuffer before reading.
993 \(INITIAL-CONTENTS can also be a cons of a string and an integer. Such
994 arguments are used as in `read-from-minibuffer') */)
974 (prompt, initial_contents) 995 (prompt, initial_contents)
975 Lisp_Object prompt, initial_contents; 996 Lisp_Object prompt, initial_contents;
976 { 997 {
977 return Feval (Fread_minibuffer (prompt, initial_contents)); 998 return Feval (Fread_minibuffer (prompt, initial_contents));
978 } 999 }
980 /* Functions that use the minibuffer to read various things. */ 1001 /* Functions that use the minibuffer to read various things. */
981 1002
982 DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0, 1003 DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
983 doc: /* Read a string from the minibuffer, prompting with string PROMPT. 1004 doc: /* Read a string from the minibuffer, prompting with string PROMPT.
984 If non-nil, second arg INITIAL-INPUT is a string to insert before reading. 1005 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
1006 This argument has been superseded by DEFAULT-VALUE and should normally
1007 be nil in new code. It behaves as in `read-from-minibuffer'. See the
1008 documentation string of that function for details.
985 The third arg HISTORY, if non-nil, specifies a history list 1009 The third arg HISTORY, if non-nil, specifies a history list
986 and optionally the initial position in the list. 1010 and optionally the initial position in the list.
987 See `read-from-minibuffer' for details of HISTORY argument. 1011 See `read-from-minibuffer' for details of HISTORY argument.
988 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used 1012 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
989 for history commands, and as the value to return if the user enters 1013 for history commands, and as the value to return if the user enters
1003 return val; 1027 return val;
1004 } 1028 }
1005 1029
1006 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, 1030 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
1007 doc: /* Read a string from the terminal, not allowing blanks. 1031 doc: /* Read a string from the terminal, not allowing blanks.
1008 Prompt with PROMPT, and provide INITIAL as an initial value of the input string. 1032 Prompt with PROMPT. Whitespace terminates the input. If INITIAL is
1033 non-nil, it should be a string, which is used as initial input, with
1034 point positioned at the end, so that SPACE will accept the input.
1035 \(Actually, INITIAL can also be a cons of a string and an integer.
1036 Such values are treated as in `read-from-minibuffer', but are normally
1037 not useful in this function.)
1009 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits 1038 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
1010 the current input method and the setting of `enable-multibyte-characters'. */) 1039 the current input method and the setting of`enable-multibyte-characters'. */)
1011 (prompt, initial, inherit_input_method) 1040 (prompt, initial, inherit_input_method)
1012 Lisp_Object prompt, initial, inherit_input_method; 1041 Lisp_Object prompt, initial, inherit_input_method;
1013 { 1042 {
1014 CHECK_STRING (prompt); 1043 CHECK_STRING (prompt);
1015 if (! NILP (initial))
1016 CHECK_STRING (initial);
1017
1018 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, 1044 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil,
1019 0, Qminibuffer_history, make_number (0), Qnil, 0, 1045 0, Qminibuffer_history, make_number (0), Qnil, 0,
1020 !NILP (inherit_input_method)); 1046 !NILP (inherit_input_method));
1021 } 1047 }
1022 1048
1236 if (STRINGP (eltstring) 1262 if (STRINGP (eltstring)
1237 && SCHARS (string) <= SCHARS (eltstring) 1263 && SCHARS (string) <= SCHARS (eltstring)
1238 && (tem = Fcompare_strings (eltstring, make_number (0), 1264 && (tem = Fcompare_strings (eltstring, make_number (0),
1239 make_number (SCHARS (string)), 1265 make_number (SCHARS (string)),
1240 string, make_number (0), Qnil, 1266 string, make_number (0), Qnil,
1241 completion_ignore_case ?Qt : Qnil), 1267 completion_ignore_case ? Qt : Qnil),
1242 EQ (Qt, tem))) 1268 EQ (Qt, tem)))
1243 { 1269 {
1244 /* Yes. */ 1270 /* Yes. */
1245 Lisp_Object regexps; 1271 Lisp_Object regexps;
1246 Lisp_Object zero; 1272 Lisp_Object zero;
1247 XSETFASTINT (zero, 0); 1273 XSETFASTINT (zero, 0);
1248 1274
1249 /* Ignore this element if it fails to match all the regexps. */ 1275 /* Ignore this element if it fails to match all the regexps. */
1250 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1276 {
1251 regexps = XCDR (regexps)) 1277 int count = SPECPDL_INDEX ();
1252 { 1278 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1253 tem = Fstring_match (XCAR (regexps), eltstring, zero); 1279 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1254 if (NILP (tem)) 1280 regexps = XCDR (regexps))
1255 break; 1281 {
1256 } 1282 tem = Fstring_match (XCAR (regexps), eltstring, zero);
1257 if (CONSP (regexps)) 1283 if (NILP (tem))
1258 continue; 1284 break;
1285 }
1286 unbind_to (count, Qnil);
1287 if (CONSP (regexps))
1288 continue;
1289 }
1259 1290
1260 /* Ignore this element if there is a predicate 1291 /* Ignore this element if there is a predicate
1261 and the predicate doesn't like it. */ 1292 and the predicate doesn't like it. */
1262 1293
1263 if (!NILP (predicate)) 1294 if (!NILP (predicate))
1491 Lisp_Object regexps; 1522 Lisp_Object regexps;
1492 Lisp_Object zero; 1523 Lisp_Object zero;
1493 XSETFASTINT (zero, 0); 1524 XSETFASTINT (zero, 0);
1494 1525
1495 /* Ignore this element if it fails to match all the regexps. */ 1526 /* Ignore this element if it fails to match all the regexps. */
1496 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1527 {
1497 regexps = XCDR (regexps)) 1528 int count = SPECPDL_INDEX ();
1498 { 1529 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1499 tem = Fstring_match (XCAR (regexps), eltstring, zero); 1530 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1500 if (NILP (tem)) 1531 regexps = XCDR (regexps))
1501 break; 1532 {
1502 } 1533 tem = Fstring_match (XCAR (regexps), eltstring, zero);
1503 if (CONSP (regexps)) 1534 if (NILP (tem))
1504 continue; 1535 break;
1536 }
1537 unbind_to (count, Qnil);
1538 if (CONSP (regexps))
1539 continue;
1540 }
1505 1541
1506 /* Ignore this element if there is a predicate 1542 /* Ignore this element if there is a predicate
1507 and the predicate doesn't like it. */ 1543 and the predicate doesn't like it. */
1508 1544
1509 if (!NILP (predicate)) 1545 if (!NILP (predicate))
1535 Lisp_Object Vminibuffer_completing_file_name; 1571 Lisp_Object Vminibuffer_completing_file_name;
1536 1572
1537 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, 1573 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
1538 doc: /* Read a string in the minibuffer, with completion. 1574 doc: /* Read a string in the minibuffer, with completion.
1539 PROMPT is a string to prompt with; normally it ends in a colon and a space. 1575 PROMPT is a string to prompt with; normally it ends in a colon and a space.
1540 TABLE is an alist whose elements' cars are strings, or an obarray. 1576 TABLE can be an list of strings, an alist, an obarray or a hash table.
1541 TABLE can also be a function to do the completion itself. 1577 TABLE can also be a function to do the completion itself.
1542 PREDICATE limits completion to a subset of TABLE. 1578 PREDICATE limits completion to a subset of TABLE.
1543 See `try-completion' and `all-completions' for more details 1579 See `try-completion' and `all-completions' for more details
1544 on completion, TABLE, and PREDICATE. 1580 on completion, TABLE, and PREDICATE.
1545 1581
1546 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless 1582 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
1547 the input is (or completes to) an element of TABLE or is null. 1583 the input is (or completes to) an element of TABLE or is null.
1548 If it is also not t, typing RET does not exit if it does non-null completion. 1584 If it is also not t, typing RET does not exit if it does non-null completion.
1549 If the input is null, `completing-read' returns an empty string, 1585 If the input is null, `completing-read' returns DEF, or an empty string
1550 regardless of the value of REQUIRE-MATCH. 1586 if DEF is nil, regardless of the value of REQUIRE-MATCH.
1551 1587
1552 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially. 1588 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
1553 If it is (STRING . POSITION), the initial input 1589 with point positioned at the end.
1554 is STRING, but point is placed POSITION characters into the string. 1590 If it is (STRING . POSITION), the initial input is STRING, but point
1555 This feature is deprecated--it is best to pass nil for INITIAL-INPUT 1591 is placed at _zero-indexed_ position POSITION in STRING. (*Note*
1556 and supply the default value DEF instead. The user can yank the 1592 that this is different from `read-from-minibuffer' and related
1557 default value into the minibuffer easily using \\[next-history-element]. 1593 functions, which use one-indexing for POSITION.) This feature is
1558 1594 deprecated--it is best to pass nil for INITIAL-INPUT and supply the
1559 HIST, if non-nil, specifies a history list 1595 default value DEF instead. The user can yank the default value into
1560 and optionally the initial position in the list. 1596 the minibuffer easily using \\[next-history-element].
1561 It can be a symbol, which is the history list variable to use, 1597
1562 or it can be a cons cell (HISTVAR . HISTPOS). 1598 HIST, if non-nil, specifies a history list and optionally the initial
1563 In that case, HISTVAR is the history list variable to use, 1599 position in the list. It can be a symbol, which is the history list
1564 and HISTPOS is the initial position (the position in the list 1600 variable to use, or it can be a cons cell (HISTVAR . HISTPOS). In
1565 which INITIAL-INPUT corresponds to). 1601 that case, HISTVAR is the history list variable to use, and HISTPOS
1566 Positions are counted starting from 1 at the beginning of the list. 1602 is the initial position (the position in the list used by the
1567 The variable `history-length' controls the maximum length of a 1603 minibuffer history commands). For consistency, you should also
1568 history list. 1604 specify that element of the history as the value of
1605 INITIAL-CONTENTS. (This is the only case in which you should use
1606 INITIAL-INPUT instead of DEF.) Positions are counted starting from
1607 1 at the beginning of the list. The variable `history-length'
1608 controls the maximum length of a history list.
1569 1609
1570 DEF, if non-nil, is the default value. 1610 DEF, if non-nil, is the default value.
1571 1611
1572 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits 1612 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits
1573 the current input method and the setting of `enable-multibyte-characters'. 1613 the current input method and the setting of `enable-multibyte-characters'.
1648 If ALIST is a function, it is called with three arguments: 1688 If ALIST is a function, it is called with three arguments:
1649 the values STRING, PREDICATE and `lambda'. */) 1689 the values STRING, PREDICATE and `lambda'. */)
1650 (string, alist, predicate) 1690 (string, alist, predicate)
1651 Lisp_Object string, alist, predicate; 1691 Lisp_Object string, alist, predicate;
1652 { 1692 {
1653 Lisp_Object regexps, tem = Qnil; 1693 Lisp_Object regexps, tail, tem = Qnil;
1654 int i = 0; 1694 int i = 0;
1655 1695
1656 CHECK_STRING (string); 1696 CHECK_STRING (string);
1657 1697
1658 if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist)))) 1698 if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist))))
1674 if (STRING_MULTIBYTE (string)) 1714 if (STRING_MULTIBYTE (string))
1675 string = Fstring_make_unibyte (string); 1715 string = Fstring_make_unibyte (string);
1676 else 1716 else
1677 string = Fstring_make_multibyte (string); 1717 string = Fstring_make_multibyte (string);
1678 1718
1679 tem = oblookup (Vminibuffer_completion_table, 1719 tem = oblookup (alist,
1680 SDATA (string), 1720 SDATA (string),
1681 SCHARS (string), 1721 SCHARS (string),
1682 SBYTES (string)); 1722 SBYTES (string));
1683 if (!SYMBOLP (tem))
1684 return Qnil;
1685 } 1723 }
1724
1725 if (completion_ignore_case && !SYMBOLP (tem))
1726 {
1727 for (i = XVECTOR (alist)->size - 1; i >= 0; i--)
1728 {
1729 tail = XVECTOR (alist)->contents[i];
1730 if (SYMBOLP (tail))
1731 while (1)
1732 {
1733 if (EQ((Fcompare_strings (string, make_number (0), Qnil,
1734 Fsymbol_name (tail),
1735 make_number (0) , Qnil, Qt)),
1736 Qt))
1737 {
1738 tem = tail;
1739 break;
1740 }
1741 if (XSYMBOL (tail)->next == 0)
1742 break;
1743 XSETSYMBOL (tail, XSYMBOL (tail)->next);
1744 }
1745 }
1746 }
1747
1748 if (!SYMBOLP (tem))
1749 return Qnil;
1686 } 1750 }
1687 else if (HASH_TABLE_P (alist)) 1751 else if (HASH_TABLE_P (alist))
1688 { 1752 {
1689 i = hash_lookup (XHASH_TABLE (alist), string, NULL); 1753 struct Lisp_Hash_Table *h = XHASH_TABLE (alist);
1754 i = hash_lookup (h, string, NULL);
1690 if (i >= 0) 1755 if (i >= 0)
1691 tem = HASH_KEY (XHASH_TABLE (alist), i); 1756 tem = HASH_KEY (h, i);
1692 else 1757 else
1758 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1759 if (!NILP (HASH_HASH (h, i)) &&
1760 EQ (Fcompare_strings (string, make_number (0), Qnil,
1761 HASH_KEY (h, i), make_number (0) , Qnil,
1762 completion_ignore_case ? Qt : Qnil),
1763 Qt))
1764 {
1765 tem = HASH_KEY (h, i);
1766 break;
1767 }
1768 if (!STRINGP (tem))
1693 return Qnil; 1769 return Qnil;
1694 } 1770 }
1695 else 1771 else
1696 return call3 (alist, string, predicate, Qlambda); 1772 return call3 (alist, string, predicate, Qlambda);
1697 1773
1698 /* Reject this element if it fails to match all the regexps. */ 1774 /* Reject this element if it fails to match all the regexps. */
1699 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1775 {
1700 regexps = XCDR (regexps)) 1776 int count = SPECPDL_INDEX ();
1701 { 1777 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1702 if (NILP (Fstring_match (XCAR (regexps), 1778 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1703 SYMBOLP (tem) ? string : tem, 1779 regexps = XCDR (regexps))
1704 Qnil))) 1780 {
1705 return Qnil; 1781 if (NILP (Fstring_match (XCAR (regexps),
1706 } 1782 SYMBOLP (tem) ? string : tem,
1783 Qnil)))
1784 return unbind_to (count, Qnil);
1785 }
1786 unbind_to (count, Qnil);
1787 }
1707 1788
1708 /* Finally, check the predicate. */ 1789 /* Finally, check the predicate. */
1709 if (!NILP (predicate)) 1790 if (!NILP (predicate))
1710 return HASH_TABLE_P (alist) 1791 {
1711 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i)) 1792 return HASH_TABLE_P (alist)
1712 : call1 (predicate, tem); 1793 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i))
1794 : call1 (predicate, tem);
1795 }
1713 else 1796 else
1714 return Qt; 1797 return Qt;
1715 } 1798 }
1716 1799
1717 /* returns: 1800 /* returns:
2159 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list, 2242 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
2160 1, 1, 0, 2243 1, 1, 0,
2161 doc: /* Display the list of completions, COMPLETIONS, using `standard-output'. 2244 doc: /* Display the list of completions, COMPLETIONS, using `standard-output'.
2162 Each element may be just a symbol or string 2245 Each element may be just a symbol or string
2163 or may be a list of two strings to be printed as if concatenated. 2246 or may be a list of two strings to be printed as if concatenated.
2247 If it is a list of two strings, the first is the actual completion
2248 alternative, the second serves as annotation.
2164 `standard-output' must be a buffer. 2249 `standard-output' must be a buffer.
2165 The actual completion alternatives, as inserted, are given `mouse-face' 2250 The actual completion alternatives, as inserted, are given `mouse-face'
2166 properties of `highlight'. 2251 properties of `highlight'.
2167 At the end, this runs the normal hook `completion-setup-hook'. 2252 At the end, this runs the normal hook `completion-setup-hook'.
2168 It can find the completion buffer in `standard-output'. */) 2253 It can find the completion buffer in `standard-output'. */)
2199 Lisp_Object startpos, endpos; 2284 Lisp_Object startpos, endpos;
2200 2285
2201 startpos = Qnil; 2286 startpos = Qnil;
2202 2287
2203 elt = Fcar (tail); 2288 elt = Fcar (tail);
2289 if (SYMBOLP (elt))
2290 elt = SYMBOL_NAME (elt);
2204 /* Compute the length of this element. */ 2291 /* Compute the length of this element. */
2205 if (CONSP (elt)) 2292 if (CONSP (elt))
2206 { 2293 {
2207 tem = XCAR (elt); 2294 tem = XCAR (elt);
2208 CHECK_STRING (tem); 2295 CHECK_STRING (tem);
2510 staticpro (&Qcurrent_input_method); 2597 staticpro (&Qcurrent_input_method);
2511 2598
2512 Qactivate_input_method = intern ("activate-input-method"); 2599 Qactivate_input_method = intern ("activate-input-method");
2513 staticpro (&Qactivate_input_method); 2600 staticpro (&Qactivate_input_method);
2514 2601
2602 Qcase_fold_search = intern ("case-fold-search");
2603 staticpro (&Qcase_fold_search);
2604
2515 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function, 2605 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function,
2516 doc: /* If this is non-nil, `read-buffer' does its work by calling this function. */); 2606 doc: /* If this is non-nil, `read-buffer' does its work by calling this function. */);
2517 Vread_buffer_function = Qnil; 2607 Vread_buffer_function = Qnil;
2518 2608
2519 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook, 2609 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook,
2544 This variable makes a difference whenever the minibuffer window is active. */); 2634 This variable makes a difference whenever the minibuffer window is active. */);
2545 enable_recursive_minibuffers = 0; 2635 enable_recursive_minibuffers = 0;
2546 2636
2547 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table, 2637 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
2548 doc: /* Alist or obarray used for completion in the minibuffer. 2638 doc: /* Alist or obarray used for completion in the minibuffer.
2549 This becomes the ALIST argument to `try-completion' and `all-completion'. 2639 This becomes the ALIST argument to `try-completion' and `all-completions'.
2640 The value can also be a list of strings or a hash table.
2550 2641
2551 The value may alternatively be a function, which is given three arguments: 2642 The value may alternatively be a function, which is given three arguments:
2552 STRING, the current buffer contents; 2643 STRING, the current buffer contents;
2553 PREDICATE, the predicate for filtering possible matches; 2644 PREDICATE, the predicate for filtering possible matches;
2554 CODE, which says what kind of things to do. 2645 CODE, which says what kind of things to do.
2591 doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame. 2682 doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame.
2592 Some uses of the echo area also raise that frame (since they use it too). */); 2683 Some uses of the echo area also raise that frame (since they use it too). */);
2593 minibuffer_auto_raise = 0; 2684 minibuffer_auto_raise = 0;
2594 2685
2595 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list, 2686 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list,
2596 doc: /* List of regexps that should restrict possible completions. */); 2687 doc: /* List of regexps that should restrict possible completions.
2688 The basic completion functions only consider a completion acceptable
2689 if it matches all regular expressions in this list, with
2690 `case-fold-search' bound to the value of `completion-ignore-case'.
2691 See Info node `(elisp)Basic Completion', for a description of these
2692 functions. */);
2597 Vcompletion_regexp_list = Qnil; 2693 Vcompletion_regexp_list = Qnil;
2598 2694
2599 DEFVAR_BOOL ("minibuffer-allow-text-properties", 2695 DEFVAR_BOOL ("minibuffer-allow-text-properties",
2600 &minibuffer_allow_text_properties, 2696 &minibuffer_allow_text_properties,
2601 doc: /* Non-nil means `read-from-minibuffer' should not discard text properties. 2697 doc: /* Non-nil means `read-from-minibuffer' should not discard text properties.
2675 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'), 2771 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'),
2676 "minibuffer-complete-and-exit"); 2772 "minibuffer-complete-and-exit");
2677 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'), 2773 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'),
2678 "minibuffer-complete-and-exit"); 2774 "minibuffer-complete-and-exit");
2679 } 2775 }
2776
2777 /* arch-tag: 8f69b601-fba3-484c-a6dd-ceaee54a7a73
2778 (do not change this comment) */