Merge from emacs--devo--0
[bpt/emacs.git] / src / cmds.c
index 71b56e4..45b3f87 100644 (file)
@@ -1,12 +1,12 @@
 /* Simple built-in editing commands.
    Copyright (C) 1985, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002,
-                 2003, 2004, 2005 Free Software Foundation, Inc.
+                 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 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,
@@ -24,7 +24,7 @@ Boston, MA 02110-1301, USA.  */
 #include "lisp.h"
 #include "commands.h"
 #include "buffer.h"
-#include "charset.h"
+#include "character.h"
 #include "syntax.h"
 #include "window.h"
 #include "keyboard.h"
@@ -77,12 +77,12 @@ On reaching end of buffer, stop and signal error.  */)
     if (new_point < BEGV)
       {
        SET_PT (BEGV);
-       Fsignal (Qbeginning_of_buffer, Qnil);
+       xsignal0 (Qbeginning_of_buffer);
       }
     if (new_point > ZV)
       {
        SET_PT (ZV);
-       Fsignal (Qend_of_buffer, Qnil);
+       xsignal0 (Qend_of_buffer);
       }
 
     SET_PT (new_point);
@@ -157,10 +157,10 @@ DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, 0, 1, "p",
 With argument N not nil or 1, move forward N - 1 lines first.
 If point reaches the beginning or end of buffer, it stops there.
 
-This function does not move point across a field boundary unless that
-would move point to a different line than the original, unconstrained
-result.  If N is nil or 1, and a front-sticky field starts at point,
-the point does not move.  To ignore field boundaries bind
+This function constrains point to the current field unless this moves
+point to a different line than the original, unconstrained result.  If
+N is nil or 1, and a front-sticky field starts at point, the point
+does not move.  To ignore field boundaries bind
 `inhibit-field-text-motion' to t, or use the `forward-line' function
 instead.  For instance, `(forward-line 0)' does the same thing as
 `(beginning-of-line)', except that it ignores field boundaries.  */)
@@ -183,11 +183,11 @@ With argument N not nil or 1, move forward N - 1 lines first.
 If point reaches the beginning or end of buffer, it stops there.
 To ignore intangibility, bind `inhibit-point-motion-hooks' to t.
 
-This function does not move point across a field boundary unless that
-would move point to a different line than the original, unconstrained
-result.  If N is nil or 1, and a rear-sticky field ends at point,
-the point does not move.  To ignore field boundaries bind
-`inhibit-field-text-motion' to t.  */)
+This function constrains point to the current field unless this moves
+point to a different line than the original, unconstrained result.  If
+N is nil or 1, and a rear-sticky field ends at point, the point does
+not move.  To ignore field boundaries bind `inhibit-field-text-motion'
+to t.  */)
      (n)
      Lisp_Object n;
 {
@@ -245,14 +245,14 @@ N was explicitly specified.  */)
       if (XINT (n) < 0)
        {
          if (pos < BEGV)
-           Fsignal (Qbeginning_of_buffer, Qnil);
+           xsignal0 (Qbeginning_of_buffer);
          else
            del_range (pos, PT);
        }
       else
        {
          if (pos > ZV)
-           Fsignal (Qend_of_buffer, Qnil);
+           xsignal0 (Qend_of_buffer);
          else
            del_range (PT, pos);
        }
@@ -327,11 +327,11 @@ Whichever character you type to run this command is inserted.  */)
   CHECK_NUMBER (n);
 
   /* Barf if the key that invoked this was not a character.  */
-  if (!INTEGERP (last_command_char))
+  if (!CHARACTERP (last_command_char))
     bitch_at_user ();
   {
     int character = translate_char (Vtranslation_table_for_input,
-                                   XINT (last_command_char), 0, 0, 0);
+                                   XINT (last_command_char));
     if (XINT (n) >= 2 && NILP (current_buffer->overwrite_mode))
       {
        int modified_char = character;
@@ -395,7 +395,6 @@ internal_self_insert (c, noautofill)
   /* At first, get multi-byte form of C in STR.  */
   if (!NILP (current_buffer->enable_multibyte_characters))
     {
-      c = unibyte_char_to_multibyte (c);
       len = CHAR_STRING (c, str);
       if (len == 1)
        /* If C has modifier bits, this makes C an appropriate
@@ -472,10 +471,19 @@ 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)
-      && SYNTAX (c) != Sword
+      && synt != Sword
       && NILP (current_buffer->read_only)
-      && PT > BEGV && SYNTAX (XFASTINT (Fprevious_char ())) == Sword)
+      && PT > BEGV
+      && (!NILP (current_buffer->enable_multibyte_characters)
+         ? SYNTAX (XFASTINT (Fprevious_char ())) == Sword
+         : (SYNTAX (unibyte_char_to_multibyte (XFASTINT (Fprevious_char ())))
+            == Sword)))
     {
       int modiff = MODIFF;
       Lisp_Object sym;
@@ -528,7 +536,8 @@ internal_self_insert (c, noautofill)
           justification, if any, know where the end is going to be.  */
        SET_PT_BOTH (PT - 1, PT_BYTE - 1);
       tem = call0 (current_buffer->auto_fill_function);
-      if (c == '\n')
+      /* Test PT < ZV in case the auto-fill-function is strange.  */
+      if (c == '\n' && PT < ZV)
        SET_PT_BOTH (PT + 1, PT_BYTE + 1);
       if (!NILP (tem))
        hairy = 2;
@@ -543,7 +552,6 @@ internal_self_insert (c, noautofill)
       Vself_insert_face = Qnil;
     }
 
-  synt = SYNTAX (c);
   if ((synt == Sclose || synt == Smath)
       && !NILP (Vblink_paren_function) && INTERACTIVE
       && !noautofill)