X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/49b23c2a404cf31fb1aeecc7932a7304aaf16a67..0e2501ed344f5c8e251bcdca981f5d81dd78f663:/src/minibuf.c diff --git a/src/minibuf.c b/src/minibuf.c index c84c83c1c8..86dd095fa2 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1,7 +1,7 @@ /* Minibuffer input and completion. Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007 Free Software Foundation, Inc. + 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -27,7 +27,7 @@ Boston, MA 02110-1301, USA. */ #include "lisp.h" #include "commands.h" #include "buffer.h" -#include "charset.h" +#include "character.h" #include "dispextern.h" #include "keyboard.h" #include "frame.h" @@ -118,6 +118,7 @@ Lisp_Object Vread_buffer_function; /* Nonzero means completion ignores case. */ int completion_ignore_case; +Lisp_Object Qcompletion_ignore_case; /* List of regexps that should restrict possible completions. */ @@ -256,9 +257,13 @@ string_to_object (val, defalt) GCPRO2 (val, defalt); - if (STRINGP (val) && SCHARS (val) == 0 - && STRINGP (defalt)) - val = defalt; + if (STRINGP (val) && SCHARS (val) == 0) + { + if (STRINGP (defalt)) + val = defalt; + else if (CONSP (defalt) && STRINGP (XCAR (defalt))) + val = XCAR (defalt); + } expr_and_pos = Fread_from_string (val, Qnil, Qnil); pos = XINT (Fcdr (expr_and_pos)); @@ -336,7 +341,7 @@ read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag, /* If Lisp form desired instead of string, parse it. */ if (expflag) - val = string_to_object (val, defalt); + val = string_to_object (val, CONSP (defalt) ? XCAR (defalt) : defalt); return val; } @@ -784,6 +789,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag, histstring = val; else if (STRINGP (defalt)) histstring = defalt; + else if (CONSP (defalt) && STRINGP (XCAR (defalt))) + histstring = XCAR (defalt); else histstring = Qnil; @@ -1051,8 +1058,8 @@ DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, doc: /* Return a Lisp object read using the minibuffer, unevaluated. Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS is a string to insert in the minibuffer before reading. -\(INITIAL-CONTENTS can also be a cons of a string and an integer. Such -arguments are used as in `read-from-minibuffer'.) */) +\(INITIAL-CONTENTS can also be a cons of a string and an integer. +Such arguments are used as in `read-from-minibuffer'.) */) (prompt, initial_contents) Lisp_Object prompt, initial_contents; { @@ -1066,8 +1073,8 @@ DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, doc: /* Return value of Lisp expression read using the minibuffer. Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS is a string to insert in the minibuffer before reading. -\(INITIAL-CONTENTS can also be a cons of a string and an integer. Such -arguments are used as in `read-from-minibuffer'.) */) +\(INITIAL-CONTENTS can also be a cons of a string and an integer. +Such arguments are used as in `read-from-minibuffer'.) */) (prompt, initial_contents) Lisp_Object prompt, initial_contents; { @@ -1101,7 +1108,7 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits Qnil, history, default_value, inherit_input_method); if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) - val = default_value; + val = CONSP (default_value) ? XCAR (default_value) : default_value; return val; } @@ -1224,7 +1231,7 @@ The argument PROMPT should be a string ending with a colon and a space. */) args[0] = build_string ("%s (default %s): "); args[1] = prompt; - args[2] = def; + args[2] = CONSP (def) ? XCAR (def) : def; prompt = Fformat (3, args); } @@ -1294,11 +1301,14 @@ is used to further constrain the set of candidates. */) int bestmatchsize = 0; /* These are in bytes, too. */ int compare, matchsize; - int type = (HASH_TABLE_P (collection) ? 3 - : VECTORP (collection) ? 2 - : NILP (collection) || (CONSP (collection) - && (!SYMBOLP (XCAR (collection)) - || NILP (XCAR (collection))))); + enum { function_table, list_table, obarray_table, hash_table} + type = (HASH_TABLE_P (collection) ? hash_table + : VECTORP (collection) ? obarray_table + : ((NILP (collection) + || (CONSP (collection) + && (!SYMBOLP (XCAR (collection)) + || NILP (XCAR (collection))))) + ? list_table : function_table)); int index = 0, obsize = 0; int matchcount = 0; int bindcount = -1; @@ -1306,7 +1316,7 @@ is used to further constrain the set of candidates. */) struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; CHECK_STRING (string); - if (type == 0) + if (type == function_table) return call3 (collection, string, predicate, Qnil); bestmatch = bucket = Qnil; @@ -1314,7 +1324,7 @@ is used to further constrain the set of candidates. */) /* If COLLECTION is not a list, set TAIL just for gc pro. */ tail = collection; - if (type == 2) + if (type == obarray_table) { collection = check_obarray (collection); obsize = XVECTOR (collection)->size; @@ -1328,7 +1338,7 @@ is used to further constrain the set of candidates. */) /* elt gets the alist element or symbol. eltstring gets the name to check as a completion. */ - if (type == 1) + if (type == list_table) { if (!CONSP (tail)) break; @@ -1336,7 +1346,7 @@ is used to further constrain the set of candidates. */) eltstring = CONSP (elt) ? XCAR (elt) : elt; tail = XCDR (tail); } - else if (type == 2) + else if (type == obarray_table) { if (!EQ (bucket, zero)) { @@ -1357,7 +1367,7 @@ is used to further constrain the set of candidates. */) continue; } } - else /* if (type == 3) */ + else /* if (type == hash_table) */ { while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection)) && NILP (HASH_HASH (XHASH_TABLE (collection), index))) @@ -1411,15 +1421,17 @@ is used to further constrain the set of candidates. */) tem = Fcommandp (elt, Qnil); else { - if (bindcount >= 0) { - unbind_to (bindcount, Qnil); - bindcount = -1; - } + if (bindcount >= 0) + { + unbind_to (bindcount, Qnil); + bindcount = -1; + } GCPRO4 (tail, string, eltstring, bestmatch); - tem = type == 3 - ? call2 (predicate, elt, - HASH_VALUE (XHASH_TABLE (collection), index - 1)) - : call1 (predicate, elt); + tem = (type == hash_table + ? call2 (predicate, elt, + HASH_VALUE (XHASH_TABLE (collection), + index - 1)) + : call1 (predicate, elt)); UNGCPRO; } if (NILP (tem)) continue; @@ -1829,7 +1841,7 @@ Completion ignores case if the ambient value of !NILP (inherit_input_method)); if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) - val = def; + val = CONSP (def) ? XCAR (def) : def; RETURN_UNGCPRO (unbind_to (count, val)); } @@ -2104,10 +2116,10 @@ string rather than a cons cell whose car is a string. */) if (SYMBOLP (key)) key = Fsymbol_name (key); - for (tail = list; !NILP (tail); tail = Fcdr (tail)) + for (tail = list; CONSP (tail); tail = XCDR (tail)) { register Lisp_Object elt, tem, thiscar; - elt = Fcar (tail); + elt = XCAR (tail); thiscar = CONSP (elt) ? XCAR (elt) : elt; if (SYMBOLP (thiscar)) thiscar = Fsymbol_name (thiscar); @@ -2420,23 +2432,14 @@ Return nil if there is no valid completion, else t. */) /* Now find first word-break in the stuff found by completion. i gets index in string of where to stop completing. */ - { - int len, c; - int bytes = SBYTES (completion); - register const unsigned char *completion_string = SDATA (completion); - for (; i_byte < SBYTES (completion); i_byte += len, i++) - { - c = STRING_CHAR_AND_LENGTH (completion_string + i_byte, - bytes - i_byte, - len); - if (SYNTAX (c) != Sword) - { - i_byte += len; - i++; - break; - } - } - } + while (i_byte < SBYTES (completion)) + { + int c; + + FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, completion, i, i_byte); + if (SYNTAX (c) != Sword) + break; + } /* If got no characters, print help for user. */ @@ -2716,7 +2719,7 @@ DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, doc: /* Terminate minibuffer input. */) () { - if (INTEGERP (last_command_char)) + if (CHARACTERP (last_command_char)) internal_self_insert (XINT (last_command_char), 0); else bitch_at_user (); @@ -2826,6 +2829,9 @@ syms_of_minibuf () minibuf_save_list = Qnil; staticpro (&minibuf_save_list); + Qcompletion_ignore_case = intern ("completion-ignore-case"); + staticpro (&Qcompletion_ignore_case); + Qread_file_name_internal = intern ("read-file-name-internal"); staticpro (&Qread_file_name_internal);