diff --git a/src/files.c b/src/files.c index 4f5f0dc9..60ce1b13 100644 --- a/src/files.c +++ b/src/files.c @@ -406,13 +406,11 @@ void stat_with_alloc(const char *filename, struct stat **pstat) } #endif /* !NANO_TINY */ -/* This does one of three things. If the filename is "", just create a new - * empty buffer. Otherwise, read the given file into the existing buffer, - * or into a new buffer when MULTIBUFFER is set or there is no buffer yet. */ -bool open_buffer(const char *filename, bool undoable) +/* This does one of three things. If the filename is "", it just creates + * a new empty buffer. When the filename is not empty, it reads that file + * into a new buffer when requested, otherwise into the existing buffer. */ +bool open_buffer(const char *filename, bool new_buffer) { - bool new_buffer = (openfile == NULL || ISSET(MULTIBUFFER)); - /* Whether we load into the current buffer or a new one. */ char *realname; /* The filename after tilde expansion. */ FILE *f; @@ -478,7 +476,7 @@ bool open_buffer(const char *filename, bool undoable) /* If we have a non-new file, read it in. Then, if the buffer has * no stat, update the stat, if applicable. */ if (rc > 0) { - read_file(f, rc, realname, undoable && !new_buffer, new_buffer); + read_file(f, rc, realname, !new_buffer, new_buffer); #ifndef NANO_TINY if (openfile->current_stat == NULL) stat_with_alloc(realname, &openfile->current_stat); @@ -1121,7 +1119,7 @@ void do_insertfile(void) #ifdef ENABLE_MULTIBUFFER /* When in multibuffer mode, first open a blank buffer. */ if (ISSET(MULTIBUFFER)) - open_buffer("", FALSE); + open_buffer("", TRUE); #endif /* If the command is not empty, execute it and read its output * into the buffer, and add the command to the history list. */ @@ -1148,8 +1146,8 @@ void do_insertfile(void) /* Make sure the specified path is tilde-expanded. */ answer = free_and_assign(answer, real_dir_from_tilde(answer)); - /* Read the specified file into the current buffer. */ - open_buffer(answer, TRUE); + /* Read the file into a new buffer or into current buffer. */ + open_buffer(answer, ISSET(MULTIBUFFER)); } #ifdef ENABLE_MULTIBUFFER diff --git a/src/help.c b/src/help.c index a0da5f97..0407a80a 100644 --- a/src/help.c +++ b/src/help.c @@ -75,7 +75,7 @@ void wrap_the_help_text(bool redisplaying) if (redisplaying) close_buffer(); - open_buffer(tempfilename, FALSE); + open_buffer(tempfilename, TRUE); remove_magicline(); prepare_for_display(); diff --git a/src/nano.c b/src/nano.c index 53adf1b3..93a99b8a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1164,7 +1164,7 @@ bool scoop_stdin(void) } /* Read the input into a new buffer. */ - open_buffer("", FALSE); + open_buffer("", TRUE); read_file(stream, 0, "stdin", TRUE, FALSE); openfile->edittop = openfile->fileage; @@ -2616,7 +2616,7 @@ int main(int argc, char **argv) optind++; if (!scoop_stdin()) continue; - } else if (!open_buffer(argv[optind++], FALSE)) + } else if (!open_buffer(argv[optind++], TRUE)) continue; /* If a position was given on the command line, go there. */ @@ -2636,7 +2636,7 @@ int main(int argc, char **argv) * directories, then open a blank buffer and allow editing. Otherwise, * switch from the last opened file to the next, that is: the first. */ if (openfile == NULL) { - open_buffer("", FALSE); + open_buffer("", TRUE); UNSET(VIEW_MODE); } #ifdef ENABLE_MULTIBUFFER diff --git a/src/proto.h b/src/proto.h index d131f995..f8c04262 100644 --- a/src/proto.h +++ b/src/proto.h @@ -267,7 +267,7 @@ void do_uncut_text(void); /* Most functions in files.c. */ void initialize_buffer_text(void); void set_modified(void); -bool open_buffer(const char *filename, bool undoable); +bool open_buffer(const char *filename, bool new_buffer); #ifdef ENABLE_SPELLER void replace_buffer(const char *filename); #ifndef NANO_TINY diff --git a/src/text.c b/src/text.c index 2f01b7db..d558225b 100644 --- a/src/text.c +++ b/src/text.c @@ -3226,7 +3226,7 @@ void do_linter(void) goto free_lints_and_return; } else if (i == 1) { SET(MULTIBUFFER); - open_buffer(curlint->filename, FALSE); + open_buffer(curlint->filename, TRUE); } else { char *dontwantfile = mallocstrcpy(NULL, curlint->filename); lintstruct *restlint = NULL;