nano

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

commit 86c08560ad45fd905c49a9cb9eeee10c5af31bb3
parent 119a6f0de33e7948bc60cd8a6992e7d19a027dc6
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 25 May 2018 17:57:04 +0200

linter: make sure that the margin is updated before displaying a buffer

This fixes https://savannah.gnu.org/bugs/?53977.
Reported-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>

Diffstat:
Msrc/nano.c | 42+++++++++++++++++++++++++-----------------
Msrc/proto.h | 3+++
Msrc/text.c | 3+++
3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -1541,6 +1541,30 @@ int get_keycode(const char *keyname, const int standard) return standard; } +#ifdef ENABLE_LINENUMBERS +/* Ensure that the margin can accomodate the buffer's highest line number. */ +void check_margin(void) +{ + int needed_margin = digits(openfile->filebot->lineno) + 1; + + /* When not requested or space is too tight, suppress line numbers. */ + if (!ISSET(LINE_NUMBERS) || needed_margin > COLS - 4) + needed_margin = 0; + + if (needed_margin != margin) { + margin = needed_margin; + editwincols = COLS - margin; + +#ifndef NANO_TINY + /* Ensure that firstcolumn is the starting column of its chunk. */ + ensure_firstcolumn_is_aligned(); +#endif + /* The margin has changed -- schedule a full refresh. */ + refresh_needed = TRUE; + } +} +#endif /* ENABLE_LINENUMBERS */ + /* Say that an unbound key was struck, and if possible which one. */ void unbound_key(int code) { @@ -2643,23 +2667,7 @@ int main(int argc, char **argv) while (TRUE) { #ifdef ENABLE_LINENUMBERS - int needed_margin = digits(openfile->filebot->lineno) + 1; - - /* Suppress line numbers when there is not enough room for them. */ - if (!ISSET(LINE_NUMBERS) || needed_margin > COLS - 4) - needed_margin = 0; - - if (needed_margin != margin) { - margin = needed_margin; - editwincols = COLS - margin; - -#ifndef NANO_TINY - /* Ensure that firstcolumn is the starting column of its chunk. */ - ensure_firstcolumn_is_aligned(); -#endif - /* The margin has changed -- schedule a full refresh. */ - refresh_needed = TRUE; - } + check_margin(); #endif if (currmenu != MMAIN) display_main_list(); diff --git a/src/proto.h b/src/proto.h @@ -442,6 +442,9 @@ void enable_signals(void); void disable_flow_control(void); void enable_flow_control(void); void terminal_init(void); +#ifdef ENABLE_LINENUMBERS +void check_margin(void); +#endif void unbound_key(int code); bool okay_for_view(const sc *shortcut); int do_input(bool allow_funcs); diff --git a/src/text.c b/src/text.c @@ -3335,6 +3335,9 @@ void do_linter(void) goto_line_posx(curlint->lineno, curlint->colno - 1); titlebar(NULL); adjust_viewport(CENTERING); +#ifdef ENABLE_LINENUMBERS + check_margin(); +#endif edit_refresh(); statusbar(curlint->msg); bottombars(MLINTER);