This patch fixes a minor bug with the quickfix window.  It also makes a small
improvement and does some refactoring.

To reproduce the bug:

  vim -u NONE
  :copen
  <C-W><CR>

... note that you get an error message and a window still opens.  A window
should not open.

The refactoring is farily obvious.  Callbacks for "<CR>" and "CTRL-W <CR>" in
the quickfix window are moved into "quickfix.c".  This seems like the natural
place for these functions.

The improvement is somewhat nice.  If the split succeeds, we clear the jumplist
in the new window with the ":clearjumps" command.  This means that we can't
jump back to the quickfix list in the new window (we don't want two quickfix
lists).

As usual, a test is included to make sure that the bug remains fixed.

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>From 1591f6a25c962ed58adad2211304a53da7170dbe Mon Sep 17 00:00:00 2001
From: Jason Franklin <j_...@fastmail.us>
Date: Tue, 29 May 2018 10:40:45 -0400
Subject: [PATCH] Fix bug with "CTRL-W <CR>" quickfix window command

---
 src/normal.c                  | 14 ++++----------
 src/proto/quickfix.pro        |  2 ++
 src/quickfix.c                | 44 +++++++++++++++++++++++++++++++++++++++++++
 src/testdir/test_quickfix.vim | 20 ++++++++++++++++++++
 src/window.c                  | 19 +++++--------------
 5 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/src/normal.c b/src/normal.c
index 58f7a7a..9bd668f 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -6195,18 +6195,12 @@ nv_down(cmdarg_T *cap)
 	cap->arg = FORWARD;
 	nv_page(cap);
     }
-    else
 #if defined(FEAT_QUICKFIX)
-    /* In a quickfix window a <CR> jumps to the error under the cursor. */
-    if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
-    {
-	if (curwin->w_llist_ref == NULL)
-	    do_cmdline_cmd((char_u *)".cc");	/* quickfix window */
-	else
-	    do_cmdline_cmd((char_u *)".ll");	/* location list window */
-    }
-    else
+    /* Quickfix window only: view the result under the cursor. */
+    else if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
+	qf_view_result();
 #endif
+    else
     {
 #ifdef FEAT_CMDWIN
 	/* In the cmdline window a <CR> executes the command. */
diff --git a/src/proto/quickfix.pro b/src/proto/quickfix.pro
index d32655f..6d41e57 100644
--- a/src/proto/quickfix.pro
+++ b/src/proto/quickfix.pro
@@ -7,6 +7,8 @@ void qf_list(exarg_T *eap);
 void qf_age(exarg_T *eap);
 void qf_history(exarg_T *eap);
 void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after);
+void qf_view_result();
+void qf_view_result_split();
 void ex_cwindow(exarg_T *eap);
 void ex_cclose(exarg_T *eap);
 void ex_copen(exarg_T *eap);
diff --git a/src/quickfix.c b/src/quickfix.c
index 1b281ce..3d52b11 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3470,6 +3470,50 @@ qf_types(int c, int nr)
 }
 
 /*
+ * "<CR>": Open the entry/result under the cursor.
+ */
+    void
+qf_view_result()
+{
+    char_u      cmd[32];
+
+    if (!bt_quickfix(curbuf))
+	return;
+
+    sprintf((char *) cmd, ".%s", IS_LL_WINDOW(curwin) ? "ll" : "cc");
+
+    do_cmdline_cmd(cmd);
+}
+
+/*
+ * "CTRL-W <CR>": Open the entry/result under the cursor in a new split.
+ */
+    void
+qf_view_result_split()
+{
+    char_u      cmd[32];
+    qf_info_T   *qi = &ql_info;
+
+    if (!bt_quickfix(curbuf))
+	return;
+
+    if (IS_LL_WINDOW(curwin))
+	qi = GET_LOC_LIST(curwin);
+
+    if (qi->qf_lists[qi->qf_curlist].qf_count == 0)
+    {
+	EMSG(_(e_quickfix));
+	return;
+    }
+
+    sprintf((char *) cmd, "split +%ld%s", (long) curwin->w_cursor.lnum,
+	    IS_LL_WINDOW(curwin) ? "ll" : "cc");
+
+    if (do_cmdline_cmd(cmd) == OK)
+	do_cmdline_cmd((char_u *) "clearjumps");
+}
+
+/*
  * ":cwindow": open the quickfix window if we have errors to display,
  *	       close it if not.
  * ":lwindow": open the location list window if we have locations to display,
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index c3850ce..e131e8b 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -3350,3 +3350,23 @@ func Test_qftitle()
   call assert_equal('Errors', w:quickfix_title)
   cclose
 endfunc
+
+" Test for the "CTRL-W <CR>" command.
+func Test_qf_view_result_split()
+
+  " Test that "CTRL-W <CR>" in a quickfix window fails with empty list.
+  call setqflist([])
+  copen
+  let l:win_count = winnr('$')
+  call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
+  call assert_equal(l:win_count, winnr('$'))
+  cclose
+
+  " Test that "CTRL-W <CR>" in a location list window fails with empty list.
+  call setloclist(0, [])
+  lopen
+  let l:win_count = winnr('$')
+  call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
+  call assert_equal(l:win_count, winnr('$'))
+  lclose
+endfunc
diff --git a/src/window.c b/src/window.c
index d3ec4cd..5df4af9 100644
--- a/src/window.c
+++ b/src/window.c
@@ -520,23 +520,14 @@ wingotofile:
 		break;
 #endif
 
+/* Quickfix window only: view the result under the cursor in a new split. */
+#if defined(FEAT_QUICKFIX)
     case K_KENTER:
     case CAR:
-#if defined(FEAT_QUICKFIX)
-		/*
-		 * In a quickfix window a <CR> jumps to the error under the
-		 * cursor in a new window.
-		 */
-		if (bt_quickfix(curbuf))
-		{
-		    sprintf((char *)cbuf, "split +%ld%s",
-				(long)curwin->w_cursor.lnum,
-				(curwin->w_llist_ref == NULL) ? "cc" : "ll");
-		    do_cmdline_cmd(cbuf);
-		}
-#endif
+		if (bt_quickfix(curbuf) == TRUE)
+		    qf_view_result_split();
 		break;
-
+#endif
 
 /* CTRL-W g  extended commands */
     case 'g':
-- 
2.7.4

Raspunde prin e-mail lui