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.
master
Benno Schulenberg 2019-05-30 16:37:16 +02:00
parent 6dc8570d55
commit 5a48edc9ae
5 changed files with 23 additions and 24 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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);

View File

@ -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