declare smobs in alloc.c
[bpt/emacs.git] / src / cmds.c
index 225c26b..3755ac3 100644 (file)
@@ -1,6 +1,6 @@
 /* Simple built-in editing commands.
 
-Copyright (C) 1985, 1993-1998, 2001-201 Free Software Foundation, Inc.
+Copyright (C) 1985, 1993-1998, 2001-2014 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,11 +19,11 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
-#include <setjmp.h>
+
 #include "lisp.h"
 #include "commands.h"
-#include "buffer.h"
 #include "character.h"
+#include "buffer.h"
 #include "syntax.h"
 #include "window.h"
 #include "keyboard.h"
@@ -47,10 +47,10 @@ DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
   return make_number (PT + XINT (n));
 }
 
-/* Add N to point; or subtract N if FORWARD is zero.  N defaults to 1.
+/* Add N to point; or subtract N if FORWARD is false.  N defaults to 1.
    Validate the new location.  Return nil.  */
 static Lisp_Object
-move_point (Lisp_Object n, int forward)
+move_point (Lisp_Object n, bool forward)
 {
   /* This used to just set point to point + XINT (n), and then check
      to see if it was within boundaries.  But now that SET_PT can
@@ -85,6 +85,8 @@ move_point (Lisp_Object n, int forward)
 DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
        doc: /* Move point N characters forward (backward if N is negative).
 On reaching end or beginning of buffer, stop and signal error.
+Interactively, N is the numeric prefix argument.
+If N is omitted or nil, move point 1 character forward.
 
 Depending on the bidirectional context, the movement may be to the
 right or to the left on the screen.  This is in contrast with
@@ -97,6 +99,8 @@ right or to the left on the screen.  This is in contrast with
 DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
        doc: /* Move point N characters backward (forward if N is negative).
 On attempt to pass beginning or end of buffer, stop and signal error.
+Interactively, N is the numeric prefix argument.
+If N is omitted or nil, move point 1 character backward.
 
 Depending on the bidirectional context, the movement may be to the
 right or to the left on the screen.  This is in contrast with
@@ -117,9 +121,7 @@ With positive N, a non-empty line at the end counts as one line
 successfully moved (for the return value).  */)
   (Lisp_Object n)
 {
-  ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
-  ptrdiff_t pos, pos_byte;
-  EMACS_INT count, shortage;
+  ptrdiff_t opoint = PT, pos, pos_byte, shortage, count;
 
   if (NILP (n))
     count = 1;
@@ -130,16 +132,12 @@ successfully moved (for the return value).  */)
     }
 
   if (count <= 0)
-    shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1);
+    pos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1,
+                       &shortage, &pos_byte, 1);
   else
-    shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1);
-
-  /* Since scan_newline does TEMP_SET_PT_BOTH,
-     and we want to set PT "for real",
-     go back to the old point and then come back here.  */
-  pos = PT;
-  pos_byte = PT_BYTE;
-  TEMP_SET_PT_BOTH (opoint, opoint_byte);
+    pos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count,
+                       &shortage, &pos_byte, 1);
+
   SET_PT_BOTH (pos, pos_byte);
 
   if (shortage > 0
@@ -231,7 +229,8 @@ Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
 Interactively, N is the prefix arg, and KILLFLAG is set if
 N was explicitly specified.
 
-The command `delete-forward-char' is preferable for interactive use.  */)
+The command `delete-forward-char' is preferable for interactive use, e.g.
+because it respects values of `delete-active-region' and `overwrite-mode'.  */)
   (Lisp_Object n, Lisp_Object killflag)
 {
   EMACS_INT pos;
@@ -270,6 +269,7 @@ static int nonundocount;
 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.
+The numeric prefix argument N says how many times to repeat the insertion.
 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
@@ -277,8 +277,11 @@ After insertion, the value of `auto-fill-function' is called if the
 At the end, it runs `post-self-insert-hook'.  */)
   (Lisp_Object n)
 {
-  int remove_boundary = 1;
-  CHECK_NATNUM (n);
+  bool remove_boundary = 1;
+  CHECK_NUMBER (n);
+
+  if (XFASTINT (n) < 0)
+    error ("Negative repetition argument %"pI"d", XFASTINT (n));
 
   if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command)))
     nonundocount = 0;
@@ -296,20 +299,23 @@ At the end, it runs `post-self-insert-hook'.  */)
 
   if (remove_boundary
       && CONSP (BVAR (current_buffer, undo_list))
-      && NILP (XCAR (BVAR (current_buffer, undo_list))))
+      && NILP (XCAR (BVAR (current_buffer, undo_list)))
+      /* Only remove auto-added boundaries, not boundaries
+        added be explicit calls to undo-boundary.  */
+      && EQ (BVAR (current_buffer, undo_list), last_undo_boundary))
     /* Remove the undo_boundary that was just pushed.  */
-    BVAR (current_buffer, undo_list) = XCDR (BVAR (current_buffer, undo_list));
+    bset_undo_list (current_buffer, XCDR (BVAR (current_buffer, undo_list)));
 
   /* Barf if the key that invoked this was not a character.  */
   if (!CHARACTERP (last_command_event))
     bitch_at_user ();
-  {
+  else {
     int character = translate_char (Vtranslation_table_for_input,
                                    XINT (last_command_event));
     int val = internal_self_insert (character, XFASTINT (n));
     if (val == 2)
       nonundocount = 0;
-    frame_make_pointer_invisible ();
+    frame_make_pointer_invisible (SELECTED_FRAME ());
   }
 
   return Qnil;
@@ -353,9 +359,7 @@ internal_self_insert (int c, EMACS_INT n)
     }
   else
     {
-      str[0] = (SINGLE_BYTE_CHAR_P (c)
-               ? c
-               : multibyte_char_to_unibyte (c));
+      str[0] = SINGLE_BYTE_CHAR_P (c) ? c : CHAR_TO_BYTE8 (c);
       len = 1;
     }
   if (!NILP (overwrite)
@@ -435,7 +439,7 @@ internal_self_insert (int c, EMACS_INT n)
                  : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
          == Sword))
     {
-      int modiff = MODIFF;
+      EMACS_INT modiff = MODIFF;
       Lisp_Object sym;
 
       sym = call0 (Qexpand_abbrev);
@@ -443,11 +447,12 @@ internal_self_insert (int c, EMACS_INT n)
       /* 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 (SYMBOLP (sym) && ! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
-         && SYMBOLP (XSYMBOL (sym)->function))
+      if (SYMBOLP (sym) && ! NILP (sym)
+         && ! NILP (SYMBOL_FUNCTION (sym))
+         && SYMBOLP (SYMBOL_FUNCTION (sym)))
        {
          Lisp_Object prop;
-         prop = Fget (XSYMBOL (sym)->function, intern ("no-self-insert"));
+         prop = Fget (SYMBOL_FUNCTION (sym), intern ("no-self-insert"));
          if (! NILP (prop))
            return 1;
        }
@@ -517,6 +522,8 @@ internal_self_insert (int c, EMACS_INT n)
 void
 syms_of_cmds (void)
 {
+#include "cmds.x"
+
   DEFSYM (Qkill_backward_chars, "kill-backward-chars");
   DEFSYM (Qkill_forward_chars, "kill-forward-chars");
   DEFSYM (Qoverwrite_mode_binary, "overwrite-mode-binary");
@@ -527,16 +534,6 @@ syms_of_cmds (void)
               doc: /* Hook run at the end of `self-insert-command'.
 This is run after inserting the character.  */);
   Vpost_self_insert_hook = Qnil;
-
-  defsubr (&Sforward_point);
-  defsubr (&Sforward_char);
-  defsubr (&Sbackward_char);
-  defsubr (&Sforward_line);
-  defsubr (&Sbeginning_of_line);
-  defsubr (&Send_of_line);
-
-  defsubr (&Sdelete_char);
-  defsubr (&Sself_insert_command);
 }
 
 void