From 37d8ad8687bfa82a181517e0616bfeda97548d67 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 30 Dec 2015 10:11:20 +0000 Subject: [PATCH] Not trying to position the cursor when opening a buffer failed. This fixes Savannah bug #46778. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5514 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 9 +++++---- src/nano.c | 4 +++- src/proto.h | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89ff5007..bafff506 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-12-30 Benno Schulenberg + * src/nano.c (main), src/files.c (open_buffer): Don't try to position + the cursor when opening a buffer failed (because the user specified a + directory, for example). This fixes Savannah bug #46778. + 2015-12-29 Benno Schulenberg * doc/syntax/{c,objc,asm}.nanorc: Disable the regex for multiline strings as it colours some things wrong and is a glutton on time. diff --git a/src/files.c b/src/files.c index 59034844..5e421372 100644 --- a/src/files.c +++ b/src/files.c @@ -323,7 +323,7 @@ int do_lockfile(const char *filename) /* If it's not "", filename is a file to open. We make a new buffer, if * necessary, and then open and read the file, if applicable. */ -void open_buffer(const char *filename, bool undoable) +bool open_buffer(const char *filename, bool undoable) { bool quiet = FALSE; bool new_buffer = (openfile == NULL @@ -343,7 +343,7 @@ void open_buffer(const char *filename, bool undoable) if (check_operating_dir(filename, FALSE)) { statusbar(_("Can't insert file from outside of %s"), operating_dir); - return; + return FALSE; } #endif @@ -358,7 +358,7 @@ void open_buffer(const char *filename, bool undoable) else statusbar(_("\"%s\" is not a normal file"), filename); beep(); - return; + return FALSE; } } @@ -374,7 +374,7 @@ void open_buffer(const char *filename, bool undoable) #ifndef DISABLE_MULTIBUFFER if (openfile->next) { close_buffer(TRUE); - return; + return FALSE; } #endif } else if (lockstatus == 0) { @@ -421,6 +421,7 @@ void open_buffer(const char *filename, bool undoable) if (new_buffer) color_update(); #endif + return TRUE; } #ifndef DISABLE_SPELLER diff --git a/src/nano.c b/src/nano.c index dc998106..9066bf0e 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2622,7 +2622,9 @@ int main(int argc, char **argv) if (i < argc - 1 && argv[i][0] == '+') parse_line_column(&argv[i][1], &iline, &icol); else { - open_buffer(argv[i], FALSE); + /* If opening fails, don't try to position the cursor. */ + if (!open_buffer(argv[i], FALSE)) + continue; /* If a position was given on the command line, go there. */ if (iline > 0 || icol > 0) { diff --git a/src/proto.h b/src/proto.h index 0d2683c2..566790d4 100644 --- a/src/proto.h +++ b/src/proto.h @@ -283,7 +283,7 @@ void do_uncut_text(void); /* All functions in files.c. */ void make_new_buffer(void); void initialize_buffer_text(void); -void open_buffer(const char *filename, bool undoable); +bool open_buffer(const char *filename, bool undoable); #ifndef DISABLE_SPELLER void replace_buffer(const char *filename); #endif -- 2.39.5