35
35
# #
36
36
# # .formatted (true/false) If true, the builtin pager tries to avoid
37
37
# # 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
39
40
# # 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;
42
44
# # if false, entering 'q' is necessary in order to
43
45
# # return from the pager.
44
46
# #
@@ -117,8 +119,8 @@ GAPInfo.UserPreferences.Pager := UserPreference("Pager");
117
119
# # <Item>
118
120
# # a positive integer denoting the position of the first line that is
119
121
# # 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;
122
124
# # the default is 1,
123
125
# # </Item>
124
126
# # <Mark>exitAtEnd</Mark>
@@ -132,8 +134,8 @@ GAPInfo.UserPreferences.Pager := UserPreference("Pager");
132
134
# If the text contains ANSI color sequences we reset the terminal before
133
135
# we print the last line.
134
136
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;
137
139
138
140
formatted := false ;
139
141
linepos := 1 ;
@@ -167,10 +169,12 @@ BindGlobal("PAGER_BUILTIN", function( r )
167
169
if IsBound (r.start) then
168
170
if IsPosInt(r.start) then
169
171
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
172
173
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 ;
174
178
else
175
179
Error(" unsupported r.start value: " , r.start);
176
180
fi ;
@@ -240,6 +244,11 @@ BindGlobal("PAGER_BUILTIN", function( r )
240
244
from := linepos;
241
245
len := Length(lines);
242
246
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 ;
243
252
repeat
244
253
for i in [ from.. Minimum(len, from+ size[ 2 ] - 2 )] do
245
254
pl(lines[ i] , " \n " );
@@ -312,7 +321,9 @@ BindGlobal("PAGER_EXTERNAL", function( lines )
312
321
od ;
313
322
lines := str;
314
323
fi ;
315
- if linepos > 1 then
324
+ if IsString(linepos) then
325
+ cmdargs := [ Concatenation(" +/" , linepos)] ;
326
+ elif linepos > 1 then
316
327
cmdargs := [ Concatenation(" +" , String(linepos))] ;
317
328
else
318
329
cmdargs := [] ;
0 commit comments