From 5a48edc9aecb10ad9b73372c1efea31ce7f7bc8f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 30 May 2019 16:37:16 +0200 Subject: [PATCH] tweaks: reshuffle some code to the one place that needs it The extra things that close_buffer() did are only needed and useful when manually closing a buffer, so move them there. The other three calls of close_buffer() only need to get rid of the current buffer (making the preceding buffer the new current one) and nothing else. --- src/files.c | 23 ++++++----------------- src/help.c | 6 ++++-- src/nano.c | 14 +++++++++++--- src/proto.h | 2 +- src/winio.c | 2 +- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/files.c b/src/files.c index f92a74ab..c7157da4 100644 --- a/src/files.c +++ b/src/files.c @@ -462,7 +462,8 @@ bool open_buffer(const char *filename, bool new_buffer) /* When not overriding an existing lock, discard the buffer. */ if (do_lockfile(realname) < 0) { #ifdef ENABLE_MULTIBUFFER - close_buffer(); + openfile = openfile->prev; + close_buffer(openfile->next); #endif free(realname); return FALSE; @@ -647,24 +648,12 @@ void switch_to_next_buffer(void) switch_to_adjacent_buffer(FORWARD); } -/* Delete the current entry from the circular list of open files, - * after switching to the buffer after it. */ -void close_buffer(void) +/* Remove the given buffer from the circular list of buffers. */ +void close_buffer(openfilestruct *buffer) { -#ifdef ENABLE_HISTORIES - if (ISSET(POSITIONLOG) && !inhelp) - update_poshistory(openfile->filename, - openfile->current->lineno, xplustabs() + 1); -#endif + unlink_opennode(buffer); - switch_to_next_buffer(); - - /* Delete the old file buffer, and adjust the count in the top bar. */ - unlink_opennode(openfile->prev); - if (!inhelp) - titlebar(NULL); - - /* If now just one buffer remains open, show "Exit" in the help lines. */ + /* When just one buffer remains open, show "Exit" in the help lines. */ if (openfile == openfile->next) exitfunc->desc = exit_tag; } diff --git a/src/help.c b/src/help.c index 89dbde75..dfb844c8 100644 --- a/src/help.c +++ b/src/help.c @@ -223,9 +223,9 @@ void do_help(void) } } - close_buffer(); - /* Switch back to the buffer we were invoked from. */ + /* Switch back to the original buffer and discard the help-text buffer. */ openfile = openfile->prev; + close_buffer(openfile->next); /* Restore the settings of all flags. */ memcpy(flags, stash, sizeof(flags)); @@ -254,6 +254,8 @@ void do_help(void) } else bottombars(oldmenu); + prepare_for_display(); + #ifdef ENABLE_BROWSER if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR) browser_refresh(); diff --git a/src/nano.c b/src/nano.c index d304c26d..ebffe52f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1037,9 +1037,17 @@ void close_and_go(void) #endif #ifdef ENABLE_MULTIBUFFER /* If there is another buffer, close this one; otherwise terminate. */ - if (openfile != openfile->next) - close_buffer(); - else + if (openfile != openfile->next) { +#ifdef ENABLE_HISTORIES + if (ISSET(POSITIONLOG)) + update_poshistory(openfile->filename, + openfile->current->lineno, xplustabs() + 1); +#endif + switch_to_next_buffer(); + close_buffer(openfile->prev); + /* Adjust the count in the top bar. */ + titlebar(NULL); + } else #endif finish(); } diff --git a/src/proto.h b/src/proto.h index 4e24a367..3ec47b42 100644 --- a/src/proto.h +++ b/src/proto.h @@ -276,7 +276,7 @@ void prepare_for_display(void); void mention_name_and_linecount(void); void switch_to_prev_buffer(void); void switch_to_next_buffer(void); -void close_buffer(void); +void close_buffer(openfilestruct *buffer); #endif void read_file(FILE *f, int fd, const char *filename, bool undoable); int open_file(const char *filename, bool newfie, FILE **f); diff --git a/src/winio.c b/src/winio.c index 8fea5fee..7e96d7c0 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3374,8 +3374,8 @@ void total_refresh(void) titlebar(title); #ifdef ENABLE_HELP if (inhelp) { - close_buffer(); openfile = openfile->prev; + close_buffer(openfile->next); wrap_help_text_into_buffer(); } else #endif