Skip to content

Commit

Permalink
Change M command to mark bottom line on screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Oct 25, 2017
1 parent a89ae06 commit 0a150b3
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 135 deletions.
4 changes: 3 additions & 1 deletion NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
* When using -S, mark truncated lines with a special character.
The character can be changed or disabled via the new --rscroll option.

* New command M visually marks the last line displayed on the screen.
* New command M marks the last line displayed on the screen.

* New command ESC-m removes a line mark.

* Status column (enabled via -J) now shows mark letters.

Expand Down
4 changes: 2 additions & 2 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
#define A_GOEND_BUF 57
#define A_LLSHIFT 58
#define A_RRSHIFT 59
#define A_SETATTN 60
#define A_CLRATTN 61
#define A_CLRMARK 62
#define A_SETMARKBOT 63

#define A_INVALID 100
#define A_NOACTION 101
Expand Down
178 changes: 84 additions & 94 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ extern int secure;
extern int hshift;
extern int bs_mode;
extern int show_attn;
extern int sticky_attn;
extern int status_col;
extern POSITION highest_hilite;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
extern char *every_first_cmd;
extern char version[];
extern struct scrpos initial_scrpos;
Expand Down Expand Up @@ -86,8 +87,7 @@ static void multi_search();
static void
cmd_exec()
{
if (!sticky_attn)
clear_attn();
clear_attn();
clear_bot();
flush();
}
Expand Down Expand Up @@ -293,6 +293,16 @@ is_erase_char(c)
return (c == erase_char || c == erase2_char || c == kill_char);
}

/*
* Is a character a carriage return or newline?
*/
static int
is_newline_char(c)
int c;
{
return (c == '\n' || c == '\r');
}

/*
* Handle the first char of an option (after the initial dash).
*/
Expand Down Expand Up @@ -418,7 +428,7 @@ mca_opt_char(c)
if (optgetname)
{
/* We're getting a long option name. */
if (c != '\n' && c != '\r')
if (!is_newline_char(c))
return (mca_opt_nonfirst_char(c));
if (curropt == NULL)
{
Expand Down Expand Up @@ -582,7 +592,7 @@ mca_char(c)
/*
* The multichar command is terminated by a newline.
*/
if (c == '\n' || c == '\r')
if (is_newline_char(c))
{
/*
* Execute the command.
Expand Down Expand Up @@ -1210,7 +1220,7 @@ commands()
number = get_swindow();
cmd_exec();
if (show_attn)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
forward((int) number, 0, 1);
break;

Expand Down Expand Up @@ -1239,7 +1249,7 @@ commands()
number = 1;
cmd_exec();
if (show_attn == OPT_ONPLUS && number > 1)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
forward((int) number, 0, 0);
break;

Expand All @@ -1261,7 +1271,7 @@ commands()
number = 1;
cmd_exec();
if (show_attn == OPT_ONPLUS && number > 1)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
forward((int) number, 1, 0);
break;

Expand All @@ -1283,7 +1293,7 @@ commands()
number = get_swindow();
cmd_exec();
if (show_attn == OPT_ONPLUS)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
forward((int) number, 1, 0);
break;

Expand All @@ -1292,7 +1302,7 @@ commands()
* Forward forever, ignoring EOF.
*/
if (show_attn)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
newaction = forw_loop(0);
break;

Expand All @@ -1309,7 +1319,7 @@ commands()
wscroll = (int) number;
cmd_exec();
if (show_attn == OPT_ONPLUS)
set_attnpos(bottompos, 0);
set_attnpos(bottompos);
forward(wscroll, 0, 0);
break;

Expand Down Expand Up @@ -1545,56 +1555,50 @@ commands()
/*
* Edit a new file. Get the filename.
*/
if (secure)
if (!secure)
{
error("Command not available", NULL_PARG);
break;
start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
c = getcc();
goto again;
}
start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
c = getcc();
goto again;
#else
#endif
error("Command not available", NULL_PARG);
break;
#endif

case A_VISUAL:
/*
* Invoke an editor on the input file.
*/
#if EDITOR
if (secure)
if (!secure)
{
error("Command not available", NULL_PARG);
break;
}
if (ch_getflags() & CH_HELPFILE)
break;
if (strcmp(get_filename(curr_ifile), "-") == 0)
{
error("Cannot edit standard input", NULL_PARG);
if (ch_getflags() & CH_HELPFILE)
break;
if (strcmp(get_filename(curr_ifile), "-") == 0)
{
error("Cannot edit standard input", NULL_PARG);
break;
}
if (get_altfilename(curr_ifile) != NULL)
{
error("WARNING: This file was viewed via LESSOPEN",
NULL_PARG);
}
start_mca(A_SHELL, "!", ml_shell, 0);
/*
* Expand the editor prototype string
* and pass it to the system to execute.
* (Make sure the screen is displayed so the
* expansion of "+%lm" works.)
*/
make_display();
cmd_exec();
lsystem(pr_expand(editproto, 0), (char*)NULL);
break;
}
if (get_altfilename(curr_ifile) != NULL)
{
error("WARNING: This file was viewed via LESSOPEN",
NULL_PARG);
}
start_mca(A_SHELL, "!", ml_shell, 0);
/*
* Expand the editor prototype string
* and pass it to the system to execute.
* (Make sure the screen is displayed so the
* expansion of "+%lm" works.)
*/
make_display();
cmd_exec();
lsystem(pr_expand(editproto, 0), (char*)NULL);
break;
#else
#endif
error("Command not available", NULL_PARG);
break;
#endif

case A_NEXT_FILE:
/*
Expand Down Expand Up @@ -1741,70 +1745,66 @@ commands()
* Shell escape.
*/
#if SHELL_ESCAPE
if (secure)
if (!secure)
{
error("Command not available", NULL_PARG);
break;
start_mca(A_SHELL, "!", ml_shell, 0);
c = getcc();
goto again;
}
start_mca(A_SHELL, "!", ml_shell, 0);
c = getcc();
goto again;
#else
#endif
error("Command not available", NULL_PARG);
break;
#endif

case A_SETMARK:
/*
* Set a mark.
*/
case A_SETMARKBOT:
if (ch_getflags() & CH_HELPFILE)
break;
start_mca(A_SETMARK, "mark: ", (void*)NULL, 0);
start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0);
c = getcc();
if (is_erase_char(c) || is_newline_char(c))
break;
setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP);
repaint();
break;

case A_CLRMARK:
start_mca(A_SETMARK, "clear mark: ", (void*)NULL, 0);
c = getcc();
if (c == erase_char || c == erase2_char ||
c == kill_char || c == '\n' || c == '\r')
if (is_erase_char(c) || is_newline_char(c))
break;
setmark(c);
clrmark(c);
repaint();
break;

case A_GOMARK:
/*
* Go to a mark.
*/
start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
start_mca(A_SETMARK, "goto mark: ", (void*)NULL, 0);
c = getcc();
if (c == erase_char || c == erase2_char ||
c == kill_char || c == '\n' || c == '\r')
if (is_erase_char(c) || is_newline_char(c))
break;
cmd_exec();
gomark(c);
break;

case A_PIPE:
#if PIPEC
if (secure)
if (!secure)
{
error("Command not available", NULL_PARG);
break;
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
c = getcc();
if (is_erase_char(c))
break;
if (is_newline_char(c))
c = '.';
if (badmark(c))
break;
pipec = c;
start_mca(A_PIPE, "!", ml_shell, 0);
c = getcc();
goto again;
}
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
c = getcc();
if (c == erase_char || c == erase2_char || c == kill_char)
break;
if (c == '\n' || c == '\r')
c = '.';
if (badmark(c))
break;
pipec = c;
start_mca(A_PIPE, "!", ml_shell, 0);
c = getcc();
goto again;
#else
#endif
error("Command not available", NULL_PARG);
break;
#endif

case A_B_BRACKET:
case A_F_BRACKET:
Expand Down Expand Up @@ -1844,16 +1844,6 @@ commands()
screen_trashed = 1;
break;

case A_SETATTN:
status_col = 1;
set_attnpos(position(BOTTOM), 1);
repaint();
break;

case A_CLRATTN:
clear_attn();
break;

case A_PREFIX:
/*
* The command is incomplete (more chars are needed).
Expand Down
4 changes: 2 additions & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ static unsigned char cmdtable[] =
ESC,'N',0, A_T_REVERSE_SEARCH,
'&',0, A_FILTER,
'm',0, A_SETMARK,
'M',0, A_SETATTN,
ESC,'M',0, A_CLRATTN,
'M',0, A_SETMARKBOT,
ESC,'m',0, A_CLRMARK,
'\'',0, A_GOMARK,
CONTROL('X'),CONTROL('X'),0, A_GOMARK,
'E',0, A_EXAMINE,
Expand Down
3 changes: 2 additions & 1 deletion edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


#include "less.h"
#include "position.h"
#if HAVE_STAT
#include <sys/stat.h>
#endif
Expand Down Expand Up @@ -177,7 +178,7 @@ close_file()
* Save the current position so that we can return to
* the same position if we edit this file again.
*/
get_scrpos(&scrpos);
get_scrpos(&scrpos, TOP);
if (scrpos.pos != NULL_POSITION)
{
store_pos(curr_ifile, &scrpos);
Expand Down
5 changes: 1 addition & 4 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern int ignore_eoi;
extern int status_col;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
extern int sticky_attn;
#if HILITE_SEARCH
extern int hilite_search;
extern int size_linebuf;
Expand Down Expand Up @@ -428,9 +427,8 @@ back_line(curr_pos)
* Set attnpos.
*/
public void
set_attnpos(pos, sticky)
set_attnpos(pos)
POSITION pos;
int sticky;
{
int c;

Expand Down Expand Up @@ -460,5 +458,4 @@ set_attnpos(pos, sticky)
}
}
start_attnpos = pos;
sticky_attn = sticky;
}
Loading

0 comments on commit 0a150b3

Please sign in to comment.