/* Minibuffer input and completion.
-Copyright (C) 1985-1986, 1993-2012 Free Software Foundation, Inc.
+Copyright (C) 1985-1986, 1993-2013 Free Software Foundation, Inc.
This file is part of GNU Emacs.
/* Under X, we come here with minibuf_window being the
minibuffer window of the unused termcap window created in
init_window_once. That window doesn't have a buffer. */
- buffer = XWINDOW (minibuf_window)->buffer;
+ buffer = XWINDOW (minibuf_window)->contents;
if (BUFFERP (buffer))
/* Use set_window_buffer instead of Fset_window_buffer (see
discussion of bug#11984, bug#12025, bug#12026). */
}
}
-static Lisp_Object
-choose_minibuf_frame_1 (Lisp_Object ignore)
-{
- choose_minibuf_frame ();
- return Qnil;
-}
-
DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
Sactive_minibuffer_window, 0, 0, 0,
doc: /* Return the currently active minibuffer window, or nil if none. */)
\f
/* Actual minibuffer invocation. */
-static Lisp_Object read_minibuf_unwind (Lisp_Object);
-static Lisp_Object run_exit_minibuf_hook (Lisp_Object);
-static Lisp_Object read_minibuf (Lisp_Object, Lisp_Object,
- Lisp_Object,
- int, Lisp_Object,
- Lisp_Object, Lisp_Object,
- int, int);
-static Lisp_Object read_minibuf_noninteractive (Lisp_Object, Lisp_Object,
- Lisp_Object, Lisp_Object,
- int, Lisp_Object,
- Lisp_Object, Lisp_Object,
- int, int);
-static Lisp_Object string_to_object (Lisp_Object, Lisp_Object);
+static void read_minibuf_unwind (void);
+static void run_exit_minibuf_hook (void);
/* Read a Lisp object from VAL and return it. If VAL is an empty
static Lisp_Object
read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
Lisp_Object prompt, Lisp_Object backup_n,
- int expflag,
+ bool expflag,
Lisp_Object histvar, Lisp_Object histpos,
Lisp_Object defalt,
- int allow_props, int inherit_input_method)
+ bool allow_props, bool inherit_input_method)
{
ptrdiff_t size, len;
char *line;
beginning of INITIAL if N <= 0.
Normally return the result as a string (the text that was read),
- but if EXPFLAG is nonzero, read it and return the object read.
+ but if EXPFLAG, read it and return the object read.
If HISTVAR is given, save the value read on that history only if it doesn't
match the front of that history list exactly. The value is pushed onto
the list as the string that was read.
DEFALT specifies the default value for the sake of history commands.
- If ALLOW_PROPS is nonzero, we do not throw away text properties.
+ If ALLOW_PROPS, do not throw away text properties.
- if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the
+ if INHERIT_INPUT_METHOD, the minibuffer inherits the
current input method. */
static Lisp_Object
read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
- int expflag,
+ bool expflag,
Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt,
- int allow_props, int inherit_input_method)
+ bool allow_props, bool inherit_input_method)
{
Lisp_Object val;
ptrdiff_t count = SPECPDL_INDEX ();
/* Choose the minibuffer window and frame, and take action on them. */
+ /* Prepare for restoring the current buffer since choose_minibuf_frame
+ calling Fset_frame_selected_window may change it (Bug#12766). */
+ record_unwind_protect (restore_buffer, Fcurrent_buffer ());
+
choose_minibuf_frame ();
- record_unwind_protect (choose_minibuf_frame_1, Qnil);
+ record_unwind_protect_void (choose_minibuf_frame);
- record_unwind_protect (Fset_window_configuration,
+ record_unwind_protect (restore_window_configuration,
Fcurrent_window_configuration (Qnil));
/* If the minibuffer window is on a different frame, save that
frame's configuration too. */
mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
if (!EQ (mini_frame, selected_frame))
- record_unwind_protect (Fset_window_configuration,
+ record_unwind_protect (restore_window_configuration,
Fcurrent_window_configuration (mini_frame));
/* If the minibuffer is on an iconified or invisible frame,
Fcons (Vminibuffer_history_variable,
minibuf_save_list))))));
- record_unwind_protect (read_minibuf_unwind, Qnil);
+ record_unwind_protect_void (read_minibuf_unwind);
minibuf_level++;
/* We are exiting the minibuffer one way or the other, so run the hook.
It should be run before unwinding the minibuf settings. Do it
separately from read_minibuf_unwind because we need to make sure that
read_minibuf_unwind is fully executed even if exit-minibuffer-hook
signals an error. --Stef */
- record_unwind_protect (run_exit_minibuf_hook, Qnil);
+ record_unwind_protect_void (run_exit_minibuf_hook);
/* Now that we can restore all those variables, start changing them. */
bset_directory (current_buffer, ambient_dir);
else
{
- Lisp_Object buf_list;
-
- for (buf_list = Vbuffer_alist;
- CONSP (buf_list);
- buf_list = XCDR (buf_list))
- {
- Lisp_Object other_buf;
+ Lisp_Object tail, buf;
- other_buf = XCDR (XCAR (buf_list));
- if (STRINGP (BVAR (XBUFFER (other_buf), directory)))
- {
- bset_directory (current_buffer,
- BVAR (XBUFFER (other_buf), directory));
- break;
- }
- }
+ FOR_EACH_LIVE_BUFFER (tail, buf)
+ if (STRINGP (BVAR (XBUFFER (buf), directory)))
+ {
+ bset_directory (current_buffer,
+ BVAR (XBUFFER (buf), directory));
+ break;
+ }
}
if (!EQ (mini_frame, selected_frame))
XWINDOW (minibuf_window)->cursor.x = 0;
XWINDOW (minibuf_window)->must_be_updated_p = 1;
update_frame (XFRAME (selected_frame), 1, 1);
- {
- struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame);
- struct redisplay_interface *rif = FRAME_RIF (f);
- if (rif && rif->flush_display)
- rif->flush_display (f);
- }
+ flush_frame (XFRAME (XWINDOW (minibuf_window)->frame));
}
/* Make minibuffer contents into a string. */
tail = Fnthcdr (num, Vminibuffer_list);
if (NILP (tail))
{
- tail = Fcons (Qnil, Qnil);
+ tail = list1 (Qnil);
Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
}
buf = Fcar (tail);
return buf;
}
-static Lisp_Object
-run_exit_minibuf_hook (Lisp_Object data)
+static void
+run_exit_minibuf_hook (void)
{
safe_run_hooks (Qminibuffer_exit_hook);
- return Qnil;
}
/* This function is called on exiting minibuffer, whether normally or
not, and it restores the current window, buffer, etc. */
-static Lisp_Object
-read_minibuf_unwind (Lisp_Object data)
+static void
+read_minibuf_unwind (void)
{
Lisp_Object old_deactivate_mark;
Lisp_Object window;
window = minibuf_window;
/* To keep things predictable, in case it matters, let's be in the
minibuffer when we reset the relevant variables. */
- Fset_buffer (XWINDOW (window)->buffer);
+ Fset_buffer (XWINDOW (window)->contents);
/* Restore prompt, etc, from outer minibuffer level. */
minibuf_prompt = Fcar (minibuf_save_list);
if (minibuf_level == 0)
resize_mini_window (XWINDOW (window), 0);
- /* Make sure minibuffer window is erased, not ignored. */
- windows_or_buffers_changed++;
- XWINDOW (window)->last_modified = 0;
- XWINDOW (window)->last_overlay_modified = 0;
-
/* In case the previous minibuffer displayed in this miniwindow is
dead, we may keep displaying this buffer (tho it's inactive), so reset it,
to make sure we don't leave around bindings and stuff which only
made sense during the read_minibuf invocation. */
call0 (intern ("minibuffer-inactive-mode"));
- return Qnil;
}
\f
return val;
}
-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'.) */)
- (Lisp_Object prompt, Lisp_Object initial_contents)
-{
- CHECK_STRING (prompt);
- return read_minibuf (Vminibuffer_local_map, initial_contents,
- prompt, 1, Qminibuffer_history,
- make_number (0), Qnil, 0, 0);
-}
-
-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'.) */)
- (Lisp_Object prompt, Lisp_Object initial_contents)
-{
- return Feval (read_minibuf (Vread_expression_map, initial_contents,
- prompt, 1, Qread_expression_history,
- make_number (0), Qnil, 0, 0),
- Qnil);
-}
-
/* Functions that use the minibuffer to read various things. */
DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
type = (HASH_TABLE_P (collection) ? hash_table
: VECTORP (collection) ? obarray_table
: ((NILP (collection)
- || (CONSP (collection)
- && (!SYMBOLP (XCAR (collection))
- || NILP (XCAR (collection)))))
+ || (CONSP (collection) && !FUNCTIONP (collection)))
? list_table : function_table));
ptrdiff_t idx = 0, obsize = 0;
int matchcount = 0;
eltstring, zero,
make_number (compare),
completion_ignore_case ? Qt : Qnil);
- if (EQ (tem, Qt))
- matchsize = compare;
- else if (XINT (tem) < 0)
- matchsize = - XINT (tem) - 1;
- else
- matchsize = XINT (tem) - 1;
+ matchsize = EQ (tem, Qt) ? compare : eabs (XINT (tem)) - 1;
if (completion_ignore_case)
{
if (bestmatchsize != SCHARS (eltstring)
|| bestmatchsize != matchsize)
/* Don't count the same string multiple times. */
- matchcount++;
+ matchcount += matchcount <= 1;
bestmatchsize = matchsize;
if (matchsize <= SCHARS (string)
/* If completion-ignore-case is non-nil, don't
Lisp_Object allmatches;
int type = HASH_TABLE_P (collection) ? 3
: VECTORP (collection) ? 2
- : NILP (collection) || (CONSP (collection)
- && (!SYMBOLP (XCAR (collection))
- || NILP (XCAR (collection))));
+ : NILP (collection) || (CONSP (collection) && !FUNCTIONP (collection));
ptrdiff_t idx = 0, obsize = 0;
ptrdiff_t bindcount = -1;
Lisp_Object bucket, tem, zero;
functions, which use one-indexing for POSITION.) This feature is
deprecated--it is best to pass nil for INITIAL-INPUT and supply the
default value DEF instead. The user can yank the default value into
- the minibuffer easily using \\[next-history-element].
+ the minibuffer easily using \\<minibuffer-local-map>\\[next-history-element].
HIST, if non-nil, specifies a history list and optionally the initial
position in the list. It can be a symbol, which is the history list
CHECK_STRING (string);
- if ((CONSP (collection)
- && (!SYMBOLP (XCAR (collection)) || NILP (XCAR (collection))))
- || NILP (collection))
+ if (NILP (collection) || (CONSP (collection) && !FUNCTIONP (collection)))
{
tem = Fassoc_string (string, collection, completion_ignore_case ? Qt : Qnil);
if (NILP (tem))
else if (HASH_TABLE_P (collection))
{
struct Lisp_Hash_Table *h = XHASH_TABLE (collection);
+ Lisp_Object key = Qnil;
i = hash_lookup (h, string, NULL);
if (i >= 0)
tem = HASH_KEY (h, i);
else
for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
if (!NILP (HASH_HASH (h, i))
+ && (key = HASH_KEY (h, i),
+ SYMBOLP (key) ? key = Fsymbol_name (key) : key,
+ STRINGP (key))
&& EQ (Fcompare_strings (string, make_number (0), Qnil,
- HASH_KEY (h, i), make_number (0) , Qnil,
+ key, make_number (0) , Qnil,
completion_ignore_case ? Qt : Qnil),
Qt))
{
- tem = HASH_KEY (h, i);
+ tem = key;
break;
}
if (!STRINGP (tem))
else if (EQ (flag, Qlambda))
return Ftest_completion (string, Vbuffer_alist, predicate);
else if (EQ (flag, Qmetadata))
- return Fcons (Qmetadata, Fcons (Fcons (Qcategory, Qbuffer), Qnil));
+ return list2 (Qmetadata, Fcons (Qcategory, Qbuffer));
else
return Qnil;
}
properties. */);
/* We use `intern' here instead of Qread_only to avoid
initialization-order problems. */
- Vminibuffer_prompt_properties
- = Fcons (intern_c_string ("read-only"), Fcons (Qt, Qnil));
-
- DEFVAR_LISP ("read-expression-map", Vread_expression_map,
- doc: /* Minibuffer keymap used for reading Lisp expressions. */);
- Vread_expression_map = Qnil;
+ Vminibuffer_prompt_properties = list2 (intern_c_string ("read-only"), Qt);
defsubr (&Sactive_minibuffer_window);
defsubr (&Sset_minibuffer_window);
defsubr (&Sread_from_minibuffer);
- defsubr (&Seval_minibuffer);
- defsubr (&Sread_minibuffer);
defsubr (&Sread_string);
defsubr (&Sread_command);
defsubr (&Sread_variable);