tweaks: change a parameter of open_buffer() and invert its logic

master
Benno Schulenberg 2018-03-21 11:36:00 +01:00
parent 624918800b
commit dd157f1494
5 changed files with 14 additions and 16 deletions

View File

@ -406,13 +406,11 @@ void stat_with_alloc(const char *filename, struct stat **pstat)
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* This does one of three things. If the filename is "", just create a new /* This does one of three things. If the filename is "", it just creates
* empty buffer. Otherwise, read the given file into the existing buffer, * a new empty buffer. When the filename is not empty, it reads that file
* or into a new buffer when MULTIBUFFER is set or there is no buffer yet. */ * into a new buffer when requested, otherwise into the existing buffer. */
bool open_buffer(const char *filename, bool undoable) 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; char *realname;
/* The filename after tilde expansion. */ /* The filename after tilde expansion. */
FILE *f; 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 /* If we have a non-new file, read it in. Then, if the buffer has
* no stat, update the stat, if applicable. */ * no stat, update the stat, if applicable. */
if (rc > 0) { 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 #ifndef NANO_TINY
if (openfile->current_stat == NULL) if (openfile->current_stat == NULL)
stat_with_alloc(realname, &openfile->current_stat); stat_with_alloc(realname, &openfile->current_stat);
@ -1121,7 +1119,7 @@ void do_insertfile(void)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* When in multibuffer mode, first open a blank buffer. */ /* When in multibuffer mode, first open a blank buffer. */
if (ISSET(MULTIBUFFER)) if (ISSET(MULTIBUFFER))
open_buffer("", FALSE); open_buffer("", TRUE);
#endif #endif
/* If the command is not empty, execute it and read its output /* If the command is not empty, execute it and read its output
* into the buffer, and add the command to the history list. */ * 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. */ /* Make sure the specified path is tilde-expanded. */
answer = free_and_assign(answer, real_dir_from_tilde(answer)); answer = free_and_assign(answer, real_dir_from_tilde(answer));
/* Read the specified file into the current buffer. */ /* Read the file into a new buffer or into current buffer. */
open_buffer(answer, TRUE); open_buffer(answer, ISSET(MULTIBUFFER));
} }
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER

View File

@ -75,7 +75,7 @@ void wrap_the_help_text(bool redisplaying)
if (redisplaying) if (redisplaying)
close_buffer(); close_buffer();
open_buffer(tempfilename, FALSE); open_buffer(tempfilename, TRUE);
remove_magicline(); remove_magicline();
prepare_for_display(); prepare_for_display();

View File

@ -1164,7 +1164,7 @@ bool scoop_stdin(void)
} }
/* Read the input into a new buffer. */ /* Read the input into a new buffer. */
open_buffer("", FALSE); open_buffer("", TRUE);
read_file(stream, 0, "stdin", TRUE, FALSE); read_file(stream, 0, "stdin", TRUE, FALSE);
openfile->edittop = openfile->fileage; openfile->edittop = openfile->fileage;
@ -2616,7 +2616,7 @@ int main(int argc, char **argv)
optind++; optind++;
if (!scoop_stdin()) if (!scoop_stdin())
continue; continue;
} else if (!open_buffer(argv[optind++], FALSE)) } else if (!open_buffer(argv[optind++], TRUE))
continue; continue;
/* If a position was given on the command line, go there. */ /* 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, * directories, then open a blank buffer and allow editing. Otherwise,
* switch from the last opened file to the next, that is: the first. */ * switch from the last opened file to the next, that is: the first. */
if (openfile == NULL) { if (openfile == NULL) {
open_buffer("", FALSE); open_buffer("", TRUE);
UNSET(VIEW_MODE); UNSET(VIEW_MODE);
} }
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER

View File

@ -267,7 +267,7 @@ void do_uncut_text(void);
/* Most functions in files.c. */ /* Most functions in files.c. */
void initialize_buffer_text(void); void initialize_buffer_text(void);
void set_modified(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 #ifdef ENABLE_SPELLER
void replace_buffer(const char *filename); void replace_buffer(const char *filename);
#ifndef NANO_TINY #ifndef NANO_TINY

View File

@ -3226,7 +3226,7 @@ void do_linter(void)
goto free_lints_and_return; goto free_lints_and_return;
} else if (i == 1) { } else if (i == 1) {
SET(MULTIBUFFER); SET(MULTIBUFFER);
open_buffer(curlint->filename, FALSE); open_buffer(curlint->filename, TRUE);
} else { } else {
char *dontwantfile = mallocstrcpy(NULL, curlint->filename); char *dontwantfile = mallocstrcpy(NULL, curlint->filename);
lintstruct *restlint = NULL; lintstruct *restlint = NULL;