(Fchar_after, Fchar_before): Properly check arg type
[bpt/emacs.git] / src / editfns.c
index 1630888..587e751 100644 (file)
@@ -380,7 +380,12 @@ DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0,
 Executes BODY just like `progn'.\n\
 The values of point, mark and the current buffer are restored\n\
 even in case of abnormal exit (throw or error).\n\
-The state of activation of the mark is also restored.")
+The state of activation of the mark is also restored.\n\
+\n\
+This construct does not save `deactivate-mark', and therefore\n\
+functions that change the buffer will still cause deactivation\n\
+of the mark at the end of the command.  To prevent that, bind\n\
+`deactivate-mark' with `let'.")
   (args)
      Lisp_Object args;
 {
@@ -458,6 +463,7 @@ is in effect, in which case it is less.")
 DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
   "Return the byte position for character position POSITION.")
   (position)
+     Lisp_Object position;
 {
   CHECK_NUMBER_COERCE_MARKER (position, 1);
   return make_number (CHAR_TO_BYTE (XINT (position)));
@@ -554,20 +560,22 @@ If `enable-multibyte-characters' is nil or POS is not at character boundary,\n\
   register Lisp_Object val;
 
   if (NILP (pos))
-    return make_number (FETCH_CHAR (PT_BYTE));
-
-  if (MARKERP (pos))
-    pos_byte = marker_byte_position (pos);
+    pos_byte = PT_BYTE;
+  else if (MARKERP (pos))
+    {
+      pos_byte = marker_byte_position (pos);
+      if (pos_byte < BEGV_BYTE || pos_byte >= ZV_BYTE)
+       return Qnil;
+    }
   else
     {
       CHECK_NUMBER_COERCE_MARKER (pos, 0);
+      if (pos < BEGV || pos >= ZV)
+       return Qnil;
       
       pos_byte = CHAR_TO_BYTE (XINT (pos));
     }
 
-  if (pos_byte < BEGV_BYTE || pos_byte >= ZV_BYTE)
-    return Qnil;
-
   return make_number (FETCH_CHAR (pos_byte));
 }
 
@@ -587,17 +595,22 @@ is returned as a character.")
   if (NILP (pos))
     pos_byte = PT_BYTE;
   else if (MARKERP (pos))
-    pos_byte = marker_byte_position (pos);
+    {
+      pos_byte = marker_byte_position (pos);
+
+      if (pos_byte <= BEGV_BYTE || pos_byte > ZV_BYTE)
+       return Qnil;
+    }
   else
     {
       CHECK_NUMBER_COERCE_MARKER (pos, 0);
 
+      if (pos <= BEGV || pos > ZV)
+       return Qnil;
+
       pos_byte = CHAR_TO_BYTE (XINT (pos));
     }
 
-  if (pos_byte <= BEGV_BYTE || pos_byte > ZV_BYTE)
-    return Qnil;
-
   if (!NILP (current_buffer->enable_multibyte_characters))
     {
       DEC_POS (pos_byte);
@@ -1825,8 +1838,6 @@ Both characters must have the same length of multi-byte form.")
          if (NILP (noundo))
            record_change (pos, 1);
          for (i = 0; i < len; i++) *p++ = tostr[i];
-         pos++;
-         pos_byte += len;
        }
       INC_BOTH (pos, pos_byte);
     }
@@ -2074,7 +2085,7 @@ minibuffer contents show.")
          message_text = (char *)xmalloc (80);
          message_length = 80;
        }
-      if (XSTRING (val)->size > message_length)
+      if (XSTRING (val)->size_byte > message_length)
        {
          message_length = XSTRING (val)->size_byte;
          message_text = (char *)xrealloc (message_text, message_length);
@@ -2301,7 +2312,17 @@ Use %% to put a single % into the output.")
            if (*format == 'e' || *format == 'f' || *format == 'g')
              args[n] = Ffloat (args[n]);
 #endif
-           thissize = 30;
+           thissize = 30;      
+           if (*format == 'c' && ! SINGLE_BYTE_CHAR_P (XINT (args[n])))
+             {
+               if (! multibyte)
+                 {
+                   multibyte = 1;
+                   goto retry;
+                 }
+               args[n] = Fchar_to_string (args[n]);
+               thissize = XSTRING (args[n])->size_byte;
+             }
          }
 #ifdef LISP_FLOAT_TYPE
        else if (FLOATP (args[n]) && *format != 's')
@@ -2316,7 +2337,7 @@ Use %% to put a single % into the output.")
            /* Anything but a string, convert to a string using princ.  */
            register Lisp_Object tem;
            tem = Fprin1_to_string (args[n], Qt);
-           if (STRING_MULTIBYTE (tem))
+           if (STRING_MULTIBYTE (tem) & ! multibyte)
              {
                multibyte = 1;
                goto retry;
@@ -2378,16 +2399,17 @@ Use %% to put a single % into the output.")
 
          if (STRINGP (args[n]))
            {
-             int padding, nbytes;
+             int padding, nbytes, width;
 
              nbytes = copy_text (XSTRING (args[n])->data, p,
                                  XSTRING (args[n])->size_byte,
                                  STRING_MULTIBYTE (args[n]), multibyte);
+             width = strwidth (p, nbytes);
              p += nbytes;
              nchars += XSTRING (args[n])->size;
 
              /* If spec requires it, pad on right with spaces.  */
-             padding = minlen - XSTRING (args[n])->size;
+             padding = minlen - width;
              while (padding-- > 0)
                {
                  *p++ = ' ';
@@ -2456,7 +2478,7 @@ format1 (string1)
   args[2] = arg2;
   args[3] = arg3;
   args[4] = arg4;
-  doprnt (buf, sizeof buf, string1, (char *)0, 5, args);
+  doprnt (buf, sizeof buf, string1, (char *)0, 5, (char **) args);
 #else
   doprnt (buf, sizeof buf, string1, (char *)0, 5, &string1 + 1);
 #endif