Hi,

On Mon, Mar 20, 2017 at 1:47 PM, Bram Moolenaar <[email protected]> wrote:
>
> Yegappan wrote:
>
>> When developing additional tests for the quickfix functionality,
>> I found that some part of the code checks whether the quickfix
>> or location list stack is empty. To test for these conditions, we
>> need a function to delete the quickfix and location list stacks.
>>
>> What about extending the setqflist() and setloclist() functions
>> to add support for deleting a list? If the action parameter is 'd',
>> then delete the last quickfix/location list. If the action
>> parameter is 'w', then wipe out the entire list.
>>
>> setqflist([], 'd')  - Delete the last quickfix list.
>> setqflist([], 'w') - Wipe out the quickfix stack.
>> setloclist(0, [], 'd') - Delete the last location list.
>> setloclist(0, [], 'w') - Wipe out the location list stack.
>>
>> Do you have any other suggestions?
>
> Does this have any other use than for testing?  If not, then I would
> keep it as simple as possible.  Perhaps we don't need the "w" argument?
>

The attached patch adds support for freeing the quickfix stack
using the setqflist() function. Updated the quickfix tests to
make use of this functionality and added additional test cases.

- Yegappan

-- 
-- 
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.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index db0a756..2e8927c 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -6946,6 +6946,9 @@ setqflist({list} [, {action}[, {what}]])          
*setqflist()*
                can also be used to clear the list: >
                        :call setqflist([], 'r')
 <      
+               If {action} is set to 'f', then all the quickfix lists in the
+               quickfix stack are freed.
+
                If {action} is not present or is set to ' ', then a new list
                is created.
 
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 8869810..40dd5e9 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -10038,7 +10038,8 @@ set_qf_ll_list(
            act = get_tv_string_chk(action_arg);
            if (act == NULL)
                return;         /* type error; errmsg already given */
-           if ((*act == 'a' || *act == 'r' || *act == ' ') && act[1] == NUL)
+           if ((*act == 'a' || *act == 'r' || *act == ' ' || *act == 'f') &&
+                   act[1] == NUL)
                action = *act;
            else
                EMSG2(_(e_invact), act);
diff --git a/src/quickfix.c b/src/quickfix.c
index 9021212..09701db 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4861,6 +4861,17 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int 
action)
     return retval;
 }
 
+    static void
+qf_free_stack(win_T *wp, qf_info_T *qi)
+{
+    qf_free_all(wp);
+    if (wp == NULL) {
+       /* quickfix list */
+       qi->qf_curlist = 0;
+       qi->qf_listcount = 0;
+    }
+}
+
 /*
  * Populate the quickfix list with the items supplied in the list
  * of dictionaries. "title" will be copied to w:quickfix_title.
@@ -4884,10 +4895,15 @@ set_errorlist(
            return FAIL;
     }
 
-    if (what != NULL)
-       retval = qf_set_properties(qi, what, action);
-    else
-       retval = qf_add_entries(qi, list, title, action);
+    if (action == 'f') {
+       /* Free the entire quickfix or location list stack */
+       qf_free_stack(wp, qi);
+    } else {
+       if (what != NULL)
+           retval = qf_set_properties(qi, what, action);
+       else
+           retval = qf_add_entries(qi, list, title, action);
+    }
 
     return retval;
 }
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 94b56e6..6e4b8c2 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -38,6 +38,7 @@ func s:setup_commands(cchar)
     command! -nargs=* Xhelpgrep helpgrep <args>
     let g:Xgetlist = function('getqflist')
     let g:Xsetlist = function('setqflist')
+    call setqflist([], 'f')
   else
     command! -nargs=* -bang Xlist <mods>llist<bang> <args>
     command! -nargs=* Xgetexpr <mods>lgetexpr <args>
@@ -69,6 +70,7 @@ func s:setup_commands(cchar)
     command! -nargs=* Xhelpgrep lhelpgrep <args>
     let g:Xgetlist = function('getloclist', [0])
     let g:Xsetlist = function('setloclist', [0])
+    call setloclist(0, [], 'f')
   endif
 endfunc
 
@@ -76,6 +78,9 @@ endfunc
 func XlistTests(cchar)
   call s:setup_commands(a:cchar)
 
+  if a:cchar == 'l'
+      call assert_fails('llist', 'E776:')
+  endif
   " With an empty list, command should return error
   Xgetexpr []
   silent! Xlist
@@ -146,6 +151,9 @@ endfunc
 func XageTests(cchar)
   call s:setup_commands(a:cchar)
 
+  let list = [{'bufnr': 1, 'lnum': 1}]
+  call g:Xsetlist(list)
+
   " Jumping to a non existent list should return error
   silent! Xolder 99
   call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
@@ -179,11 +187,7 @@ func XageTests(cchar)
 endfunc
 
 func Test_cage()
-  let list = [{'bufnr': 1, 'lnum': 1}]
-  call setqflist(list)
   call XageTests('c')
-
-  call setloclist(0, list)
   call XageTests('l')
 endfunc
 
@@ -192,6 +196,11 @@ endfunc
 func XwindowTests(cchar)
   call s:setup_commands(a:cchar)
 
+  " Opening the location list window without any errors should fail
+  if a:cchar == 'l'
+      call assert_fails('lopen', 'E776:')
+  endif
+
   " Create a list with no valid entries
   Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
 
@@ -232,6 +241,19 @@ func XwindowTests(cchar)
   " Calling cwindow should close the quickfix window with no valid errors
   Xwindow
   call assert_true(winnr('$') == 1)
+
+  if a:cchar == 'c'
+      " Opening the quickfix window in multiple tab pages should reuse the
+      " quickfix buffer
+      Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
+                 \ 'Xtestfile3:3:1:Line3']
+      Xopen
+      let qfbufnum = bufnr('%')
+      tabnew
+      Xopen
+      call assert_equal(qfbufnum, bufnr('%'))
+      new | only | tabonly
+  endif
 endfunc
 
 func Test_cwindow()
@@ -360,6 +382,13 @@ endfunc
 func Xtest_browse(cchar)
   call s:setup_commands(a:cchar)
 
+  " Jumping to first or next location list entry without any error should
+  " result in failure
+  if a:cchar == 'l'
+      call assert_fails('lfirst', 'E776:')
+      call assert_fails('lnext', 'E776:')
+  endif
+
   call s:create_test_file('Xqftestfile1')
   call s:create_test_file('Xqftestfile2')
 
@@ -1550,6 +1579,11 @@ endfunc
 func XbottomTests(cchar)
   call s:setup_commands(a:cchar)
 
+  " Calling lbottom without any errors should fail
+  if a:cchar == 'l'
+      call assert_fails('lbottom', 'E776:')
+  endif
+
   call g:Xsetlist([{'filename': 'foo', 'lnum': 42}]) 
   Xopen
   let wid = win_getid()
@@ -1571,10 +1605,9 @@ endfunc
 func HistoryTest(cchar)
   call s:setup_commands(a:cchar)
 
-  call assert_fails(a:cchar . 'older 99', 'E380:')
   " clear all lists after the first one, then replace the first one.
   call g:Xsetlist([])
-  Xolder
+  call assert_fails('Xolder 99', 'E380:')
   let entry = {'filename': 'foo', 'lnum': 42}
   call g:Xsetlist([entry], 'r')
   call g:Xsetlist([entry, entry])
@@ -1617,6 +1650,7 @@ func Xproperty_tests(cchar)
     call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
 
     " Set and get the title
+    call g:Xsetlist([])
     Xopen
     wincmd p
     call g:Xsetlist([{'filename':'foo', 'lnum':27}])

Raspunde prin e-mail lui