Bram,
here is a patch, that returns the complete quickfix/location list stack.
This is needed, so plugin writers can correctly handle quickfix and
location lists.
Currently, there is no way, to set the quickfix lists back to their
original values (without running through the complete stack (using
colder/lolder).
regards,
Christian
--
Unsere Zeit ist ein großer Wecker. Die große eiserne Wanduhr rasselt
und ruft mit gewaltigen Schlägen.
-- Johann Gottfried Herder
--
--
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/groups/opt_out.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1793,10 +1793,12 @@
getline( {lnum}) String line {lnum} of current buffer
getline( {lnum}, {end}) List lines {lnum} to {end} of current buffer
getloclist( {nr}) List list of location list items
+getlocstack( {nr}) Dict stack of location lists
getmatches() List list of current matches
getpid() Number process ID of Vim
getpos( {expr}) List position of cursor, mark, etc.
getqflist() List list of quickfix items
+getqfstack() Dict stack of quickfix lists
getreg( [{regname} [, 1]]) String contents of register
getregtype( [{regname}]) String type of register
gettabvar( {nr}, {varname} [, {def}])
@@ -3380,6 +3382,14 @@
returned. For an invalid window number {nr}, an empty list is
returned. Otherwise, same as |getqflist()|.
+getlocstack({nr}) *getlocstack()*
+ Returns a dictionary with the complete stack of location
+ lists for window {nr}. When {nr} is zero the current
+ window is used.
+ For a location list window, the displayed location list is
+ returned. For an invalid window number {nr}, an empty
+ dictionary is returned. Otherwise, same as |getqfstack()|.
+
getmatches() *getmatches()*
Returns a |List| with all matches previously defined by
|matchadd()| and the |:match| commands. |getmatches()| is
@@ -3402,7 +3412,7 @@
:unlet m
<
-getqflist() *getqflist()*
+getqflist() *getqflist()*
Returns a list with all the current quickfix errors. Each
list item is a dictionary with these entries:
bufnr number of buffer that has the file name, use
@@ -3428,6 +3438,20 @@
: echo bufname(d.bufnr) ':' d.lnum '=' d.text
:endfor
+getqfstack({nr}) *getqfstack()*
+ Returns a dictionary with the stack of the quickfix lists
+ with the following items:
+ "cur" The current position in the quickfix stack
+ "entry0" A list with all errors of the first quickfix list.
+ See |getqflist()| for detail information on the
+ entries.
+ "entry1" A list with all errors of the second quickfix list.
+ ...
+ "entry9" A list with all errors of the last quickfix list.
+ "title0" |w:quickfix_title| of the first quickfix list.
+ "title1" |w:quickfix_title| of the second quickfix list.
+ ...
+ "title9" |w:quickfix_title| of the last quickfix list.
getreg([{regname} [, 1]]) *getreg()*
The result is a String, which is the contents of register
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -779,8 +779,10 @@
Quickfix and location lists: *quickfix-functions*
getqflist() list of quickfix errors
+ getqfstack() stack of quickfix lists
setqflist() modify a quickfix list
getloclist() list of location list items
+ getlocstack() stack of location lists
setloclist() modify a location list
Insert mode completion: *completion-functions*
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -556,6 +556,7 @@
static void f_getpid __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getqflist __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_getqfstack __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getregtype __ARGS((typval_T *argvars, typval_T *rettv));
static void f_gettabvar __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7936,10 +7937,12 @@
{"getftype", 1, 1, f_getftype},
{"getline", 1, 2, f_getline},
{"getloclist", 1, 1, f_getqflist},
+ {"getlocstack", 1, 1, f_getqfstack},
{"getmatches", 0, 0, f_getmatches},
{"getpid", 0, 0, f_getpid},
{"getpos", 1, 1, f_getpos},
{"getqflist", 0, 0, f_getqflist},
+ {"getqfstack", 0, 0, f_getqfstack},
{"getreg", 0, 2, f_getreg},
{"getregtype", 0, 1, f_getregtype},
{"gettabvar", 2, 3, f_gettabvar},
@@ -11711,7 +11714,37 @@
return;
}
- (void)get_errorlist(wp, rettv->vval.v_list);
+ (void)get_errorlist(wp, rettv->vval.v_list, NULL);
+ }
+#endif
+}
+
+/*
+ * "getqfstack()" functions
+ */
+ static void
+f_getqfstack(argvars, rettv)
+ typval_T *argvars UNUSED;
+ typval_T *rettv UNUSED;
+{
+#ifdef FEAT_QUICKFIX
+ win_T *wp;
+ list_T *l = list_alloc();
+#endif
+
+#ifdef FEAT_QUICKFIX
+ if (rettv_dict_alloc(rettv) == OK && l != NULL)
+ {
+ wp = NULL;
+ ++l->lv_refcount;
+ if (argvars[0].v_type != VAR_UNKNOWN) /* getlocstack() */
+ {
+ wp = find_win_by_nr(&argvars[0], NULL);
+ if (wp == NULL)
+ return;
+ }
+
+ (void)get_errorlist(wp, l, rettv->vval.v_dict);
}
#endif
}
diff --git a/src/proto/quickfix.pro b/src/proto/quickfix.pro
--- a/src/proto/quickfix.pro
+++ b/src/proto/quickfix.pro
@@ -23,7 +23,7 @@
void ex_cfile __ARGS((exarg_T *eap));
void ex_vimgrep __ARGS((exarg_T *eap));
char_u *skip_vimgrep_pat __ARGS((char_u *p, char_u **s, int *flags));
-int get_errorlist __ARGS((win_T *wp, list_T *list));
+int get_errorlist __ARGS((win_T *wp, list_T *list, dict_T *dict));
int set_errorlist __ARGS((win_T *wp, list_T *list, int action, char_u *title));
void ex_cbuffer __ARGS((exarg_T *eap));
void ex_cexpr __ARGS((exarg_T *eap));
diff --git a/src/quickfix.c b/src/quickfix.c
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3735,9 +3735,10 @@
* Add each quickfix error to list "list" as a dictionary.
*/
int
-get_errorlist(wp, list)
+get_errorlist(wp, list, dict_all)
win_T *wp;
list_T *list;
+ dict_T *dict_all;
{
qf_info_T *qi = &ql_info;
dict_T *dict;
@@ -3745,6 +3746,8 @@
qfline_T *qfp;
int i;
int bufnum;
+ int j;
+ char_u *qf_title;
if (wp != NULL)
{
@@ -3753,39 +3756,72 @@
return FAIL;
}
- if (qi->qf_curlist >= qi->qf_listcount
- || qi->qf_lists[qi->qf_curlist].qf_count == 0)
+ if (dict_all == NULL && (qi->qf_curlist >= qi->qf_listcount
+ || qi->qf_lists[qi->qf_curlist].qf_count == 0))
return FAIL;
- qfp = qi->qf_lists[qi->qf_curlist].qf_start;
- for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i)
+ j = (dict_all != NULL ? 0 : qi->qf_curlist);
+
+ for (; j < LISTCOUNT; j++)
{
- /* Handle entries with a non-existing buffer number. */
- bufnum = qfp->qf_fnum;
- if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
- bufnum = 0;
-
- if ((dict = dict_alloc()) == NULL)
- return FAIL;
- if (list_append_dict(list, dict) == FAIL)
- return FAIL;
-
- buf[0] = qfp->qf_type;
- buf[1] = NUL;
- if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL
- || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL
- || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL
- || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL
- || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL
- || dict_add_nr_str(dict, "pattern", 0L,
- qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL
- || dict_add_nr_str(dict, "text", 0L,
- qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL
- || dict_add_nr_str(dict, "type", 0L, buf) == FAIL
- || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL)
- return FAIL;
-
- qfp = qfp->qf_next;
+ qfp = qi->qf_lists[j].qf_start;
+ qf_title = qi->qf_lists[j].qf_title;
+ for (i = 1; !got_int && i <= qi->qf_lists[j].qf_count; ++i)
+ {
+ /* Handle entries with a non-existing buffer number. */
+ bufnum = qfp->qf_fnum;
+ if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
+ bufnum = 0;
+
+ if ((dict = dict_alloc()) == NULL)
+ return FAIL;
+ if (list_append_dict(list, dict) == FAIL)
+ return FAIL;
+
+ buf[0] = qfp->qf_type;
+ buf[1] = NUL;
+ if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL
+ || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL
+ || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL
+ || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL
+ || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL
+ || dict_add_nr_str(dict, "pattern", 0L,
+ qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL
+ || dict_add_nr_str(dict, "text", 0L,
+ qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL
+ || dict_add_nr_str(dict, "type", 0L, buf) == FAIL
+ || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL)
+ return FAIL;
+
+ qfp = qfp->qf_next;
+ }
+ if (dict_all == NULL)
+ break;
+ else
+ {
+ if (qi->qf_lists[j].qf_count == 0)
+ {
+ dict = dict_alloc();
+ list_append_dict(list,dict);
+ }
+ if (list != NULL)
+ {
+ char label[7] = "";
+ sprintf(label, "entry%d", j);
+ dict_add_list(dict_all, (char *)&label, list);
+ sprintf(label, "title%d", j);
+ if ((dict_add_nr_str(dict_all, (char *)&label, 0L,
+ qf_title == NULL ? (char_u *)"" : qf_title) == FAIL))
+ return FAIL;
+ if ((list = list_alloc()) == NULL)
+ return FAIL;
+ }
+ }
+ }
+ if (dict_all != NULL)
+ {
+ if (dict_add_nr_str(dict_all, "cur", qi->qf_curlist, NULL) == FAIL)
+ return FAIL;
}
return OK;
}