Remove leftover table unibyte_to_multibyte_table.
[bpt/emacs.git] / src / cmds.c
index ed37603..19073dc 100644 (file)
@@ -1,14 +1,14 @@
 /* Simple built-in editing commands.
    Copyright (C) 1985, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002,
-                 2003, 2004, 2005, 2006, 2007, 2008
+                 2003, 2004, 2005, 2006, 2007, 2008, 2009
                  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>
@@ -317,47 +315,71 @@ N was explicitly specified.  */)
   return value;
 }
 
+int nonundocount;
+
 /* Note that there's code in command_loop_1 which typically avoids
    calling this.  */
 DEFUN ("self-insert-command", Fself_insert_command, Sself_insert_command, 1, 1, "p",
        doc: /* Insert the character you type.
-Whichever character you type to run this command is inserted.  */)
+Whichever character you type to run this command is inserted.
+Before insertion, `expand-abbrev' is executed if the inserted character does
+not have word syntax and the previous character in the buffer does.
+After insertion, the value of `auto-fill-function' is called if the
+`auto-fill-chars' table has a non-nil value for the inserted character.  */)
      (n)
      Lisp_Object n;
 {
   CHECK_NUMBER (n);
+  int remove_boundary = 1;
+
+  if (!EQ (Vthis_command, current_kboard->Vlast_command))
+    nonundocount = 0;
+
+  if (NILP (Vexecuting_kbd_macro)
+      && !EQ (minibuf_window, selected_window))
+    {
+      if (nonundocount <= 0 || nonundocount >= 20)
+       {
+         remove_boundary = 0;
+         nonundocount = 0;
+       }
+      nonundocount++;
+    }
+
+  if (remove_boundary
+      && CONSP (current_buffer->undo_list)
+      && NILP (XCAR (current_buffer->undo_list)))
+    /* Remove the undo_boundary that was just pushed.  */
+    current_buffer->undo_list = XCDR (current_buffer->undo_list);
 
   /* Barf if the key that invoked this was not a character.  */
-  if (!CHARACTERP (last_command_char))
+  if (!CHARACTERP (last_command_event))
     bitch_at_user ();
   {
     int character = translate_char (Vtranslation_table_for_input,
-                                   XINT (last_command_char));
+                                   XINT (last_command_event));
     if (XINT (n) >= 2 && NILP (current_buffer->overwrite_mode))
       {
-       int modified_char = character;
-       /* Add the offset to the character, for Finsert_char.
-          We pass internal_self_insert the unmodified character
-          because it itself does this offsetting.  */
-       if (! NILP (current_buffer->enable_multibyte_characters))
-         modified_char = unibyte_char_to_multibyte (modified_char);
-
        XSETFASTINT (n, XFASTINT (n) - 2);
        /* The first one might want to expand an abbrev.  */
        internal_self_insert (character, 1);
        /* The bulk of the copies of this char can be inserted simply.
           We don't have to handle a user-specified face specially
           because it will get inherited from the first char inserted.  */
-       Finsert_char (make_number (modified_char), n, Qt);
+       Finsert_char (make_number (character), n, Qt);
        /* The last one might want to auto-fill.  */
        internal_self_insert (character, 0);
       }
     else
       while (XINT (n) > 0)
        {
+         int val;
          /* Ok since old and new vals both nonneg */
          XSETFASTINT (n, XFASTINT (n) - 1);
-         internal_self_insert (character, XFASTINT (n) != 0);
+         val = internal_self_insert (character, XFASTINT (n) != 0);
+         if (val == 2)
+           nonundocount = 0;
+         frame_make_pointer_invisible ();
        }
   }
 
@@ -473,8 +495,6 @@ internal_self_insert (c, noautofill)
       hairy = 2;
     }
 
-  if (NILP (current_buffer->enable_multibyte_characters))
-    MAKE_CHAR_MULTIBYTE (c);
   synt = SYNTAX (c);
 
   if (!NILP (current_buffer->abbrev_mode)
@@ -483,7 +503,7 @@ internal_self_insert (c, noautofill)
       && PT > BEGV
       && (!NILP (current_buffer->enable_multibyte_characters)
          ? SYNTAX (XFASTINT (Fprevious_char ())) == Sword
-         : (SYNTAX (unibyte_char_to_multibyte (XFASTINT (Fprevious_char ())))
+         : (SYNTAX (UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
             == Sword)))
     {
       int modiff = MODIFF;
@@ -494,7 +514,7 @@ internal_self_insert (c, noautofill)
       /* If we expanded an abbrev which has a hook,
         and the hook has a non-nil `no-self-insert' property,
         return right away--don't really self-insert.  */
-      if (! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
+      if (SYMBOLP (sym) && ! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
          && SYMBOLP (XSYMBOL (sym)->function))
        {
          Lisp_Object prop;
@@ -613,6 +633,7 @@ keys_of_cmds ()
 {
   int n;
 
+  nonundocount = 0;
   initial_define_key (global_map, Ctl ('I'), "self-insert-command");
   for (n = 040; n < 0177; n++)
     initial_define_key (global_map, n, "self-insert-command");