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
parent
c2518dd5f0
commit
eb2661dc2d
15
src/files.c
15
src/files.c
|
@ -511,8 +511,8 @@ bool open_buffer(const char *filename, bool undoable)
|
|||
}
|
||||
|
||||
#ifndef DISABLE_SPELLER
|
||||
/* Blow away the text of the current buffer, and then open and read
|
||||
* the specified file into its place. */
|
||||
/* Open the specified file, and if that succeeds, blow away the text of
|
||||
* the current buffer and read the file contents into its place. */
|
||||
void replace_buffer(const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
|
@ -521,15 +521,18 @@ void replace_buffer(const char *filename)
|
|||
assert(filename != NULL && filename[0] != '\0');
|
||||
|
||||
/* 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. */
|
||||
free_filestruct(openfile->fileage);
|
||||
initialize_buffer_text();
|
||||
|
||||
/* If opening the file succeeded, read it in. */
|
||||
if (descriptor > 0)
|
||||
read_file(f, descriptor, filename, FALSE, TRUE);
|
||||
/* Insert the processed file into its place. */
|
||||
read_file(f, descriptor, filename, FALSE, TRUE);
|
||||
|
||||
/* Put current at a place that is certain to exist. */
|
||||
openfile->current = openfile->fileage;
|
||||
|
|
Loading…
Reference in New Issue