diff --git a/forwback.c b/forwback.c index 5c817e83..3149e8e5 100644 --- a/forwback.c +++ b/forwback.c @@ -35,6 +35,7 @@ extern int ignore_eoi; extern int header_lines; extern int header_cols; extern int full_screen; +extern int stop_on_form_feed; extern POSITION header_start_pos; #if HILITE_SEARCH extern size_t size_linebuf; @@ -345,6 +346,8 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, int nblank) continue; } put_line(); + if (stop_on_form_feed && !do_repaint && line_is_ff() && position(TOP) != NULL_POSITION) + break; #if 0 /* {{ * Can't call clear_eol here. The cursor might be at end of line @@ -431,6 +434,8 @@ public void back(int n, POSITION pos, lbool force, lbool only_last) home(); add_line(); put_line(); + if (stop_on_form_feed && line_is_ff()) + break; } } if (nlines == 0) diff --git a/less.hlp b/less.hlp index b34bfa3f..9812f6c1 100644 --- a/less.hlp +++ b/less.hlp @@ -221,6 +221,8 @@ Automatically determine the size of the input file. --follow-name The F command changes files if the input file is renamed. + --form-feed + Stop scrolling when a form feed character is reached. --header=[_L[,_C[,_N]]] Use _L lines (starting at line _N) and _C columns as headers. --incsearch diff --git a/less.nro.VER b/less.nro.VER index 77950bf3..8398e8e5 100644 --- a/less.nro.VER +++ b/less.nro.VER @@ -1330,6 +1330,10 @@ If the reopen succeeds and the file is a different file from the original with the same name as the original (now renamed) file), .B less will display the contents of that new file. +.IP "\-\-form-feed" +When scrolling forward or backward in the file, +stop if a line beginning with a form feed character (\(haL) is reached. +This can be useful when viewing a file which uses form feeds between pages. .IP "\-\-header=\fIL\fP,\fIC\fP,\fIN\fP" .RS Sets the number of header lines and columns displayed on the screen. diff --git a/line.c b/line.c index bd7b3ac0..b2b56773 100644 --- a/line.c +++ b/line.c @@ -53,6 +53,7 @@ static int curr_last_ansi; public size_t size_linebuf = 0; /* Size of line buffer (and attr buffer) */ static struct ansi_state *line_ansi = NULL; static lbool ansi_in_line; +static int ff_starts_line; static int hlink_in_line; static int line_mark_attr; static int cshift; /* Current left-shift of output line buffer */ @@ -252,6 +253,7 @@ public void prewind(void) pendc = '\0'; in_hilite = 0; ansi_in_line = FALSE; + ff_starts_line = -1; hlink_in_line = 0; line_mark_attr = 0; line_pos = NULL_POSITION; @@ -1038,9 +1040,16 @@ public int pappend_b(char c, POSITION pos, lbool before_pendc) public int pappend(char c, POSITION pos) { + if (ff_starts_line < 0) + ff_starts_line = (c == CONTROL('L')); return pappend_b(c, pos, FALSE); } +public lbool line_is_ff(void) +{ + return (ff_starts_line == 1); +} + static int store_control_char(LWCHAR ch, constant char *rep, POSITION pos) { if (ctldisp == OPT_ON) diff --git a/opttbl.c b/opttbl.c index 76878de0..32a862a8 100644 --- a/opttbl.c +++ b/opttbl.c @@ -82,6 +82,7 @@ public int proc_tab; /* Special handling of tab */ public int proc_return; /* Special handling of carriage return */ public int match_shift; /* Extra horizontal shift on search match */ public int no_paste; /* Don't accept pasted input */ +public int stop_on_form_feed; /* Stop scrolling on a line starting with form feed */ public long match_shift_fraction = NUM_FRAC_DENOM/2; /* 1/2 of screen width */ public char intr_char = CONTROL('X'); /* Char to interrupt reads */ #if HILITE_SEARCH @@ -163,6 +164,7 @@ static struct optname want_filesize_optname = { "file-size", NULL }; static struct optname status_line_optname = { "status-line", NULL }; static struct optname header_optname = { "header", NULL }; static struct optname no_paste_optname = { "no-paste", NULL }; +static struct optname form_feed_optname = { "form-feed", NULL }; static struct optname nonum_headers_optname = { "no-number-headers", NULL }; static struct optname nosearch_headers_optname = { "no-search-headers", NULL }; static struct optname nosearch_header_lines_optname = { "no-search-header-lines", NULL }; @@ -621,6 +623,14 @@ static struct loption option[] = NULL } }, + { OLETTER_NONE, &form_feed_optname, + BOOL, OPT_OFF, &stop_on_form_feed, NULL, + { + "Don't stop on form feed", + "Stop on form feed", + NULL + } + }, { OLETTER_NONE, &nonum_headers_optname, BOOL|REPAINT, 0, &nonum_headers, NULL, {