From 2e6886406ca2c3d4d31056d9f20eb925ff6abeec Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 3 Jul 2020 09:32:25 +0200 Subject: [PATCH] tweaks: elide an unneeded global variable The constant cursor display must be suppressed whenever a message was printed to the status bar. That is: whenever 'lastmessage' is something other than 'VACUUM'. --- src/global.c | 3 --- src/help.c | 2 +- src/nano.c | 10 +++++----- src/prototypes.h | 4 +--- src/search.c | 4 ++-- src/text.c | 2 +- src/winio.c | 25 ++++++++----------------- 7 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/global.c b/src/global.c index 9a2557cb..1740cf59 100644 --- a/src/global.c +++ b/src/global.c @@ -70,9 +70,6 @@ bool as_an_at = TRUE; bool control_C_was_pressed = FALSE; /* Whether Ctrl+C was pressed (when a keyboard interrupt is enabled). */ -bool suppress_cursorpos = FALSE; - /* Should we skip constant position display for current keystroke? */ - message_type lastmessage = HUSH; /* Messages of type HUSH should not overwrite type MILD nor ALERT. */ diff --git a/src/help.c b/src/help.c index a4263add..f0b7c236 100644 --- a/src/help.c +++ b/src/help.c @@ -178,7 +178,7 @@ void show_help(void) edit_refresh(); while (TRUE) { - lastmessage = HUSH; + lastmessage = VACUUM; focusing = TRUE; /* Show the cursor when we searched and found something. */ diff --git a/src/nano.c b/src/nano.c index 80f11a40..1c134f78 100644 --- a/src/nano.c +++ b/src/nano.c @@ -944,7 +944,7 @@ RETSIGTYPE do_suspend(int signal) fflush(stdout); /* The suspend keystroke must not elicit cursor-position display. */ - suppress_cursorpos=TRUE; + lastmessage = HUSH; #ifdef SIGSTOP /* Do what mutt does: send ourselves a SIGSTOP. */ @@ -2481,13 +2481,13 @@ int main(int argc, char **argv) if (currmenu != MMAIN) bottombars(MMAIN); - lastmessage = VACUUM; - as_an_at = TRUE; - /* Update the displayed current cursor position only when there * are no keys waiting in the input buffer. */ if (ISSET(CONSTANT_SHOW) && get_key_buffer_len() == 0) - do_cursorpos(FALSE); + report_cursor_position(); + + lastmessage = VACUUM; + as_an_at = TRUE; /* Refresh just the cursor position or the entire edit window. */ if (!refresh_needed) { diff --git a/src/prototypes.h b/src/prototypes.h index 93377b78..8cda0933 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -48,8 +48,6 @@ extern bool as_an_at; extern bool control_C_was_pressed; -extern bool suppress_cursorpos; - extern message_type lastmessage; extern linestruct *pletion_line; @@ -636,7 +634,7 @@ void edit_refresh(void); void adjust_viewport(update_type manner); void full_refresh(void); void draw_all_subwindows(void); -void do_cursorpos(bool force); +void report_cursor_position(void); void do_cursorpos_void(void); void spotlight(size_t from_col, size_t to_col); #ifndef NANO_TINY diff --git a/src/search.c b/src/search.c index b684f1c4..cf08d6ec 100644 --- a/src/search.c +++ b/src/search.c @@ -307,10 +307,10 @@ int findnextstr(const char *needle, bool whole_word_only, int modus, if (match_len != NULL) *match_len = found_len; - /* Wipe the "Searching..." message and unset the suppression flag. */ + /* Wipe the "Searching..." message and unsuppress cursor-position display. */ if (feedback > 0) { wipe_statusbar(); - suppress_cursorpos = FALSE; + lastmessage = VACUUM; } return 1; diff --git a/src/text.c b/src/text.c index 347fd71e..33173ffe 100644 --- a/src/text.c +++ b/src/text.c @@ -3018,7 +3018,7 @@ void do_verbatim_input(void) /* Unsuppress cursor-position display or blank the status bar. */ if (ISSET(CONSTANT_SHOW)) - suppress_cursorpos = FALSE; + lastmessage = VACUUM; else wipe_statusbar(); diff --git a/src/winio.c b/src/winio.c index 21a5afb6..ddef8aba 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2117,9 +2117,8 @@ void titlebar(const char *path) wrefresh(topwin); } -/* Display a message on the status bar, and set suppress_cursorpos to - * TRUE, so that the message won't be immediately overwritten if - * constant cursor position display is on. */ +/* Display the given message on the status bar, but only if its importance + * is higher than that of a message that is already there. */ void statusline(message_type importance, const char *msg, ...) { va_list ap; @@ -2203,8 +2202,6 @@ void statusline(message_type importance, const char *msg, ...) /* Push the message to the screen straightaway. */ wrefresh(bottomwin); - suppress_cursorpos = TRUE; - #ifndef NANO_TINY if (old_whitespace) SET(WHITESPACE_DISPLAY); @@ -3362,21 +3359,17 @@ void draw_all_subwindows(void) bottombars(currmenu); } -/* Show info about the current cursor position on the status bar. - * Do this unconditionally when force is TRUE; otherwise, only if - * suppress_cursorpos is FALSE. In any case, reset the latter. */ -void do_cursorpos(bool force) +/* Display details about the current cursor position on the status bar. */ +void report_cursor_position(void) { char saved_byte; size_t sum, cur_xpt = xplustabs() + 1; size_t cur_lenpt = breadth(openfile->current->data) + 1; int linepct, colpct, charpct; - /* If the showing needs to be suppressed, don't suppress it next time. */ - if (suppress_cursorpos && !force) { - suppress_cursorpos = FALSE; + /* If there is a message on the status bar, do not overwrite it. */ + if (lastmessage != VACUUM) return; - } /* Determine the size of the file up to the cursor. */ saved_byte = openfile->current->data[openfile->current_x]; @@ -3395,15 +3388,13 @@ void do_cursorpos(bool force) _("line %zd/%zd (%d%%), col %zu/%zu (%d%%), char %zu/%zu (%d%%)"), openfile->current->lineno, openfile->filebot->lineno, linepct, cur_xpt, cur_lenpt, colpct, sum, openfile->totsize, charpct); - - /* Displaying the cursor position should not suppress it next time. */ - suppress_cursorpos = FALSE; } /* Unconditionally display the current cursor position. */ void do_cursorpos_void(void) { - do_cursorpos(TRUE); + lastmessage = VACUUM; + report_cursor_position(); } void disable_waiting(void)