commit ecffb856563927916dd32a8dae30ccf8b6394c4a
parent f0bb50306c2a594b1a50a67767a1142ed851d8c3
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 27 Jun 2015 15:03:45 +0000
Forgetting the case of an empty filename for replace_buffer(),
and not bothering to put the pointer at the top.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5269 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -2,6 +2,10 @@
* src/text.c (do_undo, add_undo): Skip undoing a backspace *only* when
it really tried to delete the final, magic newline.
* src/nano.h, src/text.c: Rename three flags for clarity.
+ * src/files.c (replace_buffer): This function is only ever called with
+ a temporary file as parameter, so forget the case of an empty filename.
+ Also, don't bother putting the pointer at the top of the buffer, as the
+ first action after this function is to restore the cursor position.
2015-06-23 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (edit_draw): Verify that there exists multidata for the
diff --git a/src/files.c b/src/files.c
@@ -405,35 +405,26 @@ void open_buffer(const char *filename, bool undoable)
}
#ifndef DISABLE_SPELLER
-/* If it's not "", filename is a file to open. We blow away the text of
- * the current buffer, and then open and read the file, if
- * applicable. Note that we skip the operating directory test when
- * doing this. */
+/* Blow away the text of the current buffer, and then open and read
+ * the specified file into its place. */
void replace_buffer(const char *filename)
{
FILE *f;
- int rc;
- /* rc == -2 means that we have a new file. -1 means that the
- * open() failed. 0 means that the open() succeeded. */
+ int descriptor;
- assert(filename != NULL);
+ assert(filename != NULL && filename[0] != '\0');
- /* If the filename isn't blank, open the file. Otherwise, treat it
- * as a new file. */
- rc = (filename[0] != '\0') ? open_file(filename, TRUE, FALSE, &f) : -2;
+ /* Open the file quietly. */
+ descriptor = open_file(filename, TRUE, FALSE, &f);
/* Reinitialize the text of the current buffer. */
free_filestruct(openfile->fileage);
initialize_buffer_text();
- /* If we have a non-new file, read it in. */
- if (rc > 0)
- read_file(f, rc, filename, FALSE, TRUE);
+ /* If opening the file succeeded, read it in. */
+ if (descriptor > 0)
+ read_file(f, descriptor, filename, FALSE, TRUE);
- /* Move back to the beginning of the first line of the buffer. */
- openfile->current = openfile->fileage;
- openfile->current_x = 0;
- openfile->placewewant = 0;
}
#endif /* !DISABLE_SPELLER */