(LIBS): Link in shell32.lib.
[bpt/emacs.git] / src / cmds.c
index 11e4849..f91f91b 100644 (file)
@@ -1,5 +1,5 @@
 /* Simple built-in editing commands.
-   Copyright (C) 1985, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1985, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -27,6 +27,7 @@ Boston, MA 02111-1307, USA.  */
 #include "syntax.h"
 #include "window.h"
 #include "keyboard.h"
+#include "dispextern.h"
 
 Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function;
 
@@ -39,9 +40,6 @@ Lisp_Object Vself_insert_face;
 /* This is the command that set up Vself_insert_face.  */
 Lisp_Object Vself_insert_face_command;
 
-/* Offset to add to a non-ASCII value when inserting it.  */
-int nonascii_insert_offset;
-
 extern Lisp_Object Qface;
 \f
 DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
@@ -238,18 +236,19 @@ N was explicitly specified.")
 {
   Lisp_Object value;
   int deleted_special = 0;
-  int pos, i;
+  int pos, pos_byte, i;
 
   CHECK_NUMBER (n, 0);
 
   /* See if we are about to delete a tab or newline backwards.  */
-  pos = PT_BYTE;
-  for (i = 0; i < XINT (n) && pos > BEGV_BYTE; i++)
+  pos = PT;
+  pos_byte = PT_BYTE;
+  for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++)
     {
       int c;
 
-      DEC_POS (pos);
-      c = FETCH_BYTE (pos);
+      DEC_BOTH (pos, pos_byte);
+      c = FETCH_BYTE (pos_byte);
       if (c == '\t' || c == '\n')
        {
          deleted_special = 1;
@@ -297,9 +296,8 @@ Whichever character you type to run this command is inserted.")
       /* Add the offset to the character, for Finsert_char.
         We pass internal_self_insert the unmodified character
         because it itself does this offsetting.  */
-      if (modified_char >= 0200 && modified_char <= 0377
-         && ! NILP (current_buffer->enable_multibyte_characters))
-       modified_char += nonascii_insert_offset;
+      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.  */
@@ -329,6 +327,7 @@ Whichever character you type to run this command is inserted.")
    return 0.  A value of 1 indicates this *might* not have been simple.
    A value of 2 means this did things that call for an undo boundary.  */
 
+int
 internal_self_insert (c, noautofill)
      int c;
      int noautofill;
@@ -345,10 +344,6 @@ internal_self_insert (c, noautofill)
   int chars_to_delete = 0;
   int spaces_to_insert = 0;
 
-  if (c >= 0200 && c <= 0377
-      && ! NILP (current_buffer->enable_multibyte_characters))
-    c += nonascii_insert_offset;
-
   overwrite = current_buffer->overwrite_mode;
   if (!NILP (Vbefore_change_function) || !NILP (Vafter_change_function)
       || !NILP (Vbefore_change_functions) || !NILP (Vafter_change_functions))
@@ -356,7 +351,10 @@ internal_self_insert (c, noautofill)
 
   /* At first, get multi-byte form of C in STR.  */
   if (!NILP (current_buffer->enable_multibyte_characters))
-    len = CHAR_STRING (c, workbuf, str);
+    {
+      c = unibyte_char_to_multibyte (c);
+      len = CHAR_STRING (c, workbuf, str);
+    }
   else
     workbuf[0] = c, str = workbuf, len = 1;
 
@@ -372,11 +370,10 @@ internal_self_insert (c, noautofill)
         we fill columns with spaces, if C is wider than C2, we delete
         C2 and several characters following C2.  */
 
-      /* A code at `point'.  Since this is checked only against
-         NEWLINE and TAB, we don't need a character code but only the
-         first byte of multi-byte form.  */
-      unsigned char c2 = FETCH_BYTE (PT_BYTE);
-      /* A column the cursor should be placed at after this insertion.
+      /* This is the character after point.  */
+      int c2 = FETCH_CHAR (PT_BYTE);
+
+      /* Column the cursor should be placed at after this insertion.
          The correct value should be calculated only when necessary.  */
       int target_clm = 0;
 
@@ -391,9 +388,8 @@ internal_self_insert (c, noautofill)
              && ! (c2 == '\t'
                    && XINT (current_buffer->tab_width) > 0
                    && XFASTINT (current_buffer->tab_width) < 20
-                   && ((NILP (current_buffer->enable_multibyte_characters)
-                        ? (target_clm = current_column () + 1)
-                        : (target_clm = current_column () + WIDTH_BY_CHAR_HEAD (str[0]))),
+                   && (target_clm = (current_column () 
+                                     + XINT (Fchar_width (make_number (c2)))),
                        target_clm % XFASTINT (current_buffer->tab_width)))))
        {
          int pos = PT;
@@ -453,7 +449,7 @@ internal_self_insert (c, noautofill)
 
   if (chars_to_delete)
     {
-      string = make_string (str, len);
+      string = make_string_from_bytes (str, 1, len);
       if (spaces_to_insert)
        {
          tem = Fmake_string (make_number (spaces_to_insert),
@@ -461,9 +457,8 @@ internal_self_insert (c, noautofill)
          string = concat2 (tem, string);
        }
 
-      replace_range (PT, PT + chars_to_delete, string, 1, 1);
-      SET_PT_BOTH (PT + 1 + spaces_to_insert,
-                  PT_BYTE + XSTRING (string)->size);
+      replace_range (PT, PT + chars_to_delete, string, 1, 1, 0);
+      Fforward_char (make_number (1 + spaces_to_insert));
     }
   else
     insert_and_inherit (str, len);
@@ -510,6 +505,7 @@ internal_self_insert (c, noautofill)
 \f
 /* module initialization */
 
+void
 syms_of_cmds ()
 {
   Qkill_backward_chars = intern ("kill-backward-chars");
@@ -536,13 +532,6 @@ If `last-command' does not equal this value, we ignore `self-insert-face'.");
 More precisely, a char with closeparen syntax is self-inserted.");
   Vblink_paren_function = Qnil;
 
-  DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset,
-    "Offset to add to a non-ascii code 0200...0377 when inserting it.\n\
-This applies only when multibyte characters are enabled, and it serves\n\
-to convert a Latin-1 or similar 8-bit character code to the corresponding\n\
-Emacs character code.");
-  nonascii_insert_offset = 0;
-
   defsubr (&Sforward_point);
   defsubr (&Sforward_char);
   defsubr (&Sbackward_char);
@@ -556,6 +545,7 @@ Emacs character code.");
   defsubr (&Sself_insert_command);
 }
 
+void
 keys_of_cmds ()
 {
   int n;