spelling: if rereading the file fails, don't destroy the current buffer

If for some reason opening the spell-checked or formatted file fails,
don't throw away the current contents of the buffer.

(It should also give proper feedback about the failure, but we'll leave
that for some other time.)
master
Benno Schulenberg 2016-04-17 17:33:18 +02:00
parent c2518dd5f0
commit eb2661dc2d
1 changed files with 9 additions and 6 deletions

View File

@ -511,8 +511,8 @@ bool open_buffer(const char *filename, bool undoable)
} }
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
/* Blow away the text of the current buffer, and then open and read /* Open the specified file, and if that succeeds, blow away the text of
* the specified file into its place. */ * the current buffer and read the file contents into its place. */
void replace_buffer(const char *filename) void replace_buffer(const char *filename)
{ {
FILE *f; FILE *f;
@ -521,15 +521,18 @@ void replace_buffer(const char *filename)
assert(filename != NULL && filename[0] != '\0'); assert(filename != NULL && filename[0] != '\0');
/* Open the file quietly. */ /* Open the file quietly. */
descriptor = open_file(filename, TRUE, FALSE, &f); descriptor = open_file(filename, FALSE, TRUE, &f);
/* If opening failed, forget it. */
if (descriptor < 0)
return;
/* Reinitialize the text of the current buffer. */ /* Reinitialize the text of the current buffer. */
free_filestruct(openfile->fileage); free_filestruct(openfile->fileage);
initialize_buffer_text(); initialize_buffer_text();
/* If opening the file succeeded, read it in. */ /* Insert the processed file into its place. */
if (descriptor > 0) read_file(f, descriptor, filename, FALSE, TRUE);
read_file(f, descriptor, filename, FALSE, TRUE);
/* Put current at a place that is certain to exist. */ /* Put current at a place that is certain to exist. */
openfile->current = openfile->fileage; openfile->current = openfile->fileage;