]> code.delx.au - gnu-emacs/commitdiff
Add x_catch_errors_with_handler.
authorKen Raeburn <raeburn@raeburn.org>
Fri, 2 Oct 2015 09:00:23 +0000 (05:00 -0400)
committerKen Raeburn <raeburn@raeburn.org>
Sun, 11 Oct 2015 05:15:12 +0000 (01:15 -0400)
* src/xterm.c (struct x_error_message_stack): Add new fields for a
callback function and associated data pointer.
(x_error_catcher): If the callback function is set, call it after
saving the error message string.
(x_catch_errors_with_handler): Renamed from x_catch_errors but now
accepts a callback function and data pointer.
(x_catch_errors): Now a wrapper function.
* src/xterm.h (x_special_error_handler): New typedef.
(x_catch_errors_with_handler): Declare.

src/xterm.c
src/xterm.h

index 6e870c5ebb92d5cb651b1d5928c06a9eeaddd87b..7ff6b17c30ab7e18d4712205038c3463a4f23b89 100644 (file)
@@ -9190,6 +9190,8 @@ x_text_icon (struct frame *f, const char *icon_name)
 struct x_error_message_stack {
   char string[X_ERROR_MESSAGE_SIZE];
   Display *dpy;
+  x_special_error_handler handler;
+  void *handler_data;
   struct x_error_message_stack *prev;
 };
 static struct x_error_message_stack *x_error_message;
@@ -9204,6 +9206,9 @@ x_error_catcher (Display *display, XErrorEvent *event)
   XGetErrorText (display, event->error_code,
                 x_error_message->string,
                 X_ERROR_MESSAGE_SIZE);
+  if (x_error_message->handler)
+    x_error_message->handler (display, event, x_error_message->string,
+                             x_error_message->handler_data);
 }
 
 /* Begin trapping X errors for display DPY.  Actually we trap X errors
@@ -9223,7 +9228,8 @@ x_error_catcher (Display *display, XErrorEvent *event)
    x_had_errors_p or x_check_errors.  */
 
 void
-x_catch_errors (Display *dpy)
+x_catch_errors_with_handler (Display *dpy, x_special_error_handler handler,
+                            void *handler_data)
 {
   struct x_error_message_stack *data = xmalloc (sizeof *data);
 
@@ -9232,10 +9238,18 @@ x_catch_errors (Display *dpy)
 
   data->dpy = dpy;
   data->string[0] = 0;
+  data->handler = handler;
+  data->handler_data = handler_data;
   data->prev = x_error_message;
   x_error_message = data;
 }
 
+void
+x_catch_errors (Display *dpy)
+{
+  x_catch_errors_with_handler (dpy, NULL, NULL);
+}
+
 /* Undo the last x_catch_errors call.
    DPY should be the display that was passed to x_catch_errors.
 
index fe3455ff7ce10beb99ac3d5b245f94dc5a1307b1..f7d2803ff299694b39cdfad24e49351d5a6126e0 100644 (file)
@@ -1024,8 +1024,13 @@ XrmDatabase x_load_resources (Display *, const char *, const char *,
 
 /* Defined in xterm.c */
 
+typedef void (*x_special_error_handler)(Display *, XErrorEvent *, char *,
+                                       void *);
+
 extern bool x_text_icon (struct frame *, const char *);
 extern void x_catch_errors (Display *);
+extern void x_catch_errors_with_handler (Display *, x_special_error_handler,
+                                        void *);
 extern void x_check_errors (Display *, const char *)
   ATTRIBUTE_FORMAT_PRINTF (2, 0);
 extern bool x_had_errors_p (Display *);