Hi all,

I think I've found a small bug with the gF command.

The gF command allows one to jump to the file and line number under the cursor. 
However, if the current file can't be abandoned (e.g. there are unwritten 
changes), the "jump to file" part fails, but the "jump to line number" part 
still executes. As a result, the cursor will unexpectedly move in the current 
file, even though the command failed.

The attached patch fixes this so that the "jump to line number" action is only 
done if the new file is successfully opened.

Thanks,

Michael Hwang

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
>From 8bb16d2fd12f868cca32d86d11e3f5695bb5a783 Mon Sep 17 00:00:00 2001
From: Michael Hwang <[email protected]>
Date: Mon, 22 May 2017 11:54:34 -0400
Subject: [PATCH] For gF (goto file and line), don't jump to line if file
 fails to open.

---
 src/normal.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/normal.c b/src/normal.c
index 25c0986..0716d2c 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -6227,6 +6227,7 @@ nv_gotofile(cmdarg_T *cap)
 {
     char_u	*ptr;
     linenr_T	lnum = -1;
+    int		opened;
 
     if (text_locked())
     {
@@ -6250,9 +6251,9 @@ nv_gotofile(cmdarg_T *cap)
 	if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !P_HID(curbuf))
 	    (void)autowrite(curbuf, FALSE);
 	setpcmark();
-	(void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
+	int opened = do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
 				       P_HID(curbuf) ? ECMD_HIDE : 0, curwin);
-	if (cap->nchar == 'F' && lnum >= 0)
+	if (opened == OK && cap->nchar == 'F' && lnum >= 0)
 	{
 	    curwin->w_cursor.lnum = lnum;
 	    check_cursor_lnum();
-- 
1.7.9.5

Raspunde prin e-mail lui