From xemacs-m  Wed Apr 23 09:10:43 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id JAA26303
	for <xemacs-beta@xemacs.org>; Wed, 23 Apr 1997 09:10:41 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id QAA28027; Wed, 23 Apr 1997 16:10:39 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [PATCH] debug-ignored-errors ported to XEmacs
X-URL: ftp://gnjilux.cc.fer.hr/pub/unix/util/wget/
X-Save-Project-Gutenberg: <URL:http://www.promo.net/pg/nl/pgny_nov96.html>
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 23 Apr 1997 16:10:38 +0200
Message-ID: <kigzpupx21t.fsf@jagor.srce.hr>
Lines: 251
X-Mailer: Gnus v5.4.45/XEmacs 19.15

Have you ever bitched at the debuggers that pop up at every minor
error, after you set `debug-on-error' to t for debugging of your
favourite Lisp code?

Well, `debug-ignored-errors' serves for this -- the docstring is as
follows:

Documentation:
*List of errors for which the debugger should not be called.
Each element may be a condition-name or a regexp that matches error messages.
If any element applies to a given error, that error skips the debugger
and just returns to top level.
This overrides the variable `debug-on-error'.
It does not apply to errors handled by `condition-case'.

I have ported this to XEmacs.  As the patch is short, and this is my
first shot at modifying C code, I call to the interesting parties to
look at the patch, and see if I missed anything obvious.  For example,
I'm still shaky with GCPRO and such things.

Specifically, I am not sure what the four `if's in
`signal_call_debugger' are for.  There seems to be only one in the
equivalent place in GNU Emacs.  I've put the check on each of these
places.

The patch follows:

--- src/eval.c.orig	Wed Apr 23 14:27:18 1997
+++ src/eval.c	Wed Apr 23 15:56:51 1997
@@ -148,6 +148,10 @@
    if an error is handled by the command loop's error handler.  */
 Lisp_Object Vdebug_on_error;
 
+/* List of conditions and regexps specifying error messages which
+   do not enter the debugger even if Vdebug_on_errors says they should.  */
+Lisp_Object Vdebug_ignored_errors;
+
 /* List of conditions (non-nil atom means all) which cause a backtrace
    if any error is signalled.  */
 Lisp_Object Vstack_trace_on_signal;
@@ -468,6 +472,46 @@
   return 0;
 }
 
+/* Return 1 if an error with condition-symbols CONDITIONS,
+   and described by SIGNAL-DATA, should skip the debugger
+   according to debugger-ignore-errors.  */
+
+static int
+skip_debugger (Lisp_Object conditions, Lisp_Object data)
+{
+  Lisp_Object tail;
+  int first_string = 1;
+  Lisp_Object error_message;
+
+  for (tail = Vdebug_ignored_errors; CONSP (tail);
+       tail = XCONS (tail)->cdr)
+    {
+      if (STRINGP (XCONS (tail)->car))
+	{
+	  if (first_string)
+	    {
+	      error_message = Ferror_message_string (data);
+	      first_string = 0;
+	    }
+	  if (fast_string_match (XCONS (tail)->car, 0, error_message,
+				 0, -1, 0, ERROR_ME, 0) >= 0)
+	    return 1;
+	}
+      else
+	{
+	  Lisp_Object contail;
+
+          for (contail = conditions; CONSP (contail);
+	       contail = XCONS (contail)->cdr)
+            if (EQ (XCONS (tail)->car, XCONS (contail)->car))
+	      return 1;
+	}
+    }
+
+  return 0;
+}
+
+
 /* Actually generate a backtrace on STREAM. */
 
 static Lisp_Object
@@ -515,12 +559,16 @@
   Lisp_Object val = Qunbound;
   Lisp_Object all_handlers = Vcondition_handlers;
   int speccount = specpdl_depth_counter;
+  int skip;
   struct gcpro gcpro1;
   GCPRO1 (all_handlers);
 
   Vcondition_handlers = active_handlers;
 
-  if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only 
+  skip = skip_debugger (conditions, Fcons (sig, data));
+
+  if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only
+      && !skip
       && wants_debugger (Vstack_trace_on_error, conditions))
     {
       specbind (Qdebug_on_error, Qnil);
@@ -537,6 +585,7 @@
     }
       
   if (!entering_debugger && !*debugger_entered && !signal_vars_only
+      && !skip
       && (EQ (sig, Qquit)
 	  ? debug_on_quit
 	  : wants_debugger (Vdebug_on_error, conditions)))
@@ -552,6 +601,7 @@
     }
 
   if (!entering_debugger && !*stack_trace_displayed
+      && !skip
       && wants_debugger (Vstack_trace_on_signal, conditions))
     {
       specbind (Qdebug_on_error, Qnil);
@@ -568,6 +618,7 @@
     }
 
   if (!entering_debugger && !*debugger_entered
+      && !skip
       && (EQ (sig, Qquit)
 	  ? debug_on_quit
 	  : wants_debugger (Vdebug_on_signal, conditions)))
@@ -5216,6 +5267,16 @@
 See also variable `stack-trace-on-error'.
 */ );
   Vstack_trace_on_signal = Qnil;
+
+  DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /*
+*List of errors for which the debugger should not be called.
+Each element may be a condition-name or a regexp that matches error messages.
+If any element applies to a given error, that error skips the debugger
+and just returns to top level.
+This overrides the variable `debug-on-error'.
+It does not apply to errors handled by `condition-case'.
+*/ );
+  Vdebug_ignored_errors = Qnil;
 
   DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
 *Non-nil means enter debugger if an unhandled error is signalled.
--- lisp/prim/loaddefs.el.orig	Wed Apr 23 15:09:11 1997
+++ lisp/prim/loaddefs.el	Wed Apr 23 15:27:46 1997
@@ -90,6 +90,74 @@
 		  ".lof" ".blg" ".bbl" ".glo" ".idx" ".lot" ".fmt"
 		  ".diff" ".oi"))))
 
+(setq debug-ignored-errors
+      (purecopy
+       '(beginning-of-line beginning-of-buffer end-of-line
+	 end-of-buffer end-of-file buffer-read-only
+	 "^Previous command was not a yank$"
+	 "^Minibuffer window is not active$"
+	 "^End of history; no next item$"
+	 "^Beginning of history; no preceding item$"
+	 "^No recursive edit is in progress$"
+	 "^Changes to be undone are outside visible portion of buffer$"
+	 "^No undo information in this buffer$"
+	 "^No further undo information$"
+	 "^Save not confirmed$"
+	 "^Recover-file cancelled\\.$"
+
+	 ;; comint
+	 "^Not at command line$"
+	 "^Empty input ring$"
+	 "^No history$"
+	 "^Not found$";; To common?
+	 "^Current buffer has no process$"
+
+	 ;; dabbrev
+	 "^No dynamic expansion for \".*\" found\\.$"
+	 "^No further dynamic expansions for \".*\" found\\.$"
+	 "^No further dynamic expansions for `.*' found$"
+
+	 ;; Completion
+	 "^To complete, the point must be after a symbol at least [0-9]* character long\\.$"
+	 "^The string \".*\" is too short to be saved as a completion\\.$"
+
+	 ;; Compile
+	 "^No more errors\\( yet\\|\\)$"
+
+	 ;; Gnus
+	 "^NNTP: Connection closed\\.$"
+
+	 ;; info
+	 "^Node has no Previous$"
+	 "^No \".*\" in index$"
+
+	 ;; imenu
+	 "^No items suitable for an index found in this buffer\\.$"
+	 "^The mode \".*\" does not take full advantage of imenu\\.el yet\\.$"
+
+	 ;; ispell
+	 "^No word found to check!$"
+
+	 ;; man
+
+	 ;; etags
+	 "^No tags table in use!  Use .* to select one\\.$"
+	 "^There is no default tag$"
+	 "^No previous tag locations$"
+	 "^File .* is not a valid tags table$"
+	 "^No \\(more \\|\\)tags \\(matching\\|containing\\) "
+	 "^Rerun etags: `.*' not found in "
+	 "^All files processed\\.$"
+	 "^No .* or .* in progress.$"
+	 "^File .* not in current tags tables$"
+	 "No tags table loaded."
+	 "^Nothing to complete$"
+
+	 ;; BBDB
+	 "^no previous record$"
+	 "^no next record$")))
+
+
 (make-variable-buffer-local 'indent-tabs-mode)
 
 
--- src/ChangeLog.orig	Wed Apr 23 14:34:02 1997
+++ src/ChangeLog	Wed Apr 23 16:03:31 1997
@@ -1,3 +1,8 @@
+Wed Apr 23 16:03:20 1997  Hrvoje Niksic  <hniksic@srce.hr>
+
+	* eval.c (skip_debugger): New function.
+	(signal_call_debugger): Use it.
+
 Tue Apr 22 08:22:22 1997  Hrvoje Niksic  <hniksic@srce.hr>
 
 	* balloon-x.c, balloon_help.c, balloon_help.h: Modified to conform
--- lisp/ChangeLog.orig	Wed Apr 23 16:04:17 1997
+++ lisp/ChangeLog	Wed Apr 23 16:04:27 1997
@@ -1,3 +1,7 @@
+Wed Apr 23 16:04:22 1997  Hrvoje Niksic  <hniksic@srce.hr>
+
+	* prim/loaddefs.el (debug-ignored-errors): Initialize.
+
 Tue Apr 22 07:01:20 1997  Hrvoje Niksic  <hniksic@srce.hr>
 
 	* prim/keydefs.el (global-map): Bind it to `C-z'.


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
You'll notice that perl is not itself written in Perl.
                                                 -- The Perl FAQ

