From bc114ff540d25cc3dd08c43d11a3a72acb375414 Mon Sep 17 00:00:00 2001
From: Kamil Zabielski <50334623+limakzi@users.noreply.github.com>
Date: Tue, 10 Mar 2026 09:43:17 +0100
Subject: [PATCH 1/2] Add WhereDepth for UserPreference
---
doc/ref/mloop.xml | 6 +++++-
lib/error.g | 7 +++++--
lib/init.g | 11 +++++++++++
tst/testinstall/error.tst | 15 +++++++++++++++
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/doc/ref/mloop.xml b/doc/ref/mloop.xml
index a0f844dd4d..678a66b8ce 100644
--- a/doc/ref/mloop.xml
+++ b/doc/ref/mloop.xml
@@ -743,7 +743,11 @@ is an example in the &GAP; code where the idea is actually used.
Backtrace
Stack trace
shows the last nr commands on the execution stack during whose execution
-the error occurred. If not given, nr defaults to 5. (Assume, for the
+the error occurred. If not given, nr defaults to the value of the
+WhereDepth user preference (initially 5).
+If nr or the WhereDepth preference is not a non-negative integer,
+it is treated as 5.
+(Assume, for the
following example, that after the last example
has been set back to its default value.). acts the
same as while also showing the arguments and local
diff --git a/lib/error.g b/lib/error.g
index fbaceed8a3..7b403f911d 100644
--- a/lib/error.g
+++ b/lib/error.g
@@ -169,6 +169,9 @@ end);
BIND_GLOBAL("WHERE_INTERNAL", function(depth, showlocals)
local activecontext;
+ if not IsInt(depth) or depth < 0 then
+ depth := 5;
+ fi;
if ErrorLVars = fail or ErrorLVars = GetBottomLVars() then
PrintTo(ERROR_OUTPUT, "not in any function ");
else
@@ -181,7 +184,7 @@ end);
BIND_GLOBAL("WhereWithVars", function(arg)
local depth;
if LEN_LIST(arg) = 0 then
- depth := 5;
+ depth := UserPreference("WhereDepth");
else
depth := arg[1];
fi;
@@ -192,7 +195,7 @@ end);
BIND_GLOBAL("Where", function(arg)
local depth;
if LEN_LIST(arg) = 0 then
- depth := 5;
+ depth := UserPreference("WhereDepth");
else
depth := arg[1];
fi;
diff --git a/lib/init.g b/lib/init.g
index 810305951f..06042e0624 100644
--- a/lib/init.g
+++ b/lib/init.g
@@ -582,6 +582,17 @@ DeclareUserPreference( rec(
default:= 3,
check:= val -> IsInt( val ) and 0 <= val,
) );
+DeclareUserPreference( rec(
+ name:= "WhereDepth",
+ description:= [
+ "The number of stack frames shown by Where and WhereWithVars \
+when called without an explicit depth argument, e.g. in the default OnBreak \
+handler. Increase this value if the default of 5 is not enough to locate the \
+source of an error."
+ ],
+ default:= 5,
+ check:= val -> IsInt( val ) and 0 <= val,
+ ) );
DeclareUserPreference( rec(
name:= "ReproducibleBehaviour",
description:= [
diff --git a/tst/testinstall/error.tst b/tst/testinstall/error.tst
index 9cb0d353f7..e75a4a80ba 100644
--- a/tst/testinstall/error.tst
+++ b/tst/testinstall/error.tst
@@ -34,3 +34,18 @@ gap> if false then Stabilizer; fi;
Syntax error: found an expression when a statement was expected in stream:1
if false then Stabilizer; fi;
^
+
+#
+# WhereDepth user preference
+#
+gap> UserPreference("WhereDepth");
+5
+gap> SetUserPreference("WhereDepth", 10);
+gap> UserPreference("WhereDepth");
+10
+gap> SetUserPreference("WhereDepth", 0);
+gap> UserPreference("WhereDepth");
+0
+gap> SetUserPreference("WhereDepth", 5);
+gap> UserPreference("WhereDepth");
+5
From 765aaf1a67ac13739bb8776e8f940a2643358f88 Mon Sep 17 00:00:00 2001
From: Kamil Zabielski <50334623+limakzi@users.noreply.github.com>
Date: Sun, 15 Mar 2026 10:00:59 +0100
Subject: [PATCH 2/2] Improve documentation for WhereDepth
Co-authored-by: Max Horn
---
doc/ref/mloop.xml | 5 +++++
lib/init.g | 3 +--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/doc/ref/mloop.xml b/doc/ref/mloop.xml
index 678a66b8ce..5292ad5a52 100644
--- a/doc/ref/mloop.xml
+++ b/doc/ref/mloop.xml
@@ -753,6 +753,11 @@ has been set back to its default value.). acts the
same as while also showing the arguments and local
variables of each function.
+ acts the same as while also
+showing the arguments and local variables of each function.
+
+The following example assumes that is set to its default
+value.
StabChain(SymmetricGroup(100)); # After this we typed ^C
user interrupt at
diff --git a/lib/init.g b/lib/init.g
index 06042e0624..03601c810a 100644
--- a/lib/init.g
+++ b/lib/init.g
@@ -587,8 +587,7 @@ DeclareUserPreference( rec(
description:= [
"The number of stack frames shown by Where and WhereWithVars \
when called without an explicit depth argument, e.g. in the default OnBreak \
-handler. Increase this value if the default of 5 is not enough to locate the \
-source of an error."
+handler."
],
default:= 5,
check:= val -> IsInt( val ) and 0 <= val,