]> code.delx.au - gnu-emacs/blobdiff - src/minibuf.c
Merge from emacs--devo--0
[gnu-emacs] / src / minibuf.c
index 667799bf17004f65a07fd46301abdb6a9092cca6..c84c83c1c8ea4af4cc25f03b3936ee247e6db598 100644 (file)
@@ -7,7 +7,7 @@ This file is part of GNU Emacs.
 
 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 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -35,6 +35,7 @@ Boston, MA 02110-1301, USA.  */
 #include "syntax.h"
 #include "intervals.h"
 #include "keymap.h"
+#include "termhooks.h"
 
 extern int quit_char;
 
@@ -386,7 +387,7 @@ Return (point-min) if current buffer is not a minibuffer.  */)
 DEFUN ("minibuffer-contents", Fminibuffer_contents,
        Sminibuffer_contents, 0, 0, 0,
        doc: /* Return the user input in a minibuffer as a string.
-The current buffer must be a minibuffer.  */)
+If the current buffer is not a minibuffer, return its entire contents.  */)
      ()
 {
   int prompt_end = XINT (Fminibuffer_prompt_end ());
@@ -396,7 +397,7 @@ The current buffer must be a minibuffer.  */)
 DEFUN ("minibuffer-contents-no-properties", Fminibuffer_contents_no_properties,
        Sminibuffer_contents_no_properties, 0, 0, 0,
        doc: /* Return the user input in a minibuffer as a string, without text-properties.
-The current buffer must be a minibuffer.  */)
+If the current buffer is not a minibuffer, return its entire contents.  */)
      ()
 {
   int prompt_end = XINT (Fminibuffer_prompt_end ());
@@ -407,7 +408,7 @@ DEFUN ("minibuffer-completion-contents", Fminibuffer_completion_contents,
        Sminibuffer_completion_contents, 0, 0, 0,
        doc: /* Return the user input in a minibuffer before point as a string.
 That is what completion commands operate on.
-The current buffer must be a minibuffer.  */)
+If the current buffer is not a minibuffer, return its entire contents.  */)
      ()
 {
   int prompt_end = XINT (Fminibuffer_prompt_end ());
@@ -419,7 +420,7 @@ The current buffer must be a minibuffer.  */)
 DEFUN ("delete-minibuffer-contents", Fdelete_minibuffer_contents,
        Sdelete_minibuffer_contents, 0, 0, 0,
        doc: /* Delete all user input in a minibuffer.
-The current buffer must be a minibuffer.  */)
+If the current buffer is not a minibuffer, erase its entire contents.  */)
      ()
 {
   int prompt_end = XINT (Fminibuffer_prompt_end ());
@@ -491,7 +492,6 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (EQ (Vminibuffer_completing_file_name, Qlambda))
     Vminibuffer_completing_file_name = Qnil;
 
-  single_kboard_state ();
 #ifdef HAVE_X_WINDOWS
   if (display_hourglass_p)
     cancel_hourglass ();
@@ -529,7 +529,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   GCPRO5 (map, initial, val, ambient_dir, input_method);
 
   if (!STRINGP (prompt))
-    prompt = empty_string;
+    prompt = empty_unibyte_string;
 
   if (!enable_recursive_minibuffers
       && minibuf_level > 0)
@@ -575,6 +575,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (minibuffer_auto_raise)
     Fraise_frame (mini_frame);
 
+  temporarily_switch_to_single_kboard (XFRAME (mini_frame));
+
   /* We have to do this after saving the window configuration
      since that is what restores the current buffer.  */
 
@@ -700,26 +702,26 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
     specbind (Qinhibit_read_only, Qt);
     specbind (Qinhibit_modification_hooks, Qt);
     Ferase_buffer ();
-    unbind_to (count1, Qnil);
-  }
 
-  if (!NILP (current_buffer->enable_multibyte_characters)
-      && ! STRING_MULTIBYTE (minibuf_prompt))
-    minibuf_prompt = Fstring_make_multibyte (minibuf_prompt);
+    if (!NILP (current_buffer->enable_multibyte_characters)
+       && ! STRING_MULTIBYTE (minibuf_prompt))
+      minibuf_prompt = Fstring_make_multibyte (minibuf_prompt);
 
-  /* Insert the prompt, record where it ends.  */
-  Finsert (1, &minibuf_prompt);
-  if (PT > BEG)
-    {
-      Fput_text_property (make_number (BEG), make_number (PT),
-                         Qfront_sticky, Qt, Qnil);
-      Fput_text_property (make_number (BEG), make_number (PT),
-                         Qrear_nonsticky, Qt, Qnil);
-      Fput_text_property (make_number (BEG), make_number (PT),
-                         Qfield, Qt, Qnil);
-      Fadd_text_properties (make_number (BEG), make_number (PT),
-                           Vminibuffer_prompt_properties, Qnil);
-    }
+    /* Insert the prompt, record where it ends.  */
+    Finsert (1, &minibuf_prompt);
+    if (PT > BEG)
+      {
+       Fput_text_property (make_number (BEG), make_number (PT),
+                           Qfront_sticky, Qt, Qnil);
+       Fput_text_property (make_number (BEG), make_number (PT),
+                           Qrear_nonsticky, Qt, Qnil);
+       Fput_text_property (make_number (BEG), make_number (PT),
+                           Qfield, Qt, Qnil);
+       Fadd_text_properties (make_number (BEG), make_number (PT),
+                             Vminibuffer_prompt_properties, Qnil);
+      }
+    unbind_to (count1, Qnil);
+  }
 
   minibuf_prompt_width = (int) current_column (); /* iftc */
 
@@ -758,8 +760,12 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
       XWINDOW (minibuf_window)->cursor.x = 0;
       XWINDOW (minibuf_window)->must_be_updated_p = 1;
       update_frame (XFRAME (selected_frame), 1, 1);
-      if (rif && rif->flush_display)
-       rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame));
+      {
+        struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame);
+        struct redisplay_interface *rif = FRAME_RIF (f);
+        if (rif && rif->flush_display)
+          rif->flush_display (f);
+      }
     }
 
   /* Make minibuffer contents into a string.  */
@@ -1483,6 +1489,10 @@ is used to further constrain the set of candidates.  */)
                matchcount++;
              bestmatchsize = matchsize;
              if (matchsize <= SCHARS (string)
+                 /* If completion-ignore-case is non-nil, don't
+                    short-circuit because we want to find the best
+                    possible match *including* case differences.  */
+                 && !completion_ignore_case
                  && matchcount > 1)
                /* No need to look any further.  */
                break;
@@ -1713,9 +1723,15 @@ PREDICATE limits completion to a subset of COLLECTION.
 See `try-completion' and `all-completions' for more details
  on completion, COLLECTION, and PREDICATE.
 
-If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
- the input is (or completes to) an element of COLLECTION or is null.
- If it is also not t, typing RET does not exit if it does non-null completion.
+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.
+- anything else behaves like t except that typing RET does not exit if it
+  does non-null completion.
+
 If the input is null, `completing-read' returns DEF, or an empty string
  if DEF is nil, regardless of the value of REQUIRE-MATCH.
 
@@ -2226,6 +2242,18 @@ a repetition of this command will exit.  */)
       goto exit;
     }
 
+  if (EQ (Vminibuffer_completion_confirm, intern ("confirm-only")))
+    { /* The user is permitted to exit with an input that's rejected
+        by test-completion, but at the condition to confirm her choice.  */
+      if (EQ (current_kboard->Vlast_command, Vthis_command))
+       goto exit;
+      else
+       {
+         temp_echo_area_glyphs (build_string (" [Confirm]"));
+         return Qnil;
+       }
+    }
+
   /* Call do_completion, but ignore errors.  */
   SET_PT (ZV);
   val = internal_condition_case (complete_and_exit_1, Qerror,