nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 023edffe3df701427b6d0a6da579a7424e0fac7d
parent 2789bb0813376caf59da7f80b83c3db28c0fc370
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Fri, 21 Oct 2016 14:31:37 +0200

screen: move the margin determination to the main loop

There is no need to look at this for every painted line, because
the margin can only change when some key is struck.

Diffstat:
Msrc/nano.c | 18++++++++++++++++--
Msrc/winio.c | 17+++--------------
2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -2554,8 +2554,6 @@ int main(int argc, char **argv) * dimensions. */ window_init(); - editwincols = COLS - margin; - /* Set up the signal handlers. */ signal_init(); @@ -2694,6 +2692,22 @@ int main(int argc, char **argv) display_buffer(); while (TRUE) { +#ifdef ENABLE_LINENUMBERS + int needed_margin = digits(openfile->filebot->lineno) + 1; + + /* Only enable line numbers when there is enough room for them. */ + if (ISSET(LINE_NUMBERS) && needed_margin < COLS - 3) { + if (needed_margin != margin) { + margin = needed_margin; + editwincols = COLS - margin; + /* The margin has changed -- schedule a full refresh. */ + refresh_needed = TRUE; + } + } else { + margin = 0; + editwincols = COLS; + } +#endif if (currmenu != MMAIN) display_main_list(); diff --git a/src/winio.c b/src/winio.c @@ -2269,26 +2269,15 @@ void edit_draw(filestruct *fileptr, const char *converted, int assert(strlenpt(converted) <= editwincols); #ifdef ENABLE_LINENUMBERS - int needed_margin = digits(openfile->filebot->lineno) + 1; - - if (ISSET(LINE_NUMBERS) && needed_margin < COLS - 3) { - /* If the line numbers now require more room, schedule a refresh. */ - if (needed_margin != margin) { - margin = needed_margin; - editwincols = COLS - margin; - refresh_needed = TRUE; - } - - /* Show the line number only for the non-softwrapped parts. */ + /* If line numbering is switched on, show a line number in front of + * the text -- but only for the parts that are not softwrapped. */ + if (margin > 0) { wattron(edit, interface_color_pair[LINE_NUMBER]); if (last_drawn_line != fileptr->lineno || last_line_y >= line) mvwprintw(edit, line, 0, "%*i", margin - 1, fileptr->lineno); else mvwprintw(edit, line, 0, "%*s", margin - 1, " "); wattroff(edit, interface_color_pair[LINE_NUMBER]); - } else { - margin = 0; - editwincols = COLS; } #endif