Yegappan,

I fixed the patch per your request.  I followed points 1 & 2, but I must say
that I disagree with point 3.  I think making this change would make the
function less readable.  Thus, I didn't include that change.

Let me know if this is acceptable.

Thanks,
Jason

-- 
-- 
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 8ddb5e6b03fe59c9e9d819ee0856e9d91e881e3a Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Wed, 30 May 2018 08:22:08 -0400
Subject: [PATCH] Fix bug with "CTRL-W <CR>" quickfix window command

---
 src/normal.c                  | 14 ++++----------
 src/proto/quickfix.pro        |  1 +
 src/quickfix.c                | 40 ++++++++++++++++++++++++++++++++++++++++
 src/testdir/test_quickfix.vim | 18 ++++++++++++++++++
 src/window.c                  | 17 ++++-------------
 5 files changed, 67 insertions(+), 23 deletions(-)

diff --git a/src/normal.c b/src/normal.c
index 58f7a7a..4196108 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(FALSE);
 #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..26a5de0 100644
--- a/src/proto/quickfix.pro
+++ b/src/proto/quickfix.pro
@@ -7,6 +7,7 @@ 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(int 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..1d33045 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3470,6 +3470,46 @@ qf_types(int c, int nr)
 }
 
 /*
+ * "<CR>": Open the entry/result under the cursor.
+ * "CTRL-W <CR>": Open the entry/result under the cursor in a new split.
+ */
+    void
+qf_view_result(int 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 == NULL || qi->qf_lists[qi->qf_curlist].qf_count == 0)
+    {
+	EMSG(_(e_quickfix));
+	return;
+    }
+
+    if (split)
+    {
+	vim_snprintf((char *) cmd, sizeof(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");
+
+	return;
+    }
+
+    vim_snprintf((char *) cmd, sizeof(cmd), ".%s",
+	    IS_LL_WINDOW(curwin) ? "ll" : "cc");
+
+    do_cmdline_cmd(cmd);
+}
+
+/*
  * ":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..6f084ad 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -3350,3 +3350,21 @@ func Test_qftitle()
   call assert_equal('Errors', w:quickfix_title)
   cclose
 endfunc
+
+" Tests for the "CTRL-W <CR>" command.
+func Xview_result_split_tests(cchar)
+  call s:setup_commands(a:cchar)
+
+  " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
+  call g:Xsetlist([])
+  Xopen
+  let l:win_count = winnr('$')
+  call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
+  call assert_equal(l:win_count, winnr('$'))
+  Xclose
+endfunc
+
+func Test_view_result_split()
+  call Xview_result_split_tests('c')
+  call Xview_result_split_tests('l')
+endfunc
diff --git a/src/window.c b/src/window.c
index d3ec4cd..190a6dd 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
+		    qf_view_result(TRUE);
 		break;
-
+#endif
 
 /* CTRL-W g  extended commands */
     case 'g':
-- 
2.7.4

Raspunde prin e-mail lui