From 39ffe1b2a5802b345ebf17e8e0851b26592092d4 Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Thu, 26 Oct 2017 09:35:18 -0700 Subject: [PATCH] Minor clean up, better distinguish between sline and sindex. Fix off-by-one bug in '$. Document M and ESC-m commands. --- command.c | 4 ++-- jump.c | 19 ++++++++++--------- less.hlp.VER | 4 +++- less.nro.VER | 6 +++--- mark.c | 2 +- position.c | 23 ++++++++++++----------- prompt.c | 2 +- screen.c | 8 ++++---- search.c | 42 +++++++++++++++++++++--------------------- 9 files changed, 57 insertions(+), 53 deletions(-) diff --git a/command.c b/command.c index 1d17f9fa..803b36c3 100644 --- a/command.c +++ b/command.c @@ -1789,7 +1789,7 @@ commands() /* * Clear a mark. */ - start_mca(A_SETMARK, "clear mark: ", (void*)NULL, 0); + start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0); c = getcc(); if (is_erase_char(c) || is_newline_char(c)) break; @@ -1801,7 +1801,7 @@ commands() /* * Jump to a marked position. */ - start_mca(A_SETMARK, "goto mark: ", (void*)NULL, 0); + start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0); c = getcc(); if (is_erase_char(c) || is_newline_char(c)) break; diff --git a/jump.c b/jump.c index c826f8d5..1a798ad9 100644 --- a/jump.c +++ b/jump.c @@ -44,7 +44,7 @@ jump_forw() end_pos = ch_tell(); pos = back_line(end_pos); if (pos == NULL_POSITION) - jump_loc((POSITION)0, sc_height-1); + jump_loc(ch_zero(), sc_height-1); else { jump_loc(pos, sc_height-1); @@ -119,7 +119,7 @@ repaint() pos_clear(); if (scrpos.pos == NULL_POSITION) /* Screen hasn't been drawn yet. */ - jump_loc(0, 0); + jump_loc(ch_zero(), 1); else jump_loc(scrpos.pos, scrpos.ln); } @@ -194,13 +194,14 @@ jump_loc(pos, sline) int sline; { int nline; + int sindex; POSITION tpos; POSITION bpos; /* * Normalize sline. */ - sline = adjsline(sline); + sindex = sindex_from_sline(sline); if ((nline = onscreen(pos)) >= 0) { @@ -208,7 +209,7 @@ jump_loc(pos, sline) * The line is currently displayed. * Just scroll there. */ - nline -= sline; + nline -= sindex; if (nline > 0) forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0); else if (nline < 0) @@ -244,7 +245,7 @@ jump_loc(pos, sline) * call forw() and put the desired line at the * sline-th line on the screen. */ - for (nline = 0; nline < sline; nline++) + for (nline = 0; nline < sindex; nline++) { if (bpos != NULL_POSITION && pos <= bpos) { @@ -253,7 +254,7 @@ jump_loc(pos, sline) * close enough to the current screen * that we can just scroll there after all. */ - forw(sc_height-sline+nline-1, bpos, 1, 0, 0); + forw(sc_height-sindex+nline-1, bpos, 1, 0, 0); #if HILITE_SEARCH if (show_attn) repaint_hilite(1); @@ -275,16 +276,16 @@ jump_loc(pos, sline) lastmark(); squished = 0; screen_trashed = 0; - forw(sc_height-1, pos, 1, 0, sline-nline); + forw(sc_height-1, pos, 1, 0, sindex-nline); } else { /* * The desired line is before the current screen. * Move forward in the file far enough so that we * can call back() and put the desired line at the - * sline-th line on the screen. + * sindex-th line on the screen. */ - for (nline = sline; nline < sc_height - 1; nline++) + for (nline = sindex; nline < sc_height - 1; nline++) { pos = forw_line(pos); if (pos == NULL_POSITION) diff --git a/less.hlp.VER b/less.hlp.VER index 255dc7e0..0bbada91 100644 --- a/less.hlp.VER +++ b/less.hlp.VER @@ -69,10 +69,12 @@ Each "find open bracket" command goes backward to the open bracket matching the (_N-th) close bracket in the bottom line. - m_<_l_e_t_t_e_r_> Mark the current position with . + m_<_l_e_t_t_e_r_> Mark the current top line with . + M_<_l_e_t_t_e_r_> Mark the current bottom line with . '_<_l_e_t_t_e_r_> Go to a previously marked position. '' Go to the previous position. ^X^X Same as '. + ESC-M_<_l_e_t_t_e_r_> Clear a mark. --------------------------------------------------- A mark is any upper-case or lower-case letter. Certain marks are predefined: diff --git a/less.nro.VER b/less.nro.VER index f88d5f1c..a47143eb 100644 --- a/less.nro.VER +++ b/less.nro.VER @@ -181,9 +181,6 @@ the status column shows the marked line. .IP M Acts like m, except the last displayed line is marked rather than the first displayed line. -.IP "ESC-m" -Followed by any lowercase or uppercase letter, -removes the mark identified by that letter. .IP "'" (Single quote.) Followed by any lowercase or uppercase letter, returns to the position which @@ -196,6 +193,9 @@ Marks are preserved when a new file is examined, so the ' command can be used to switch between input files. .IP "^X^X" Same as single quote. +.IP "ESC-m" +Followed by any lowercase or uppercase letter, +clears the mark identified by that letter. .IP /pattern Search forward in the file for the N-th line containing the pattern. N defaults to 1. diff --git a/mark.c b/mark.c index 09c16072..28258927 100644 --- a/mark.c +++ b/mark.c @@ -80,7 +80,7 @@ getmark(c) } m = &sm; m->m_scrpos.pos = ch_tell(); - m->m_scrpos.ln = sc_height-1; + m->m_scrpos.ln = sc_height; m->m_ifile = curr_ifile; break; case '.': diff --git a/position.c b/position.c index f2176e3f..a19e688d 100644 --- a/position.c +++ b/position.c @@ -29,21 +29,22 @@ extern int sc_width, sc_height; * the line after the bottom line on the screen */ public POSITION -position(where) - int where; +position(sindex) + int sindex; { - switch (where) + switch (sindex) { case BOTTOM: - where = sc_height - 2; + sindex = sc_height - 2; break; case BOTTOM_PLUS_ONE: - where = sc_height - 1; + sindex = sc_height - 1; break; case MIDDLE: - where = (sc_height - 1) / 2; + sindex = (sc_height - 1) / 2; + break; } - return (table[where]); + return (table[sindex]); } /* @@ -213,7 +214,7 @@ get_scrpos(scrpos, where) * relative to the bottom of the screen. */ public int -adjsline(sline) +sindex_from_sline(sline) int sline; { /* @@ -223,12 +224,12 @@ adjsline(sline) if (sline < 0) sline += sc_height; /* - * Can't be less than 1 or greater than sc_height-1. + * Can't be less than 1 or greater than sc_height. */ if (sline <= 0) sline = 1; - if (sline >= sc_height) - sline = sc_height - 1; + if (sline > sc_height) + sline = sc_height; /* * Return zero-based line number, not one-based. */ diff --git a/prompt.c b/prompt.c index a4a6f424..b812240c 100644 --- a/prompt.c +++ b/prompt.c @@ -457,7 +457,7 @@ wherechar(p, wp) case 'm': *wp = MIDDLE; break; case 'b': *wp = BOTTOM; break; case 'B': *wp = BOTTOM_PLUS_ONE; break; - case 'j': *wp = adjsline(jump_sline); break; + case 'j': *wp = sindex_from_sline(jump_sline); break; default: *wp = TOP; p--; break; } } diff --git a/screen.c b/screen.c index 5a03bc92..32b2720c 100644 --- a/screen.c +++ b/screen.c @@ -1914,14 +1914,14 @@ check_winch() * Goto a specific line on the screen. */ public void -goto_line(slinenum) - int slinenum; +goto_line(sindex) + int sindex; { #if !MSDOS_COMPILER - tputs(tgoto(sc_move, 0, slinenum), 1, putchr); + tputs(tgoto(sc_move, 0, sindex), 1, putchr); #else flush(); - _settextposition(slinenum+1, 1); + _settextposition(sindex+1, 1); #endif } diff --git a/search.c b/search.c index 2ca42de4..35700611 100644 --- a/search.c +++ b/search.c @@ -251,7 +251,7 @@ prev_pattern(info) repaint_hilite(on) int on; { - int slinenum; + int sindex; POSITION pos; int save_hide_hilite; @@ -273,13 +273,13 @@ repaint_hilite(on) return; } - for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++) + for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) { - pos = position(slinenum); + pos = position(sindex); if (pos == NULL_POSITION) continue; (void) forw_line(pos); - goto_line(slinenum); + goto_line(sindex); put_line(); } lower_left(); @@ -292,7 +292,7 @@ repaint_hilite(on) public void clear_attn() { - int slinenum; + int sindex; POSITION old_start_attnpos; POSITION old_end_attnpos; POSITION pos; @@ -313,17 +313,17 @@ clear_attn() if (squished) repaint(); - for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++) + for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) { - pos = position(slinenum); + pos = position(sindex); if (pos == NULL_POSITION) continue; - epos = position(slinenum+1); + epos = position(sindex+1); if (pos <= old_end_attnpos && (epos == NULL_POSITION || epos > old_start_attnpos)) { (void) forw_line(pos); - goto_line(slinenum); + goto_line(sindex); put_line(); moved = 1; } @@ -1059,7 +1059,7 @@ search_pos(search_type) int search_type; { POSITION pos; - int linenum; + int sindex; if (empty_screen()) { @@ -1082,7 +1082,7 @@ search_pos(search_type) pos = ch_length(); } } - linenum = 0; + sindex = 0; } else { int add_one = 0; @@ -1093,18 +1093,18 @@ search_pos(search_type) * Search does not include current screen. */ if (search_type & SRCH_FORW) - linenum = sc_height-1; /* BOTTOM_PLUS_ONE */ + sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ else - linenum = 0; /* TOP */ + sindex = 0; /* TOP */ } else if (how_search == OPT_ONPLUS && !(search_type & SRCH_AFTER_TARGET)) { /* * Search includes all of displayed screen. */ if (search_type & SRCH_FORW) - linenum = 0; /* TOP */ + sindex = 0; /* TOP */ else - linenum = sc_height-1; /* BOTTOM_PLUS_ONE */ + sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ } else { /* @@ -1112,11 +1112,11 @@ search_pos(search_type) * It starts at the jump target (if searching backwards), * or at the jump target plus one (if forwards). */ - linenum = adjsline(jump_sline); + sindex = sindex_from_sline(jump_sline); if (search_type & SRCH_FORW) add_one = 1; } - pos = position(linenum); + pos = position(sindex); if (add_one) pos = forw_raw_line(pos, (char **)NULL, (int *)NULL); } @@ -1128,17 +1128,17 @@ search_pos(search_type) { while (pos == NULL_POSITION) { - if (++linenum >= sc_height) + if (++sindex >= sc_height) break; - pos = position(linenum); + pos = position(sindex); } } else { while (pos == NULL_POSITION) { - if (--linenum < 0) + if (--sindex < 0) break; - pos = position(linenum); + pos = position(sindex); } } return (pos);