Subject: 26.0.50; edebug-max-depth should be customizable

From: Gemini Lasswell <[email-masked]>
Date: Sun, 16 Oct 2016 14:58:44 -0700

Edebug's recursion limit is currently 150, but this is not enough for
the following files in the Emacs source tree:

lisp/calc/calc-ext.el
lisp/help-macro.el
lisp/international/fontset.el

The latter two can be successfully instrumented with edebug-max-depth
set to 200, but the minimum value necessary for calc-ext.el is somewhere
between 500 and 1000. All three of these files contain large quoted
lists.

I'm attaching a patch to accomplish this. I chose to mention
max-lisp-eval-depth and max-specpdl-size in the defcustom docstring, but
I also noticed that Edebug temporarily bumps max-lisp-eval-depth up by
800 while it's working. I could modify the patch to replace the 800 by
something along the lines of (+ 200 (* max-edebug-depth 4)), if someone
with more Emacs experience than me says it is a good idea. Edebug also
increases max-specpdl-size (by 2000) so that probably would also need to
be changed in the code.

>From 860deea4d3ff07c105435ac36c8477fcb6e1d008 Mon Sep 17 00:00:00 2001
From: gazally <[email-masked]>
Date: Sun, 16 Oct 2016 13:34:56 -0700
Subject: [PATCH] Change edebug-max-depth from defconst to defcustom

Make edebug-max-depth customizable to give Edebug the ability to
instrument code containing very large quoted lists.
* lisp/emacs-lisp/edebug.el (edebug-max-depth): Add defcustom.
---
 lisp/emacs-lisp/edebug.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 6918539..facbda8 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -112,6 +112,18 @@ edebug-eval-macro-args
   :type 'boolean
   :group 'edebug)
 
+(defcustom edebug-max-depth 150
+  "Maximum recursion depth when instrumenting code.
+This limit stops recursion if an Edebug specification contains an
+infinite loop. When Edebug is instrumenting code containing very
+large quoted lists, it may reach this limit and give the error
+message \"Too deep - perhaps infinite loop in spec?\" You can
+safely make this limit considerably larger than its default
+value, but you may also need to increase `max-lisp-eval-depth'
+and `max-specpdl-size'."
+  :type 'integer
+  :group 'edebug)
+
 (defcustom edebug-save-windows t
   "If non-nil, Edebug saves and restores the window configuration.
 That takes some time, so if your program does not care what happens to
@@ -1452,7 +1464,6 @@ edebug-list-form
 (defvar edebug-after-dotted-spec nil)
 
 (defvar edebug-matching-depth 0)  ;; initial value
-(defconst edebug-max-depth 150)  ;; maximum number of matching recursions.

 ;;; Failure to match
-- 
2.10.1