]> code.delx.au - gnu-emacs/blobdiff - src/minibuf.c
* lisp.h (is_daemon): Declare.
[gnu-emacs] / src / minibuf.c
index 71edfbd528133cbed2bb36ba6883bacfdbf74f6a..205ee5851fd07b010ab8b6dbbbc3e0982ad65ff4 100644 (file)
@@ -1,14 +1,14 @@
 /* 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.
+   Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+                 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+                 200 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,9 +16,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 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., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
@@ -115,6 +113,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.  */
 
@@ -783,10 +782,10 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
       Lisp_Object histval;
 
       /* If variable is unbound, make it nil.  */
-      if (EQ (SYMBOL_VALUE (Vminibuffer_history_variable), Qunbound))
-       Fset (Vminibuffer_history_variable, Qnil);
 
-      histval = Fsymbol_value (Vminibuffer_history_variable);
+      histval = find_symbol_value (Vminibuffer_history_variable);
+      if (EQ (histval, Qunbound))
+       Fset (Vminibuffer_history_variable, Qnil);
 
       /* The value of the history variable must be a cons or nil.  Other
         values are unacceptable.  We silently ignore these values.  */
@@ -1180,17 +1179,25 @@ 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.  */)
+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))
@@ -1220,9 +1227,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
     {
@@ -1230,8 +1237,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
@@ -1445,9 +1453,6 @@ is used to further constrain the set of candidates.  */)
              else
                matchsize = XINT (tem) - 1;
 
-             if (matchsize < 0)
-               /* When can this happen ?  -stef  */
-               matchsize = compare;
              if (completion_ignore_case)
                {
                  /* If this is an exact match except for case,
@@ -1513,13 +1518,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 */
@@ -1820,7 +1819,7 @@ Completion ignores case if the ambient value of
                      : (NILP (Vminibuffer_completing_file_name)
                         || EQ (Vminibuffer_completing_file_name, Qlambda)
                         ? Vminibuffer_local_must_match_map
-                        : Vminibuffer_local_must_match_filename_map),
+                        : Vminibuffer_local_filename_must_match_map),
                      init, prompt, make_number (pos), 0,
                      histvar, histpos, def, 0,
                      !NILP (inherit_input_method));
@@ -1964,7 +1963,28 @@ The arguments STRING and PREDICATE are as in `try-completion',
   if (NILP (flag))
     return Ftry_completion (string, Vbuffer_alist, predicate);
   else if (EQ (flag, Qt))
-    return Fall_completions (string, Vbuffer_alist, predicate, Qt);
+    {
+      Lisp_Object res = Fall_completions (string, Vbuffer_alist, predicate, Qnil);
+      if (SCHARS (string) > 0)
+       return res;
+      else
+       { /* Strip out internal buffers.  */
+         Lisp_Object bufs = res;
+         /* First, look for a non-internal buffer in `res'.  */
+         while (CONSP (bufs) && SREF (XCAR (bufs), 0) == ' ')
+           bufs = XCDR (bufs);
+         if (NILP (bufs))
+           /* All bufs in `res' are internal, so don't trip them out.  */
+           return res;
+         res = bufs;
+         while (CONSP (XCDR (bufs)))
+           if (SREF (XCAR (XCDR (bufs)), 0) == ' ')
+             XSETCDR (bufs, XCDR (XCDR (bufs)));
+           else
+             bufs = XCDR (bufs);
+         return res;
+       }
+    }
   else                         /* assume `lambda' */
     return Ftest_completion (string, Vbuffer_alist, predicate);
 }
@@ -2101,6 +2121,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;
@@ -2131,8 +2156,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;
 
@@ -2246,41 +2272,5 @@ properties.  */);
   defsubr (&Scompleting_read);
 }
 
-void
-keys_of_minibuf ()
-{
-  initial_define_key (Vminibuffer_local_map, Ctl ('g'),
-                     "abort-recursive-edit");
-  initial_define_key (Vminibuffer_local_map, Ctl ('m'),
-                     "exit-minibuffer");
-  initial_define_key (Vminibuffer_local_map, Ctl ('j'),
-                     "exit-minibuffer");
-
-  initial_define_key (Vminibuffer_local_ns_map, ' ',
-                     "exit-minibuffer");
-  initial_define_key (Vminibuffer_local_ns_map, '\t',
-                     "exit-minibuffer");
-  initial_define_key (Vminibuffer_local_ns_map, '?',
-                     "self-insert-and-exit");
-
-  initial_define_key (Vminibuffer_local_completion_map, '\t',
-                     "minibuffer-complete");
-  initial_define_key (Vminibuffer_local_completion_map, ' ',
-                     "minibuffer-complete-word");
-  initial_define_key (Vminibuffer_local_completion_map, '?',
-                     "minibuffer-completion-help");
-
-  Fdefine_key (Vminibuffer_local_filename_completion_map,
-              build_string (" "), Qnil);
-
-  initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'),
-                     "minibuffer-complete-and-exit");
-  initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'),
-                     "minibuffer-complete-and-exit");
-
-  Fdefine_key (Vminibuffer_local_must_match_filename_map,
-              build_string (" "), Qnil);
-}
-
 /* arch-tag: 8f69b601-fba3-484c-a6dd-ceaee54a7a73
    (do not change this comment) */