Fix typos in comments.
[bpt/emacs.git] / src / minibuf.c
index 7c22b6b..06e2fc5 100644 (file)
@@ -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,
-                 2008  Free Software Foundation, Inc.
+                 2008, 2009  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -21,6 +21,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <stdio.h>
+#include <setjmp.h>
 
 #include "lisp.h"
 #include "commands.h"
@@ -113,6 +114,7 @@ Lisp_Object Vread_buffer_function;
 
 int completion_ignore_case;
 Lisp_Object Qcompletion_ignore_case;
+int read_buffer_completion_ignore_case;
 
 /* List of regexps that should restrict possible completions.  */
 
@@ -186,7 +188,7 @@ choose_minibuf_frame ()
       if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (XFRAME (frame))))
          && !(EQ (frame, selected_frame)
               && minibuf_level > 0))
-       Fset_frame_selected_window (frame, Fframe_first_window (frame));
+       Fset_frame_selected_window (frame, Fframe_first_window (frame), Qnil);
   }
 }
 
@@ -524,7 +526,11 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
                build_string ("Command attempted to use minibuffer while in minibuffer"));
     }
 
-  if (noninteractive && NILP (Vexecuting_kbd_macro))
+  if ((noninteractive
+       /* In case we are running as a daemon, only do this before
+         detaching from the terminal.  */
+       || (IS_DAEMON && (daemon_pipe[1] >= 0)))
+      && NILP (Vexecuting_kbd_macro))
     {
       val = read_minibuf_noninteractive (map, initial, prompt,
                                         make_number (pos),
@@ -1176,19 +1182,28 @@ DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
 Prompt with PROMPT.
 Optional second arg DEF is value to return if user enters an empty line.
  If DEF is a list of default values, return its first element.
-If optional third arg REQUIRE-MATCH is non-nil,
- only existing buffer names are allowed.
-The argument PROMPT should be a string ending with a colon and a space.  */)
+Optional third arg REQUIRE-MATCH determines whether non-existing
+ buffer names are allowed.  It has the same meaning as the
+ REQUIRE-MATCH argument of `confirm-after-completion'.
+The argument PROMPT should be a string ending with a colon and a space.
+If `read-buffer-completion-ignore-case' is non-nil, completion ignores
+case while reading the buffer name.
+If `read-buffer-function' is non-nil, this works by calling it as a
+function, instead of the usual behavior.  */)
      (prompt, def, require_match)
      Lisp_Object prompt, def, require_match;
 {
-  Lisp_Object args[4];
+  Lisp_Object args[4], result;
   unsigned char *s;
   int len;
+  int count = SPECPDL_INDEX ();
 
   if (BUFFERP (def))
     def = XBUFFER (def)->name;
 
+  specbind (Qcompletion_ignore_case,
+           read_buffer_completion_ignore_case ? Qt : Qnil);
+
   if (NILP (Vread_buffer_function))
     {
       if (!NILP (def))
@@ -1218,9 +1233,9 @@ The argument PROMPT should be a string ending with a colon and a space.  */)
          prompt = Fformat (3, args);
        }
 
-      return Fcompleting_read (prompt, intern ("internal-complete-buffer"),
-                              Qnil, require_match, Qnil, Qbuffer_name_history,
-                              def, Qnil);
+      result = Fcompleting_read (prompt, intern ("internal-complete-buffer"),
+                                Qnil, require_match, Qnil, Qbuffer_name_history,
+                                def, Qnil);
     }
   else
     {
@@ -1228,8 +1243,9 @@ The argument PROMPT should be a string ending with a colon and a space.  */)
       args[1] = prompt;
       args[2] = def;
       args[3] = require_match;
-      return Ffuncall(4, args);
+      result = Ffuncall(4, args);
     }
+  return unbind_to (count, result);
 }
 \f
 static Lisp_Object
@@ -1508,13 +1524,7 @@ is used to further constrain the set of candidates.  */)
 
   /* Return t if the supplied string is an exact match (counting case);
      it does not require any change to be made.  */
-  if (matchcount == 1 && bestmatchsize == SCHARS (string)
-      && (tem = Fcompare_strings (bestmatch, make_number (0),
-                                 make_number (bestmatchsize),
-                                 string, make_number (0),
-                                 make_number (bestmatchsize),
-                                 Qnil),
-         EQ (Qt, tem)))
+  if (matchcount == 1 && !NILP (Fequal (bestmatch, string)))
     return Qt;
 
   XSETFASTINT (zero, 0);               /* Else extract the part in which */
@@ -1551,9 +1561,9 @@ predicate is called with two arguments: the key and the value.
 Additionally to this predicate, `completion-regexp-list'
 is used to further constrain the set of candidates.
 
-If the optional fourth argument HIDE-SPACES is non-nil,
-strings in COLLECTION that start with a space
-are ignored unless STRING itself starts with a space.  */)
+An osbolete optional fourth argument HIDE-SPACES is still accepted for
+backward compatibility.  If non-nil, strings in COLLECTION that start
+with a space are ignored unless STRING itself starts with a space.  */)
      (string, collection, predicate, hide_spaces)
      Lisp_Object string, collection, predicate, hide_spaces;
 {
@@ -1719,8 +1729,12 @@ REQUIRE-MATCH can take the following values:
 - t means that the user is not allowed to exit unless
   the input is (or completes to) an element of COLLECTION or is null.
 - nil means that the user can exit with any input.
-- `confirm-only' means that the user can exit with any input, but she will
-  need to confirm her choice if the input is not an element of COLLECTION.
+- `confirm' means that the user can exit with any input, but she needs
+  to confirm her choice if the input is not an element of COLLECTION.
+- `confirm-after-completion' means that the user can exit with any
+  input, but she needs to confirm her choice if she called
+  `minibuffer-complete' right before `minibuffer-complete-and-exit'
+  and the input is not an element of COLLECTION.
 - anything else behaves like t except that typing RET does not exit if it
   does non-null completion.
 
@@ -2117,6 +2131,11 @@ syms_of_minibuf ()
               doc: /* If this is non-nil, `read-buffer' does its work by calling this function.  */);
   Vread_buffer_function = Qnil;
 
+  DEFVAR_BOOL ("read-buffer-completion-ignore-case",
+              &read_buffer_completion_ignore_case,
+              doc: /* *Non-nil means completion ignores case when reading a buffer name.  */);
+  read_buffer_completion_ignore_case = 0;
+
   DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook,
               doc: /* Normal hook run just after entry to minibuffer.  */);
   Vminibuffer_setup_hook = Qnil;
@@ -2147,8 +2166,9 @@ history list, so it is possible to do this afterwards by calling
 
   DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case,
               doc: /* Non-nil means don't consider case significant in completion.
-
-For file-name completion, the variable `read-file-name-completion-ignore-case'
+For file-name completion, `read-file-name-completion-ignore-case'
+controls the behavior, rather than this variable.
+For buffer name completion, `read-buffer-completion-ignore-case'
 controls the behavior, rather than this variable.  */);
   completion_ignore_case = 0;
 
@@ -2177,7 +2197,14 @@ CODE can be nil, t or `lambda':
   Vminibuffer_completion_predicate = Qnil;
 
   DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm,
-              doc: /* Non-nil means to demand confirmation of completion before exiting minibuffer.  */);
+              doc: /* Whether to demand confirmation of completion before exiting minibuffer.
+If nil, confirmation is not required.
+If the value is `confirm', the user may exit with an input that is not
+ a valid completion alternative, but Emacs asks for confirmation.
+If the value is `confirm-after-completion', the user may exit with an
+ input that is not a valid completion alternative, but Emacs asks for
+ confirmation if the user submitted the input right after any of the
+ completion commands listed in `minibuffer-confirm-exit-commands'.  */);
   Vminibuffer_completion_confirm = Qnil;
 
   DEFVAR_LISP ("minibuffer-completing-file-name",