Skip to content

Commit

Permalink
Implement ESC-G command.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jul 14, 2014
1 parent ef6da45 commit 751e106
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
26 changes: 26 additions & 0 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,32 @@ ch_end_seek()
return (0);
}

/*
* Seek to the last position in the file that is currently buffered.
*/
public int
ch_end_buffer_seek()
{
register struct buf *bp;
register struct bufnode *bn;
POSITION buf_pos;
POSITION end_pos;

if (thisfile == NULL || (ch_flags & CH_CANSEEK))
return (ch_end_seek());

end_pos = 0;
FOR_BUFS(bn)
{
bp = bufnode_buf(bn);
buf_pos = (bp->block * LBUFSIZE) + bp->datasize;
if (buf_pos > end_pos)
end_pos = buf_pos;
}

return (ch_seek(end_pos));
}

/*
* Seek to the beginning of the file, or as close to it as we can get.
* We may not be able to seek there if input is a pipe and the
Expand Down
1 change: 1 addition & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#define A_PREV_TAG 54
#define A_FILTER 55
#define A_F_UNTIL_HILITE 56
#define A_GOEND_BUF 57

#define A_INVALID 100
#define A_NOACTION 101
Expand Down
13 changes: 12 additions & 1 deletion command.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ forw_loop(until_hilite)
return (A_NOACTION);

cmd_exec();
jump_forw();
jump_forw_buffered();
curr_len = ch_length();
highest_hilite = until_hilite ? curr_len : NULL_POSITION;
ignore_eoi = 1;
Expand Down Expand Up @@ -1325,6 +1325,17 @@ commands()
jump_back(number);
break;

case A_GOEND_BUF:
/*
* Go to line N, default last buffered byte.
*/
cmd_exec();
if (number <= 0)
jump_forw_buffered();
else
jump_back(number);
break;

case A_GOPOS:
/*
* Go to a specified byte position in the file.
Expand Down
1 change: 1 addition & 0 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static unsigned char cmdtable[] =
ESC,CONTROL('F'),0, A_F_BRACKET,
ESC,CONTROL('B'),0, A_B_BRACKET,
'G',0, A_GOEND,
ESC,'G',0, A_GOEND_BUF,
ESC,'>',0, A_GOEND,
'>',0, A_GOEND,
SK(SK_END),0, A_GOEND,
Expand Down
14 changes: 14 additions & 0 deletions jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ jump_forw()
}
}

/*
* Jump to the last buffered line in the file.
*/
public void
jump_forw_buffered()
{
if (ch_end_buffer_seek())
{
error("Cannot seek to end of buffers", NULL_PARG);
return;
}
jump_line_loc(ch_tell(), sc_height-1);
}

/*
* Jump to line n in the file.
*/
Expand Down
3 changes: 3 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ Go to line N in the file, default the end of the file.
(Warning: this may be slow if N is large,
or if N is not specified and
standard input, rather than a file, is being read.)
.IP "ESC-G"
Same as G, except if no number N is specified and the input is standard input,
goes to the last line which is currently buffered.
.IP "p or %"
Go to a position N percent into the file.
N should be between 0 and 100, and may contain a decimal point.
Expand Down
1 change: 1 addition & 0 deletions lesskey.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct cmdname cmdnames[] =
{ "forw-search", A_F_SEARCH },
{ "forw-window", A_F_WINDOW },
{ "goto-end", A_GOEND },
{ "goto-end-buffered", A_GOEND_BUF },
{ "goto-line", A_GOLINE },
{ "goto-mark", A_GOMARK },
{ "help", A_HELP },
Expand Down
1 change: 1 addition & 0 deletions lesskey.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ default command keys used by less:
\ee> goto-end
> goto-end
\eke goto-end
\eeG goto-end-buffered
= status
^G status
:f status
Expand Down
1 change: 1 addition & 0 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern char *prproto[];
extern char *eqproto;
extern char *hproto;
extern char *wproto;
extern char *every_first_cmd;
extern IFILE curr_ifile;
extern char version[];
extern int jump_sline;
Expand Down

0 comments on commit 751e106

Please sign in to comment.