Hi Bram,

On Sun, Aug 14, 2016 at 8:33 AM, Bram Moolenaar <[email protected]> wrote:
>
> Yegappan wrote:
>
>> On Mon, Aug 8, 2016 at 4:37 PM, Yegappan Lakshmanan <[email protected]> 
>> wrote:
>> >
>> >>
>> >> By the way, I remember some patches that add functions returning
>> >> information about buffer/window/tabpage. It would be logical if
>> >> information regarding whether given buffer contains
>> >> quickfix/location/no list was included there.
>> >>
>> >
>> > I agree. The patch to get information about a buffer/window/tab page
>> > is at:
>> >
>> > https://github.com/vim/vim/pull/833
>> >
>> > The information about the quickfix/location list window/buffer can be
>> > added to this patch.
>> >
>>
>> I am attaching a patch to add two new fields to the dict returned
>> by the getwininfo() function. The 'qfwin' field is set to true for the
>> quickfix window and the 'llwin' field is set to true for the location
>> list window.
>>
>> In this patch I also made some other minor changes. Updated the
>> help text for getwinfo() and gettabinfo() to alphabetically sort the
>> field names. Used the FOR_ALL_BUFFERS() and FOR_ALL_TABPAGES()
>> macros for walking all the buffers and tab pages in the f_getbufinfo(),
>> f_gettabinfo() and f_getwininfo() functions.
>
> Thanks.
>
> I find "qfwin" and "llwin" a bit obscure.  And they always have opposite
> values.
>
> I think it would be more useful to have one flag that means the window
> is a quickfix window, since that means it behaves differently.  And
> another flag to tell us whether it's showing quickfix errors or a
> location list.  Perhaps they could be named "quickfix" and "loclist"?
> This reflects the value of 'buftype' and setloclist().
>

I am attaching an updated patch that implements the above.

- 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 6c81575..b0dbfd5 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -4527,8 +4527,8 @@ gettabinfo([{arg}])                                       
*gettabinfo()*
 
                Each List item is a Dictionary with the following entries:
                        nr              tab page number.
-                       windows         List of window IDs in the tag page.
                        variables       dictionary of tabpage local variables.
+                       windows         List of window IDs in the tag page.
 
 gettabvar({tabnr}, {varname} [, {def}])                                
*gettabvar()*
                Get the value of a tab-local variable {varname} in tab page
@@ -4582,14 +4582,16 @@ getwininfo([{winid}])                                   
*getwininfo()*
                pages is returned.
 
                Each List item is a Dictionary with the following entries:
-                       nr              window number.
-                       tpnr            tab page number.
-                       winid           window ID.
-                       height          window height.
-                       width           window width.
                        bufnum          number of buffer in the window.
+                       height          window height.
+                       loclist         showing a location list
+                       nr              window number.
                        options         dictionary of window local options.
+                       quickfix        quickfix or a location list window
+                       tpnr            tab page number.
                        variables       dictionary of window local variables.
+                       width           window width.
+                       winid           window ID.
 
 getwinvar({winnr}, {varname} [, {def}])                                
*getwinvar()*
                Like |gettabwinvar()| for the current tabpage.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index ba6f0f5..cc38d94 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4027,7 +4027,7 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
     }
 
     /* Return information about all the buffers or a specified buffer */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (argbuf != NULL && argbuf != buf)
            continue;
@@ -5030,7 +5030,7 @@ f_gettabinfo(typval_T *argvars, typval_T *rettv)
 #ifdef FEAT_WINDOWS
     tabpage_T  *tp, *tparg = NULL;
     dict_T     *d;
-    int                tpnr = 1;
+    int                tpnr = 0;
 
     if (rettv_list_alloc(rettv) != OK)
        return;
@@ -5044,8 +5044,9 @@ f_gettabinfo(typval_T *argvars, typval_T *rettv)
     }
 
     /* Get information about a specific tab page or all tab pages */
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, tpnr++)
+    FOR_ALL_TABPAGES(tp)
     {
+       tpnr++;
        if (tparg != NULL && tp != tparg)
            continue;
        d = get_tabpage_info(tp, tpnr);
@@ -5131,6 +5132,12 @@ get_win_info(win_T *wp, short tpnr, short winnr)
     dict_add_nr_str(dict, "width", wp->w_width, NULL);
     dict_add_nr_str(dict, "bufnum", wp->w_buffer->b_fnum, NULL);
 
+#ifdef FEAT_QUICKFIX
+    dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL);
+    dict_add_nr_str(dict, "loclist",
+           (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL);
+#endif
+
     /* Copy window variables */
     vars = dict_copy(wp->w_vars, TRUE, 0);
     if (vars != NULL)
@@ -5155,7 +5162,7 @@ f_getwininfo(typval_T *argvars, typval_T *rettv)
     tabpage_T  *tp;
     win_T      *wp = NULL, *wparg = NULL;
     dict_T     *d;
-    short      tabnr, winnr;
+    short      tabnr = 0, winnr;
 #endif
 
     if (rettv_list_alloc(rettv) != OK)
@@ -5172,13 +5179,13 @@ f_getwininfo(typval_T *argvars, typval_T *rettv)
     /* Collect information about either all the windows across all the tab
      * pages or one particular window.
      */
-    tabnr = 1;
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, tabnr++)
+    FOR_ALL_TABPAGES(tp)
     {
-       wp = (tp == curtab) ? firstwin : tp->tp_firstwin;
-       winnr = 1;
-       for (; wp; wp = wp->w_next, winnr++)
+       tabnr++;
+       winnr = 0;
+       FOR_ALL_WINDOWS_IN_TAB(tp, wp)
        {
+           winnr++;
            if (wparg != NULL && wp != wparg)
                continue;
            d = get_win_info(wp, tabnr, winnr);
diff --git a/src/testdir/test_bufwintabinfo.vim 
b/src/testdir/test_bufwintabinfo.vim
index 236ca30..2c91e2f 100644
--- a/src/testdir/test_bufwintabinfo.vim
+++ b/src/testdir/test_bufwintabinfo.vim
@@ -35,4 +35,16 @@ function Test_getbufwintabinfo()
     call assert_equal([], gettabinfo(3))
 
     tabonly | only
+
+    lexpr ''
+    lopen
+    copen
+    let winlist = getwininfo()
+    call assert_false(winlist[0].quickfix)
+    call assert_false(winlist[0].loclist)
+    call assert_true(winlist[1].quickfix)
+    call assert_true(winlist[1].loclist)
+    call assert_true(winlist[2].quickfix)
+    call assert_false(winlist[2].loclist)
+    wincmd t | only
 endfunction

Raspunde prin e-mail lui