(mail-setup): Call set-buffer-multibyte because
[bpt/emacs.git] / src / xselect.c
index 289d01e..eae1b0c 100644 (file)
@@ -1,5 +1,5 @@
 /* X Selection processing for Emacs.
-   Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation.
+   Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -430,6 +430,10 @@ x_decline_selection_request (event)
    It is set to zero when the request is fully processed.  */
 static struct input_event *x_selection_current_request;
 
+/* Display info in x_selection_request.  */
+
+static struct x_display_info *selection_request_dpyinfo;
+
 /* Used as an unwind-protect clause so that, if a selection-converter signals
    an error, we tell the requester that we were unable to do what they wanted
    before we throw to top-level or go into the debugger or whatever.  */
@@ -438,7 +442,8 @@ static Lisp_Object
 x_selection_request_lisp_error (ignore)
      Lisp_Object ignore;
 {
-  if (x_selection_current_request != 0)
+  if (x_selection_current_request != 0
+      && selection_request_dpyinfo->display)
     x_decline_selection_request (x_selection_current_request);
   return Qnil;
 }
@@ -644,6 +649,12 @@ x_reply_selection_request (event, format, data, size, type)
                       PropModeReplace, data, 0);
     }
 
+  /* The window we're communicating with may have been deleted
+     in the meantime (that's a real situation from a bug report).
+     In this case, there may be events in the event queue still
+     refering to the deleted window, and we'll get a BadWindow error
+     in XTread_socket when processing the events.  I don't have
+     an idea how to fix that.  gerd, 2001-01-98.   */
   XFlush (display);
   x_uncatch_errors (display, count);
   UNBLOCK_INPUT;
@@ -701,8 +712,9 @@ x_handle_selection_request (event)
       goto DONE;
     }
 
-  count = specpdl_ptr - specpdl;
   x_selection_current_request = event;
+  count = BINDING_STACK_SIZE ();
+  selection_request_dpyinfo = dpyinfo;
   record_unwind_protect (x_selection_request_lisp_error, Qnil);
 
   target_symbol = x_atom_to_symbol (dpyinfo, SELECTION_EVENT_DISPLAY (event),
@@ -837,7 +849,7 @@ x_handle_selection_clear (event)
        for (; CONSP (rest); rest = Fcdr (rest))
          call1 (Fcar (rest), selection_symbol);
        prepare_menu_bars ();
-       redisplay_preserve_echo_area ();
+       redisplay_preserve_echo_area (20);
       }
   }
 }
@@ -874,7 +886,7 @@ x_clear_frame_selections (f)
 #if 0 /* This can crash when deleting a frame
         from x_connection_closed.  Anyway, it seems unnecessary;
         something else should cause a redisplay.  */
-         redisplay_preserve_echo_area ();
+         redisplay_preserve_echo_area (21);
 #endif
        }
 
@@ -896,7 +908,7 @@ x_clear_frame_selections (f)
            for (; CONSP (hooks); hooks = Fcdr (hooks))
              call1 (Fcar (hooks), selection_symbol);
 #if 0 /* See above */
-           redisplay_preserve_echo_area ();
+           redisplay_preserve_echo_area (22);
 #endif
          }
        XCDR (rest) = Fcdr (XCDR (rest));