/* Minibuffer input and completion.
- Copyright (C) 1985,86,93,94,95,96,97,98,99,2000,01,03,04
- Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+ 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Emacs.
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
#include <config.h>
DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end,
Sminibuffer_prompt_end, 0, 0, 0,
doc: /* Return the buffer position of the end of the minibuffer prompt.
-Return (point-min) if current buffer is not a mini-buffer. */)
+Return (point-min) if current buffer is not a minibuffer. */)
()
{
/* This function is written to be most efficient when there's a prompt. */
specbind (Qminibuffer_default, defalt);
- single_kboard_state ();
#ifdef HAVE_X_WINDOWS
if (display_hourglass_p)
cancel_hourglass ();
if (minibuffer_auto_raise)
Fraise_frame (mini_frame);
+ temporarily_switch_to_single_kboard (XFRAME (mini_frame)->device->kboard);
+
/* We have to do this after saving the window configuration
since that is what restores the current buffer. */
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') */)
+arguments are used as in `read-from-minibuffer'.) */)
(prompt, initial_contents)
Lisp_Object prompt, initial_contents;
{
Prompt with PROMPT.
Optional second arg DEF is value to return if user enters an empty line.
If optional third arg REQUIRE-MATCH is non-nil,
- only existing buffer names are allowed. */)
+ only existing buffer names are allowed.
+The argument PROMPT should be a string ending with a colon and a space. */)
(prompt, def, require_match)
Lisp_Object prompt, def, require_match;
{
Lisp_Object args[4];
+ unsigned char *s;
+ int len;
if (BUFFERP (def))
def = XBUFFER (def)->name;
{
if (!NILP (def))
{
- args[0] = build_string ("%s(default %s) ");
+ /* A default value was provided: we must change PROMPT,
+ editing the default value in before the colon. To achieve
+ this, we replace PROMPT with a substring that doesn't
+ contain the terminal space and colon (if present). They
+ are then added back using Fformat. */
+
+ if (STRINGP (prompt))
+ {
+ s = SDATA (prompt);
+ len = strlen (s);
+ if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ')
+ len = len - 2;
+ else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' '))
+ len--;
+
+ prompt = make_specified_string (s, -1, len,
+ STRING_MULTIBYTE (prompt));
+ }
+
+ args[0] = build_string ("%s (default %s): ");
args[1] = prompt;
args[2] = def;
prompt = Fformat (3, args);
|| NILP (alist))
{
tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil);
- if NILP (tem)
+ if (NILP (tem))
return Qnil;
}
else if (VECTORP (alist))
return make_number (1);
}
+EXFUN (Fexit_minibuffer, 0) NO_RETURN;
+
DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit,
Sminibuffer_complete_and_exit, 0, 0, "",
doc: /* If the minibuffer contents is a valid completion then exit.
return Qnil;
}
exit:
- return Fthrow (Qexit, Qnil);
+ return Fexit_minibuffer ();
/* NOTREACHED */
}
{
Lisp_Object completion, tem, tem1;
register int i, i_byte;
- register const unsigned char *completion_string;
struct gcpro gcpro1, gcpro2;
int prompt_end_charpos = XINT (Fminibuffer_prompt_end ());
{
int len, c;
int bytes = SBYTES (completion);
- completion_string = SDATA (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,
}
\f
DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
- 1, 1, 0,
+ 1, 2, 0,
doc: /* Display the list of completions, COMPLETIONS, using `standard-output'.
Each element may be just a symbol or string
or may be a list of two strings to be printed as if concatenated.
The actual completion alternatives, as inserted, are given `mouse-face'
properties of `highlight'.
At the end, this runs the normal hook `completion-setup-hook'.
-It can find the completion buffer in `standard-output'. */)
- (completions)
+It can find the completion buffer in `standard-output'.
+The optional second arg COMMON-SUBSTRING is a string.
+It is used to put faces, `completions-first-difference' and
+`completions-common-part' on the completion buffer. The
+`completions-common-part' face is put on the common substring
+specified by COMMON-SUBSTRING. If COMMON-SUBSTRING is nil,
+the faces are not put.
+Internally, COMMON-SUBSTRING is bound to `completion-common-substring'
+during running `completion-setup-hook'. */)
+ (completions, common_substring)
Lisp_Object completions;
+ Lisp_Object common_substring;
{
Lisp_Object tail, elt;
register int i;
int column = 0;
- struct gcpro gcpro1, gcpro2;
+ struct gcpro gcpro1, gcpro2, gcpro3;
struct buffer *old = current_buffer;
int first = 1;
except for ELT. ELT can be pointing to a string
when terpri or Findent_to calls a change hook. */
elt = Qnil;
- GCPRO2 (completions, elt);
+ GCPRO3 (completions, elt, common_substring);
if (BUFFERP (Vstandard_output))
set_buffer_internal (XBUFFER (Vstandard_output));
}
}
- UNGCPRO;
-
if (BUFFERP (Vstandard_output))
set_buffer_internal (old);
if (!NILP (Vrun_hooks))
- call1 (Vrun_hooks, intern ("completion-setup-hook"));
+ {
+ int count1 = SPECPDL_INDEX ();
+
+ specbind (intern ("completion-common-substring"), common_substring);
+ call1 (Vrun_hooks, intern ("completion-setup-hook"));
+
+ unbind_to (count1, Qnil);
+ }
+
+ UNGCPRO;
return Qnil;
}
+
+static Lisp_Object
+display_completion_list_1 (list)
+ Lisp_Object list;
+{
+ return Fdisplay_completion_list (list, Qnil);
+}
+
DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help,
0, 0, "",
doc: /* Display a list of possible completions of the current minibuffer contents. */)
}
else
internal_with_output_to_temp_buffer ("*Completions*",
- Fdisplay_completion_list,
+ display_completion_list_1,
Fsort (completions, Qstring_lessp));
return Qnil;
}
else
bitch_at_user ();
- return Fthrow (Qexit, Qnil);
+ return Fexit_minibuffer ();
}
DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "",
doc: /* Terminate this minibuffer argument. */)
()
{
- return Fthrow (Qexit, Qnil);
+ /* If the command that uses this has made modifications in the minibuffer,
+ we don't want them to cause deactivation of the mark in the original
+ buffer.
+ A better solution would be to make deactivate-mark buffer-local
+ (or to turn it into a list of buffers, ...), but in the mean time,
+ this should do the trick in most cases. */
+ Vdeactivate_mark = Qnil;
+ Fthrow (Qexit, Qnil);
}
DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0,