Merge from trunk
[bpt/emacs.git] / src / print.c
index f47b710..602575b 100644 (file)
@@ -111,7 +111,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
    EMACS_INT old_point_byte = -1, start_point_byte = -1;               \
    int specpdl_count = SPECPDL_INDEX ();                               \
    int free_print_buffer = 0;                                          \
-   int multibyte = !NILP (current_buffer->enable_multibyte_characters);        \
+   int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
    Lisp_Object original
 
 #define PRINTPREPARE                                                   \
@@ -144,10 +144,10 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
    if (NILP (printcharfun))                                            \
      {                                                                 \
        Lisp_Object string;                                             \
-       if (NILP (current_buffer->enable_multibyte_characters)          \
+       if (NILP (BVAR (current_buffer, enable_multibyte_characters))           \
           && ! print_escape_multibyte)                                 \
          specbind (Qprint_escape_multibyte, Qt);                       \
-       if (! NILP (current_buffer->enable_multibyte_characters)                \
+       if (! NILP (BVAR (current_buffer, enable_multibyte_characters))         \
           && ! print_escape_nonascii)                                  \
          specbind (Qprint_escape_nonascii, Qt);                                \
        if (print_buffer != 0)                                          \
@@ -173,7 +173,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
    if (NILP (printcharfun))                                            \
      {                                                                 \
        if (print_buffer_pos != print_buffer_pos_byte                   \
-          && NILP (current_buffer->enable_multibyte_characters))       \
+          && NILP (BVAR (current_buffer, enable_multibyte_characters)))        \
         {                                                              \
           unsigned char *temp                                          \
             = (unsigned char *) alloca (print_buffer_pos + 1);         \
@@ -250,7 +250,7 @@ printchar (unsigned int ch, Lisp_Object fun)
       else
        {
          int multibyte_p
-           = !NILP (current_buffer->enable_multibyte_characters);
+           = !NILP (BVAR (current_buffer, enable_multibyte_characters));
 
          setup_echo_area_for_printing (multibyte_p);
          insert_char (ch);
@@ -302,7 +302,7 @@ strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
         job.  */
       int i;
       int multibyte_p
-       = !NILP (current_buffer->enable_multibyte_characters);
+       = !NILP (BVAR (current_buffer, enable_multibyte_characters));
 
       setup_echo_area_for_printing (multibyte_p);
       message_dolog (ptr, size_byte, 0, multibyte_p);
@@ -371,8 +371,8 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
        chars = SCHARS (string);
       else if (! print_escape_nonascii
               && (EQ (printcharfun, Qt)
-                  ? ! NILP (buffer_defaults.enable_multibyte_characters)
-                  : ! NILP (current_buffer->enable_multibyte_characters)))
+                  ? ! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))
+                  : ! NILP (BVAR (current_buffer, enable_multibyte_characters))))
        {
          /* If unibyte string STRING contains 8-bit codes, we must
             convert STRING to a multibyte string containing the same
@@ -504,14 +504,14 @@ temp_output_buffer_setup (const char *bufname)
 
   Fkill_all_local_variables ();
   delete_all_overlays (current_buffer);
-  current_buffer->directory = old->directory;
-  current_buffer->read_only = Qnil;
-  current_buffer->filename = Qnil;
-  current_buffer->undo_list = Qt;
+  BVAR (current_buffer, directory) = BVAR (old, directory);
+  BVAR (current_buffer, read_only) = Qnil;
+  BVAR (current_buffer, filename) = Qnil;
+  BVAR (current_buffer, undo_list) = Qt;
   eassert (current_buffer->overlays_before == NULL);
   eassert (current_buffer->overlays_after == NULL);
-  current_buffer->enable_multibyte_characters
-    = buffer_defaults.enable_multibyte_characters;
+  BVAR (current_buffer, enable_multibyte_characters)
+    = BVAR (&buffer_defaults, enable_multibyte_characters);
   specbind (Qinhibit_read_only, Qt);
   specbind (Qinhibit_modification_hooks, Qt);
   Ferase_buffer ();
@@ -524,6 +524,7 @@ temp_output_buffer_setup (const char *bufname)
   specbind (Qstandard_output, buf);
 }
 
+/* FIXME: Use Lisp's with-output-to-temp-buffer instead!  */
 Lisp_Object
 internal_with_output_to_temp_buffer (const char *bufname, Lisp_Object (*function) (Lisp_Object), Lisp_Object args)
 {
@@ -545,60 +546,6 @@ internal_with_output_to_temp_buffer (const char *bufname, Lisp_Object (*function
 
   return unbind_to (count, val);
 }
-
-DEFUN ("with-output-to-temp-buffer",
-       Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,
-       1, UNEVALLED, 0,
-       doc: /* Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.
-
-This construct makes buffer BUFNAME empty before running BODY.
-It does not make the buffer current for BODY.
-Instead it binds `standard-output' to that buffer, so that output
-generated with `prin1' and similar functions in BODY goes into
-the buffer.
-
-At the end of BODY, this marks buffer BUFNAME unmodifed and displays
-it in a window, but does not select it.  The normal way to do this is
-by calling `display-buffer', then running `temp-buffer-show-hook'.
-However, if `temp-buffer-show-function' is non-nil, it calls that
-function instead (and does not run `temp-buffer-show-hook').  The
-function gets one argument, the buffer to display.
-
-The return value of `with-output-to-temp-buffer' is the value of the
-last form in BODY.  If BODY does not finish normally, the buffer
-BUFNAME is not displayed.
-
-This runs the hook `temp-buffer-setup-hook' before BODY,
-with the buffer BUFNAME temporarily current.  It runs the hook
-`temp-buffer-show-hook' after displaying buffer BUFNAME, with that
-buffer temporarily current, and the window that was used to display it
-temporarily selected.  But it doesn't run `temp-buffer-show-hook'
-if it uses `temp-buffer-show-function'.
-
-usage: (with-output-to-temp-buffer BUFNAME BODY...)  */)
-  (Lisp_Object args)
-{
-  struct gcpro gcpro1;
-  Lisp_Object name;
-  int count = SPECPDL_INDEX ();
-  Lisp_Object buf, val;
-
-  GCPRO1(args);
-  name = Feval (Fcar (args));
-  CHECK_STRING (name);
-  temp_output_buffer_setup (SSDATA (name));
-  buf = Vstandard_output;
-  UNGCPRO;
-
-  val = Fprogn (XCDR (args));
-
-  GCPRO1 (val);
-  temp_output_buffer_show (buf);
-  UNGCPRO;
-
-  return unbind_to (count, val);
-}
-
 \f
 static void print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag);
 static void print_preprocess (Lisp_Object obj);
@@ -1062,7 +1009,10 @@ float_to_string (char *buf, double data)
     {
       /* Generate the fewest number of digits that represent the
         floating point value without losing information.  */
-      dtoastr (buf, FLOAT_TO_STRING_BUFSIZE, 0, 0, data);
+      dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data);
+      /* The decimal point must be printed, or the byte compiler can
+        get confused (Bug#8033). */
+      width = 1;
     }
   else                 /* oink oink */
     {
@@ -1117,8 +1067,7 @@ float_to_string (char *buf, double data)
          cp[1] = '0';
          cp[2] = 0;
        }
-
-      if (*cp == 0)
+      else if (*cp == 0)
        {
          *cp++ = '.';
          *cp++ = '0';
@@ -1681,26 +1630,6 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
        {
          PRINTCHAR ('(');
 
-         /* If the first element is a backquote form,
-            print it old-style so it won't be misunderstood.  */
-         if (print_quoted && CONSP (XCAR (obj))
-             && CONSP (XCDR (XCAR (obj)))
-             && NILP (XCDR (XCDR (XCAR (obj))))
-             && EQ (XCAR (XCAR (obj)), Qbackquote))
-           {
-             Lisp_Object tem;
-             tem = XCAR (obj);
-             PRINTCHAR ('(');
-
-             print_object (Qbackquote, printcharfun, 0);
-             PRINTCHAR (' ');
-
-             print_object (XCAR (XCDR (tem)), printcharfun, 0);
-             PRINTCHAR (')');
-
-             obj = XCDR (obj);
-           }
-
          {
            EMACS_INT print_length;
            int i;
@@ -1854,7 +1783,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
          if (!NILP (XWINDOW (obj)->buffer))
            {
              strout (" on ", -1, -1, printcharfun, 0);
-             print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun);
+             print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name), printcharfun);
            }
          PRINTCHAR ('>');
        }
@@ -1904,25 +1833,25 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
          if (!NILP (h->test))
            {
              strout (" test ", -1, -1, printcharfun, 0);
-             print_object (h->test, printcharfun, 0);
+             print_object (h->test, printcharfun, escapeflag);
            }
 
          if (!NILP (h->weak))
            {
              strout (" weakness ", -1, -1, printcharfun, 0);
-             print_object (h->weak, printcharfun, 0);
+             print_object (h->weak, printcharfun, escapeflag);
            }
 
          if (!NILP (h->rehash_size))
            {
              strout (" rehash-size ", -1, -1, printcharfun, 0);
-             print_object (h->rehash_size, printcharfun, 0);
+             print_object (h->rehash_size, printcharfun, escapeflag);
            }
 
          if (!NILP (h->rehash_threshold))
            {
              strout (" rehash-threshold ", -1, -1, printcharfun, 0);
-             print_object (h->rehash_threshold, printcharfun, 0);
+             print_object (h->rehash_threshold, printcharfun, escapeflag);
            }
 
          strout (" data ", -1, -1, printcharfun, 0);
@@ -1941,9 +1870,9 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
            if (!NILP (HASH_HASH (h, i)))
              {
                if (i) PRINTCHAR (' ');
-               print_object (HASH_KEY (h, i), printcharfun, 1);
+               print_object (HASH_KEY (h, i), printcharfun, escapeflag);
                PRINTCHAR (' ');
-               print_object (HASH_VALUE (h, i), printcharfun, 1);
+               print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
              }
 
          if (size < real_size)
@@ -1955,16 +1884,16 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
        }
       else if (BUFFERP (obj))
        {
-         if (NILP (XBUFFER (obj)->name))
+         if (NILP (BVAR (XBUFFER (obj), name)))
            strout ("#<killed buffer>", -1, -1, printcharfun, 0);
          else if (escapeflag)
            {
              strout ("#<buffer ", -1, -1, printcharfun, 0);
-             print_string (XBUFFER (obj)->name, printcharfun);
+             print_string (BVAR (XBUFFER (obj), name), printcharfun);
              PRINTCHAR ('>');
            }
          else
-           print_string (XBUFFER (obj)->name, printcharfun);
+           print_string (BVAR (XBUFFER (obj), name), printcharfun);
        }
       else if (WINDOW_CONFIGURATIONP (obj))
        {
@@ -2076,7 +2005,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
              sprintf (buf, "at %ld", (long)marker_position (obj));
              strout (buf, -1, -1, printcharfun, 0);
              strout (" in ", -1, -1, printcharfun, 0);
-             print_string (XMARKER (obj)->buffer->name, printcharfun);
+             print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
            }
          PRINTCHAR ('>');
          break;
@@ -2091,7 +2020,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
                       (long)marker_position (OVERLAY_START (obj)),
                       (long)marker_position (OVERLAY_END   (obj)));
              strout (buf, -1, -1, printcharfun, 0);
-             print_string (XMARKER (OVERLAY_START (obj))->buffer->name,
+             print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
                            printcharfun);
            }
          PRINTCHAR ('>');
@@ -2310,6 +2239,4 @@ priorities.  */);
 
   print_prune_charset_plist = Qnil;
   staticpro (&print_prune_charset_plist);
-
-  defsubr (&Swith_output_to_temp_buffer);
 }