diff --git a/src/files.c b/src/files.c index 14e3d385..3e674943 100644 --- a/src/files.c +++ b/src/files.c @@ -462,8 +462,7 @@ 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 - openfile = openfile->prev; - close_buffer(openfile->next); + close_buffer(); #endif free(realname); return FALSE; @@ -645,10 +644,11 @@ void switch_to_next_buffer(void) switch_to_adjacent_buffer(FORWARD); } -/* Remove the given buffer from the circular list of buffers. */ -void close_buffer(openfilestruct *buffer) +/* Remove the current buffer from the circular list of buffers. */ +void close_buffer(void) { - unlink_opennode(buffer); + openfile = openfile->prev; + unlink_opennode(openfile->next); /* When just one buffer remains open, show "Exit" in the help lines. */ if (openfile == openfile->next) diff --git a/src/help.c b/src/help.c index dfb844c8..bc7711ab 100644 --- a/src/help.c +++ b/src/help.c @@ -223,9 +223,8 @@ void do_help(void) } } - /* Switch back to the original buffer and discard the help-text buffer. */ - openfile = openfile->prev; - close_buffer(openfile->next); + /* Discard the help-text buffer. */ + close_buffer(); /* Restore the settings of all flags. */ memcpy(flags, stash, sizeof(flags)); diff --git a/src/nano.c b/src/nano.c index 461212bd..8afb12b3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1044,7 +1044,9 @@ void close_and_go(void) openfile->current->lineno, xplustabs() + 1); #endif switch_to_next_buffer(); - close_buffer(openfile->prev); + openfile = openfile->prev; + close_buffer(); + openfile = openfile->next; /* Adjust the count in the top bar. */ titlebar(NULL); } else diff --git a/src/proto.h b/src/proto.h index 3ec47b42..4e24a367 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(openfilestruct *buffer); +void close_buffer(void); #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 7e96d7c0..dc779ea6 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3374,8 +3374,7 @@ void total_refresh(void) titlebar(title); #ifdef ENABLE_HELP if (inhelp) { - openfile = openfile->prev; - close_buffer(openfile->next); + close_buffer(); wrap_help_text_into_buffer(); } else #endif