Yegappan, Attached is the updated patch. To confirm, I...
* merged qf_view_result() and qf_view_result_split() * used vim_snprintf(); I believe I used it properly * I used the X... functions to merge the test code Let me know what you think! -- Jason Franklin -- -- 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 97516709ae8f44627c72d9662f23257261431dfe Mon Sep 17 00:00:00 2001 From: Jason Franklin <[email protected]> Date: Tue, 29 May 2018 16:02:15 -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 | 19 +++++-------------- 5 files changed, 68 insertions(+), 24 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..4129dc5 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->qf_lists[qi->qf_curlist].qf_count == 0) + { + EMSG(_(e_quickfix)); + return; + } + + if (split == TRUE) + { + 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..b79824b 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(TRUE); break; - +#endif /* CTRL-W g extended commands */ case 'g': -- 2.7.4
