Skip to content

Commit

Permalink
Add --proc-backspace, --proc-tab and --proc-return options.
Browse files Browse the repository at this point in the history
Also fix bug toggling -U while search highlighting is active.
  • Loading branch information
gwsw committed Feb 11, 2023
1 parent 68c630c commit 96f2bcd
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 19 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

* Add --intr option (github #224).

* Add --proc-backspace, --proc-tab and --proc-return options.

* Add --show-preproc-errors option (github #258).

* Add LESS_LINES and LESS_COLUMNS environment variables.
Expand Down
5 changes: 5 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern int ignore_eoi;
extern int secure;
extern int hshift;
extern int bs_mode;
extern int proc_backspace;
extern int show_attn;
extern int status_col;
extern POSITION highest_hilite;
Expand Down Expand Up @@ -84,6 +85,7 @@ static int optgetname;
static POSITION bottompos;
static int save_hshift;
static int save_bs_mode;
static int save_proc_backspace;
#if PIPEC
static char pipec;
#endif
Expand Down Expand Up @@ -1608,6 +1610,7 @@ public void commands(void)
*/
hshift = save_hshift;
bs_mode = save_bs_mode;
proc_backspace = save_proc_backspace;
if (edit_prev(1) == 0)
break;
}
Expand Down Expand Up @@ -1716,6 +1719,8 @@ public void commands(void)
hshift = 0;
save_bs_mode = bs_mode;
bs_mode = BS_SPECIAL;
save_proc_backspace = proc_backspace;
proc_backspace = OPT_OFF;
(void) edit(FAKE_HELPFILE);
break;

Expand Down
14 changes: 13 additions & 1 deletion less.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
-T [_t_a_g_s_f_i_l_e] --tag-file=[_t_a_g_s_f_i_l_e]
Use an alternate tags file.
-u -U .... --underline-special --UNDERLINE-SPECIAL
Change handling of backspaces.
Change handling of backspaces, tabs and carriage returns.
-V ........ --version
Display the version number of "less".
-w ........ --hilite-unread
Expand Down Expand Up @@ -247,6 +247,18 @@
Set default options for every search.
--show-preproc-errors
Display a message if preprocessor exits with an error status.
--proc-backspace
Process backspaces for bold/underline.
--SPECIAL-BACKSPACE
Treat backspaces as control characters.
--proc-return
Delete carriage returns before newline.
--SPECIAL-RETURN
Treat carriage returns as control characters.
--proc-tab
Expand tabs to spaces.
--SPECIAL-TAB
Treat tabs as control characters.
--status-col-width=_N
Set the width of the -J status column to _N characters.
--status-line
Expand Down
39 changes: 37 additions & 2 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ Underlined text.
.RE

.RS
The uppercase letters can be used only when the \-\-use-color option is enabled.
The uppercase letters and digits can be used only when the \-\-use-color option is enabled.
When text color is specified by both an uppercase letter and a lowercase letter,
the uppercase letter takes precedence.
For example, error messages are normally displayed as standout text.
Expand Down Expand Up @@ -692,7 +692,7 @@ White
.IP "y"
Yellow
.PP
The corresponding upper-case letter denotes a brighter shade of the color.
The corresponding uppercase letter denotes a brighter shade of the color.
For example, \-DNGk displays line numbers as bright green text on a black
background, and \-DEbR displays error messages as blue text on a
bright red background.
Expand Down Expand Up @@ -1071,6 +1071,9 @@ Unicode formatting characters, such as the Byte Order Mark,
are sent to the terminal.
Text which is overstruck or underlined can be searched for
if neither \-u nor \-U is in effect.
.sp
See also the \-\-proc-backspace, \-\-proc-tab,
and \-\-proc-return options.
.IP "\-V or \-\-version"
Displays the version number of
.BR less .
Expand Down Expand Up @@ -1271,6 +1274,38 @@ Line number 1 is assigned to the first line after any header lines.
Searches do not include header lines or header columns.
.IP "\-\-no-vbell"
Disables the terminal's visual bell.
.IP "\-\-proc-backspace"
If set, backspaces are handled as if neither the \-u option
nor the \-U option were set, even if one of those options is set.
That is, backspaces adjacent to underscores cause text to be
displayed in underline mode, and backspaces between identical
characters cause text to be displayed in boldface mode.
This allows control of backspace handling separate from
handling of tabs and carriage returns.
If not set, backspace handling is controlled by the \-u and \-U options.
.IP "\-\-PROC-BACKSPACE"
If set, backspaces are handles as if the \-u option were set;
that is backspaces are treated as control characters.
.IP "\-\-proc-return"
If set, carriage returns are handled as if neither the \-u option
nor the \-U option were set, even if one of those options is set.
That is, a carriage return immediately before a newline is deleted.
This allows control of carriage return handling separate from
handling of backspaces and tabs.
If not set, carriage return handling is controlled by the \-u and \-U options.
.IP "\-\-PROC-RETURN"
If set, carriage returns are handles as if the \-u option were set;
that is carriage returns are treated as control characters.
.IP "\-\-proc-tab"
If set, tabs are handled as if neither the \-u option
nor the \-U option were set, even if one of those options is set.
That is, tabs are expanded to spaces.
This allows control of tab handling separate from
handling of backspaces and carriage returns.
If not set, tab handling is controlled by the \-u and \-U options.
.IP "\-\-PROC-TAB"
If set, tabs are handles as if the \-u option were set;
that is tabs are treated as control characters.
.IP "\-\-redraw-on-quit"
When quitting, after sending the terminal deinitialization string,
redraws the entire last screen.
Expand Down
21 changes: 9 additions & 12 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ static int do_append(LWCHAR ch, char *rep, POSITION pos);

extern int sigs;
extern int bs_mode;
extern int proc_backspace;
extern int proc_tab;
extern int proc_return;
extern int linenums;
extern int ctldisp;
extern int twiddle;
Expand Down Expand Up @@ -893,7 +896,7 @@ public int pappend(int c, POSITION pos)
pendc = '\0';
}

if (c == '\r' && bs_mode == BS_SPECIAL)
if (c == '\r' && (proc_return == OPT_ON || (bs_mode == BS_SPECIAL && proc_return == OPT_OFF)))
{
if (mbc_buf_len > 0) /* utf_mode must be on. */
{
Expand Down Expand Up @@ -1021,15 +1024,15 @@ static int store_ansi(LWCHAR ch, char *rep, POSITION pos)

static int store_bs(LWCHAR ch, char *rep, POSITION pos)
{
if (bs_mode == BS_CONTROL)
if (proc_backspace == OPT_ONPLUS || (bs_mode == BS_CONTROL && proc_backspace == OPT_OFF))
return store_control_char(ch, rep, pos);
if (linebuf.end > 0 &&
((linebuf.end <= linebuf.print && linebuf.buf[linebuf.end-1] == '\0') ||
(linebuf.end > 0 && linebuf.attr[linebuf.end - 1] & (AT_ANSI|AT_BINARY))))
STORE_PRCHAR('\b', pos);
else if (bs_mode == BS_NORMAL)
else if (proc_backspace == OPT_OFF && bs_mode == BS_NORMAL)
STORE_CHAR(ch, AT_NORMAL, NULL, pos);
else if (bs_mode == BS_SPECIAL)
else if (proc_backspace == OPT_ON || (bs_mode == BS_SPECIAL && proc_backspace == OPT_OFF))
overstrike = backc();
return 0;
}
Expand Down Expand Up @@ -1117,15 +1120,9 @@ static int do_append(LWCHAR ch, char *rep, POSITION pos)
/*
* Expand a tab into spaces.
*/
switch (bs_mode)
{
case BS_CONTROL:
if (proc_tab == OPT_ONPLUS || (bs_mode == BS_CONTROL && proc_tab == OPT_OFF))
return store_control_char(ch, rep, pos);
case BS_NORMAL:
case BS_SPECIAL:
STORE_TAB(a, pos);
break;
}
STORE_TAB(a, pos);
return (0);
}
if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
Expand Down
32 changes: 31 additions & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public int def_search_type; /* */
public int exit_F_on_close; /* Exit F command when input closes */
public int modelines; /* Lines to read looking for modelines */
public int show_preproc_error; /* Display msg when preproc exits with error */
public int proc_backspace; /* Special handling of backspace */
public int proc_tab; /* Special handling of tab */
public int proc_return; /* Special handling of carriage return */
public char intr_char = CONTROL('X'); /* Char to interrupt reads */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
Expand Down Expand Up @@ -164,6 +167,9 @@ static struct optname no_vbell_optname = { "no-vbell", NULL };
static struct optname intr_optname = { "intr", NULL };
static struct optname wordwrap_optname = { "wordwrap", NULL };
static struct optname show_preproc_error_optname = { "show-preproc-errors", NULL };
static struct optname proc_backspace_optname = { "proc-backspace", NULL };
static struct optname proc_tab_optname = { "proc-tab", NULL };
static struct optname proc_return_optname = { "proc-return", NULL };
#if LESSTEST
static struct optname ttyin_name_optname = { "tty", NULL };
#endif /*LESSTEST*/
Expand Down Expand Up @@ -403,7 +409,7 @@ static struct loption option[] =
},
#endif
{ 'u', &u_optname,
TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &bs_mode, NULL,
{
"Display underlined text in underline mode",
"Backspaces cause overstrike",
Expand Down Expand Up @@ -678,6 +684,30 @@ static struct loption option[] =
NULL
}
},
{ OLETTER_NONE, &proc_backspace_optname,
TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_backspace, NULL,
{
"Backspace handling is specified by the -U option",
"Display underline text in underline mode",
"Print backspaces as ^H"
}
},
{ OLETTER_NONE, &proc_tab_optname,
TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_tab, NULL,
{
"Tab handling is specified by the -U option",
"Expand tabs to spaces",
"Print tabs as ^I"
}
},
{ OLETTER_NONE, &proc_return_optname,
TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_return, NULL,
{
"Carriage return handling is specified by the -U option",
"Delete carriage return before newline",
"Print carriage return as ^M"
}
},
#if LESSTEST
{ OLETTER_NONE, &ttyin_name_optname,
STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
Expand Down
7 changes: 5 additions & 2 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern int linenums;
extern int sc_height;
extern int jump_sline;
extern int bs_mode;
extern int proc_backspace;
extern int proc_return;
extern int ctldisp;
extern int status_col;
extern void *ml_search;
Expand Down Expand Up @@ -213,9 +215,9 @@ static int get_cvt_ops(int search_type)

if (is_caseless && (!re_handles_caseless || (search_type & SRCH_NO_REGEX)))
ops |= CVT_TO_LC;
if (bs_mode == BS_SPECIAL)
if (proc_backspace == OPT_ON || (bs_mode == BS_SPECIAL && proc_backspace == OPT_OFF))
ops |= CVT_BS;
if (bs_mode != BS_CONTROL)
if (proc_return == OPT_ON || (bs_mode != BS_CONTROL && proc_backspace == OPT_OFF))
ops |= CVT_CRLF;
if (ctldisp == OPT_ONPLUS)
ops |= CVT_ANSI;
Expand Down Expand Up @@ -271,6 +273,7 @@ public void repaint_hilite(int on)
continue;
(void) forw_line(pos);
goto_line(sindex);
clear_eol();
put_line();
}
overlay_header();
Expand Down
2 changes: 1 addition & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ v620 1/12/23 Add --modelines option; add --intr option;
v621 1/15/23 Add --wordwrap option; add LESS_LINES & LESS_COLUMNS.
v622 1/27/23 Add --show-preproc-errors option.
v623 2/2/23 Add # command; add ^S search modifier.
v624
v624 Add --proc-backspace, --proc-tab and --proc-return options.
*/

char version[] = "624x";

0 comments on commit 96f2bcd

Please sign in to comment.