Skip to content

Commit bc114ff

Browse files
committed
Add WhereDepth for UserPreference
1 parent 5ccd08f commit bc114ff

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

doc/ref/mloop.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,11 @@ is an example in the ⪆ code where the idea is actually used.
743743
<Index Subkey="GAP3 name for Where">Backtrace</Index>
744744
<Index>Stack trace</Index>
745745
shows the last <A>nr</A> commands on the execution stack during whose execution
746-
the error occurred. If not given, <A>nr</A> defaults to 5. (Assume, for the
746+
the error occurred. If not given, <A>nr</A> defaults to the value of the
747+
<C>WhereDepth</C> user preference (initially 5).
748+
If <A>nr</A> or the <C>WhereDepth</C> preference is not a non-negative integer,
749+
it is treated as 5.
750+
(Assume, for the
747751
following example, that after the last example <Ref Func="OnBreak"/>
748752
has been set back to its default value.). <Ref Func="WhereWithVars"/> acts the
749753
same as <Ref Func="Where"/> while also showing the arguments and local

lib/error.g

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ end);
169169

170170
BIND_GLOBAL("WHERE_INTERNAL", function(depth, showlocals)
171171
local activecontext;
172+
if not IsInt(depth) or depth < 0 then
173+
depth := 5;
174+
fi;
172175
if ErrorLVars = fail or ErrorLVars = GetBottomLVars() then
173176
PrintTo(ERROR_OUTPUT, "not in any function ");
174177
else
@@ -181,7 +184,7 @@ end);
181184
BIND_GLOBAL("WhereWithVars", function(arg)
182185
local depth;
183186
if LEN_LIST(arg) = 0 then
184-
depth := 5;
187+
depth := UserPreference("WhereDepth");
185188
else
186189
depth := arg[1];
187190
fi;
@@ -192,7 +195,7 @@ end);
192195
BIND_GLOBAL("Where", function(arg)
193196
local depth;
194197
if LEN_LIST(arg) = 0 then
195-
depth := 5;
198+
depth := UserPreference("WhereDepth");
196199
else
197200
depth := arg[1];
198201
fi;

lib/init.g

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,17 @@ DeclareUserPreference( rec(
582582
default:= 3,
583583
check:= val -> IsInt( val ) and 0 <= val,
584584
) );
585+
DeclareUserPreference( rec(
586+
name:= "WhereDepth",
587+
description:= [
588+
"The number of stack frames shown by <C>Where</C> and <C>WhereWithVars</C> \
589+
when called without an explicit depth argument, e.g. in the default <C>OnBreak</C> \
590+
handler. Increase this value if the default of 5 is not enough to locate the \
591+
source of an error."
592+
],
593+
default:= 5,
594+
check:= val -> IsInt( val ) and 0 <= val,
595+
) );
585596
DeclareUserPreference( rec(
586597
name:= "ReproducibleBehaviour",
587598
description:= [

tst/testinstall/error.tst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ gap> if false then Stabilizer; fi;
3434
Syntax error: found an expression when a statement was expected in stream:1
3535
if false then Stabilizer; fi;
3636
^
37+
38+
#
39+
# WhereDepth user preference
40+
#
41+
gap> UserPreference("WhereDepth");
42+
5
43+
gap> SetUserPreference("WhereDepth", 10);
44+
gap> UserPreference("WhereDepth");
45+
10
46+
gap> SetUserPreference("WhereDepth", 0);
47+
gap> UserPreference("WhereDepth");
48+
0
49+
gap> SetUserPreference("WhereDepth", 5);
50+
gap> UserPreference("WhereDepth");
51+
5

0 commit comments

Comments
 (0)