Skip to content

Commit 3963ca0

Browse files
committed
next iteration
Proceed as sketched in the discussion of the pull request: - Extend the documentation of `Pager` such that `start` can be a string, meaning a search string (without initial `/`), - change the calls of the different pagers accordingly, and - state that external pagers must have command line options `+n` and `+str`. (Also fix a problem with `PAGER_BUILTIN` if a too large line number is given as `start`.)
1 parent 3f12664 commit 3963ca0

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

lib/methwhy.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ BIND_GLOBAL("PageSource", function ( fun, nr... )
522522
s := First(ss, a-> ':' in a);
523523
if s <> fail then
524524
ss := SplitString(s,":","");
525-
l := Concatenation("/Obj Func", ss[2]);
525+
l := Concatenation("Obj Func", ss[2]);
526526
fi;
527527
fi;
528528
fi;

lib/pager.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
## <P/>
3131
## At least on a UNIX system one should use an external pager program like
3232
## <C>less</C> or <C>more</C>.
33-
## &GAP; assumes that this program has a command line option <C>+nr</C>
34-
## which starts the display of the text with line number <C>nr</C>.
33+
## &GAP; assumes that this program has command line options <C>+nr</C> and
34+
## <C>+/str</C> which start the display of the text with line number
35+
## <C>nr</C> or at the line with the first occurrence of the string
36+
## <C>str</C>.
3537
## <P/>
3638
## Which pager is used can be controlled by setting the user preference
3739
## <C>"Pager"</C>.
@@ -77,9 +79,12 @@
7779
## </Item>
7880
## <Mark><C>start</C></Mark>
7981
## <Item>
80-
## must be a positive integer.
81-
## This is interpreted as the number of the first line shown by the pager
82-
## (one may see the beginning of the text via back scrolling).
82+
## must be a positive integer or a string.
83+
## An integer is interpreted as the number of the first line shown by the
84+
## pager, a string is interpreted as a search string such that the first
85+
## line containing this string is the first line shown by the pager
86+
## (in both cases, one may see the beginning of the text via back
87+
## scrolling),
8388
## </Item>
8489
## <Mark><C>exitAtEnd</C></Mark>
8590
## <Item>

lib/pager.gi

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
##
3636
## .formatted (true/false) If true, the builtin pager tries to avoid
3737
## line breaks by GAP's Print.
38-
## .start (number) The display is started with line .start, but
38+
## .start (number/string) The display is started with line .start or
39+
## at the first line containing .start, but
3940
## beginning is available via back scrolling.
40-
## .exitAtEnd (true/false) If true (default), the pager is terminated
41-
## as soon as the end of the list is reached;
41+
## .exitAtEnd (true/false) If true (default), the builtin pager is
42+
## terminated as soon as the end of the list is
43+
## reached;
4244
## if false, entering 'q' is necessary in order to
4345
## return from the pager.
4446
##
@@ -117,8 +119,8 @@ GAPInfo.UserPreferences.Pager := UserPreference("Pager");
117119
## <Item>
118120
## a positive integer denoting the position of the first line that is
119121
## shown,
120-
## or a string starting with <C>"/"</C>, meaning that the first line
121-
## containing the substring behind <C>"/"</C> shall be shown;
122+
## or a string meaning that the first line containing this string
123+
## shall be shown;
122124
## the default is 1,
123125
## </Item>
124126
## <Mark>exitAtEnd</Mark>
@@ -132,8 +134,8 @@ GAPInfo.UserPreferences.Pager := UserPreference("Pager");
132134
# If the text contains ANSI color sequences we reset the terminal before
133135
# we print the last line.
134136
BindGlobal("PAGER_BUILTIN", function( r )
135-
local formatted, linepos, exitAtEnd, lines, search, size, wd, pl, count, i,
136-
stream, halt, lenhalt, delhaltline, from, len, emptyline, char, out;
137+
local formatted, linepos, exitAtEnd, lines, size, wd, pl, count, i, stream,
138+
halt, lenhalt, delhaltline, from, len, emptyline, char, out;
137139

138140
formatted := false;
139141
linepos := 1;
@@ -167,10 +169,12 @@ BindGlobal("PAGER_BUILTIN", function( r )
167169
if IsBound(r.start) then
168170
if IsPosInt(r.start) then
169171
linepos := r.start;
170-
elif IsString(r.start) and StartsWith(r.start, "/") then
171-
search := r.start{[2..Length(r.start)]};
172+
elif IsString(r.start) then
172173
linepos := PositionProperty(lines,
173-
l -> PositionSublist(l, search) <> fail);
174+
l -> PositionSublist(l, r.start) <> fail);
175+
if linepos = fail then
176+
linepos := 1;
177+
fi;
174178
else
175179
Error("unsupported r.start value: ", r.start);
176180
fi;
@@ -240,6 +244,11 @@ BindGlobal("PAGER_BUILTIN", function( r )
240244
from := linepos;
241245
len := Length(lines);
242246
emptyline:= String( "", size[1]-2 );
247+
if len < from then
248+
# Ignore the start line.
249+
# (The pager 'less' shows a warning and then goes to the first line.)
250+
from:= 1;
251+
fi;
243252
repeat
244253
for i in [from..Minimum(len, from+size[2]-2)] do
245254
pl(lines[i], "\n");
@@ -312,7 +321,9 @@ BindGlobal("PAGER_EXTERNAL", function( lines )
312321
od;
313322
lines := str;
314323
fi;
315-
if linepos > 1 then
324+
if IsString(linepos) then
325+
cmdargs := [Concatenation("+/", linepos)];
326+
elif linepos > 1 then
316327
cmdargs := [Concatenation("+", String(linepos))];
317328
else
318329
cmdargs := [];

0 commit comments

Comments
 (0)