To: vim_dev@googlegroups.com Subject: Patch 7.4.2200 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2200 Problem: Cannot get all information about a quickfix list. Solution: Add an optional argument to get/set loc/qf list(). (Yegappan Lakshmanan) Files: runtime/doc/eval.txt, src/evalfunc.c, src/proto/quickfix.pro, src/quickfix.c, src/tag.c, src/testdir/test_quickfix.vim *** ../vim-7.4.2199/runtime/doc/eval.txt 2016-08-07 18:22:30.430091014 +0200 --- runtime/doc/eval.txt 2016-08-12 16:00:14.482659857 +0200 *************** *** 2081,2091 **** getftype({fname}) String description of type of file {fname} 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 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 getreg([{regname} [, 1 [, {list}]]]) String or List contents of register getregtype([{regname}]) String type of register --- 2102,2112 ---- getftype({fname}) String description of type of file {fname} getline({lnum}) String line {lnum} of current buffer getline({lnum}, {end}) List lines {lnum} to {end} of current buffer ! getloclist({nr}[, {what}]) List list of location list items getmatches() List list of current matches getpid() Number process ID of Vim getpos({expr}) List position of cursor, mark, etc. ! getqflist([{what}]) List list of quickfix items getreg([{regname} [, 1 [, {list}]]]) String or List contents of register getregtype([{regname}]) String type of register *************** *** 2240,2250 **** setcmdpos({pos}) Number set cursor position in command-line setfperm({fname}, {mode}) Number set {fname} file permissions to {mode} setline({lnum}, {line}) Number set line {lnum} to {line} ! setloclist({nr}, {list}[, {action}]) Number modify location list using {list} setmatches({list}) Number restore a list of matches setpos({expr}, {list}) Number set the {expr} position to {list} ! setqflist({list}[, {action}]) Number modify quickfix list using {list} setreg({n}, {v}[, {opt}]) Number set register to value and type settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val} settabwinvar({tabnr}, {winnr}, {varname}, {val}) --- 2261,2272 ---- setcmdpos({pos}) Number set cursor position in command-line setfperm({fname}, {mode}) Number set {fname} file permissions to {mode} setline({lnum}, {line}) Number set line {lnum} to {line} ! setloclist({nr}, {list}[, {action}[, {what}]]) Number modify location list using {list} setmatches({list}) Number restore a list of matches setpos({expr}, {list}) Number set the {expr} position to {list} ! setqflist({list}[, {action}[, {what}]]) ! Number modify quickfix list using {list} setreg({n}, {v}[, {opt}]) Number set register to value and type settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val} settabwinvar({tabnr}, {winnr}, {varname}, {val}) *************** *** 4275,4281 **** < To get lines from another buffer see |getbufline()| ! getloclist({nr}) *getloclist()* Returns a list with all the entries in the location list for window {nr}. {nr} can be the window number or the window ID. When {nr} is zero the current window is used. --- 4318,4324 ---- < To get lines from another buffer see |getbufline()| ! getloclist({nr},[, {what}]) *getloclist()* Returns a list with all the entries in the location list for window {nr}. {nr} can be the window number or the window ID. When {nr} is zero the current window is used. *************** *** 4284,4289 **** --- 4327,4336 ---- returned. For an invalid window number {nr}, an empty list is returned. Otherwise, same as |getqflist()|. + If the optional {what} dictionary argument is supplied, then + returns the items listed in {what} as a dictionary. Refer to + |getqflist()| for the supported items in {what}. + getmatches() *getmatches()* Returns a |List| with all matches previously defined by |matchadd()| and the |:match| commands. |getmatches()| is *************** *** 4305,4312 **** 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > :unlet m < ! 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 --- 4352,4387 ---- 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > :unlet m < + *getpid()* + getpid() Return a Number which is the process ID of the Vim process. + On Unix and MS-Windows this is a unique number, until Vim + exits. On MS-DOS it's always zero. ! *getpos()* ! getpos({expr}) Get the position for {expr}. For possible values of {expr} ! see |line()|. For getting the cursor position see ! |getcurpos()|. ! The result is a |List| with four numbers: ! [bufnum, lnum, col, off] ! "bufnum" is zero, unless a mark like '0 or 'A is used, then it ! is the buffer number of the mark. ! "lnum" and "col" are the position in the buffer. The first ! column is 1. ! The "off" number is zero, unless 'virtualedit' is used. Then ! it is the offset in screen columns from the start of the ! character. E.g., a position within a or after the last ! character. ! Note that for '< and '> Visual mode matters: when it is "V" ! (visual line mode) the column of '< is zero and the column of ! '> is a large number. ! This can be used to save and restore the position of a mark: > ! let save_a_mark = getpos("'a") ! ... ! call setpos("'a", save_a_mark) ! < Also see |getcurpos()| and |setpos()|. ! ! ! getqflist([{what}]) *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 *************** *** 4331,4337 **** --- 4406,4433 ---- :for d in getqflist() : echo bufname(d.bufnr) ':' d.lnum '=' d.text :endfor + < + If the optional {what} dictionary argument is supplied, then + returns only the items listed in {what} as a dictionary. The + following string items are supported in {what}: + nr get information for this quickfix list + title get list title + winid get window id (if opened) + all all of the above quickfix properties + Non-string items in {what} are ignored. + If "nr" is not present then the current quickfix list is used. + In case of error processing {what}, an empty dictionary is + returned. + + The returned dictionary contains the following entries: + nr quickfix list number + title quickfix list title text + winid quickfix window id (if opened) + Examples: > + :echo getqflist({'all': 1}) + :echo getqflist({'nr': 2, 'title': 1}) + < getreg([{regname} [, 1 [, {list}]]]) *getreg()* The result is a String, which is the contents of register *************** *** 6478,6484 **** :endfor < Note: The '[ and '] marks are not set. ! setloclist({nr}, {list} [, {action}]) *setloclist()* Create or replace or add to the location list for window {nr}. {nr} can be the window number or the window ID. When {nr} is zero the current window is used. --- 6568,6574 ---- :endfor < Note: The '[ and '] marks are not set. ! setloclist({nr}, {list} [, {action}[, {what}]) *setloclist()* Create or replace or add to the location list for window {nr}. {nr} can be the window number or the window ID. When {nr} is zero the current window is used. *************** *** 6488,6493 **** --- 6578,6587 ---- Otherwise, same as |setqflist()|. Also see |location-list|. + If the optional {what} dictionary argument is supplied, then + only the items listed in {what} are set. Refer to |setqflist()| + for the list of supported keys in {what}. + setmatches({list}) *setmatches()* Restores a list of matches saved by |getmatches()|. Returns 0 if successful, otherwise -1. All current matches are cleared *************** *** 6540,6547 **** also set the preferred column. Also see the "curswant" key in |winrestview()|. ! ! setqflist({list} [, {action}]) *setqflist()* Create or replace or add to the quickfix list using the items in {list}. Each item in {list} is a dictionary. Non-dictionary items in {list} are ignored. Each dictionary --- 6634,6640 ---- also set the preferred column. Also see the "curswant" key in |winrestview()|. ! setqflist({list} [, {action}[, {what}]]) *setqflist()* Create or replace or add to the quickfix list using the items in {list}. Each item in {list} is a dictionary. Non-dictionary items in {list} are ignored. Each dictionary *************** *** 6573,6585 **** Note that the list is not exactly the same as what |getqflist()| returns. If {action} is set to 'a', then the items from {list} are added to the existing quickfix list. If there is no existing ! list, then a new list is created. If {action} is set to 'r', ! then the items from the current quickfix list are replaced ! with the items from {list}. If {action} is not present or is ! set to ' ', then a new list is created. Returns zero for success, -1 for failure. This function can be used to create a quickfix list --- 6666,6698 ---- Note that the list is not exactly the same as what |getqflist()| returns. + *E927* If {action} is set to 'a', then the items from {list} are added to the existing quickfix list. If there is no existing ! list, then a new list is created. ! ! If {action} is set to 'r', then the items from the current ! quickfix list are replaced with the items from {list}. This ! can also be used to clear the list: > ! :call setqflist([], 'r') ! < ! If {action} is not present or is set to ' ', then a new list ! is created. ! ! If the optional {what} dictionary argument is supplied, then ! only the items listed in {what} are set. The first {list} ! argument is ignored. The following items can be specified in ! {what}: ! nr list number in the quickfix stack ! title quickfix list title text ! Unsupported keys in {what} are ignored. ! If the "nr" item is not present, then the current quickfix list ! is modified. + Examples: > + :call setqflist([], 'r', {'title': 'My search'}) + :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) + < Returns zero for success, -1 for failure. This function can be used to create a quickfix list *** ../vim-7.4.2199/src/evalfunc.c 2016-08-07 18:22:30.422091081 +0200 --- src/evalfunc.c 2016-08-12 16:02:26.725465757 +0200 *************** *** 171,176 **** --- 171,177 ---- static void f_getftime(typval_T *argvars, typval_T *rettv); static void f_getftype(typval_T *argvars, typval_T *rettv); static void f_getline(typval_T *argvars, typval_T *rettv); + static void f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED); static void f_getmatches(typval_T *argvars, typval_T *rettv); static void f_getpid(typval_T *argvars, typval_T *rettv); static void f_getcurpos(typval_T *argvars, typval_T *rettv); *************** *** 591,601 **** {"getftime", 1, 1, f_getftime}, {"getftype", 1, 1, f_getftype}, {"getline", 1, 2, f_getline}, ! {"getloclist", 1, 1, f_getqflist}, {"getmatches", 0, 0, f_getmatches}, {"getpid", 0, 0, f_getpid}, {"getpos", 1, 1, f_getpos}, ! {"getqflist", 0, 0, f_getqflist}, {"getreg", 0, 3, f_getreg}, {"getregtype", 0, 1, f_getregtype}, {"gettabvar", 2, 3, f_gettabvar}, --- 592,602 ---- {"getftime", 1, 1, f_getftime}, {"getftype", 1, 1, f_getftype}, {"getline", 1, 2, f_getline}, ! {"getloclist", 1, 2, f_getloclist}, {"getmatches", 0, 0, f_getmatches}, {"getpid", 0, 0, f_getpid}, {"getpos", 1, 1, f_getpos}, ! {"getqflist", 0, 1, f_getqflist}, {"getreg", 0, 3, f_getreg}, {"getregtype", 0, 1, f_getregtype}, {"gettabvar", 2, 3, f_gettabvar}, *************** *** 741,750 **** {"setcmdpos", 1, 1, f_setcmdpos}, {"setfperm", 2, 2, f_setfperm}, {"setline", 2, 2, f_setline}, ! {"setloclist", 2, 3, f_setloclist}, {"setmatches", 1, 1, f_setmatches}, {"setpos", 2, 2, f_setpos}, ! {"setqflist", 1, 2, f_setqflist}, {"setreg", 2, 3, f_setreg}, {"settabvar", 3, 3, f_settabvar}, {"settabwinvar", 4, 4, f_settabwinvar}, --- 742,751 ---- {"setcmdpos", 1, 1, f_setcmdpos}, {"setfperm", 2, 2, f_setfperm}, {"setline", 2, 2, f_setline}, ! {"setloclist", 2, 4, f_setloclist}, {"setmatches", 1, 1, f_setmatches}, {"setpos", 2, 2, f_setpos}, ! {"setqflist", 1, 3, f_setqflist}, {"setreg", 2, 3, f_setreg}, {"settabvar", 3, 3, f_settabvar}, {"settabwinvar", 4, 4, f_settabwinvar}, *************** *** 4529,4534 **** --- 4530,4580 ---- get_buffer_lines(curbuf, lnum, end, retlist, rettv); } + static void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv); + + static void + get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv) + { + #ifdef FEAT_QUICKFIX + if (what_arg->v_type == VAR_UNKNOWN) + { + if (rettv_list_alloc(rettv) == OK) + if (is_qf || wp != NULL) + (void)get_errorlist(wp, -1, rettv->vval.v_list); + } + else + { + if (rettv_dict_alloc(rettv) == OK) + if (is_qf || (wp != NULL)) + { + if (what_arg->v_type == VAR_DICT) + { + dict_T *d = what_arg->vval.v_dict; + + if (d != NULL) + get_errorlist_properties(wp, d, rettv->vval.v_dict); + } + else + EMSG(_(e_dictreq)); + } + } + #endif + } + + /* + * "getloclist()" function + */ + static void + f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + #ifdef FEAT_QUICKFIX + win_T *wp; + + wp = find_win_by_nr(&argvars[0], NULL); + get_qf_loc_list(FALSE, wp, &argvars[1], rettv); + #endif + } + /* * "getmatches()" function */ *************** *** 4666,4693 **** } /* ! * "getqflist()" and "getloclist()" functions */ static void f_getqflist(typval_T *argvars UNUSED, typval_T *rettv UNUSED) { #ifdef FEAT_QUICKFIX ! win_T *wp; ! #endif ! ! #ifdef FEAT_QUICKFIX ! if (rettv_list_alloc(rettv) == OK) ! { ! wp = NULL; ! if (argvars[0].v_type != VAR_UNKNOWN) /* getloclist() */ ! { ! wp = find_win_by_nr(&argvars[0], NULL); ! if (wp == NULL) ! return; ! } ! ! (void)get_errorlist(wp, rettv->vval.v_list); ! } #endif } --- 4712,4724 ---- } /* ! * "getqflist()" function */ static void f_getqflist(typval_T *argvars UNUSED, typval_T *rettv UNUSED) { #ifdef FEAT_QUICKFIX ! get_qf_loc_list(TRUE, NULL, &argvars[0], rettv); #endif } *************** *** 9525,9531 **** appended_lines_mark(lcount, added); } ! static void set_qf_ll_list(win_T *wp, typval_T *list_arg, typval_T *action_arg, typval_T *rettv); /* * Used by "setqflist()" and "setloclist()" functions --- 9556,9562 ---- appended_lines_mark(lcount, added); } ! static void set_qf_ll_list(win_T *wp, typval_T *list_arg, typval_T *action_arg, typval_T *what_arg, typval_T *rettv); /* * Used by "setqflist()" and "setloclist()" functions *************** *** 9535,9540 **** --- 9566,9572 ---- win_T *wp UNUSED, typval_T *list_arg UNUSED, typval_T *action_arg UNUSED, + typval_T *what_arg UNUSED, typval_T *rettv) { #ifdef FEAT_QUICKFIX *************** *** 9551,9556 **** --- 9583,9590 ---- else { list_T *l = list_arg->vval.v_list; + dict_T *d = NULL; + int valid_dict = TRUE; if (action_arg->v_type == VAR_STRING) { *************** *** 9567,9574 **** else EMSG(_(e_stringreq)); ! if (l != NULL && action && set_errorlist(wp, l, action, ! (char_u *)(wp == NULL ? "setqflist()" : "setloclist()")) == OK) rettv->vval.v_number = 0; } #endif --- 9601,9620 ---- else EMSG(_(e_stringreq)); ! if (action_arg->v_type != VAR_UNKNOWN ! && what_arg->v_type != VAR_UNKNOWN) ! { ! if (what_arg->v_type == VAR_DICT) ! d = what_arg->vval.v_dict; ! else ! { ! EMSG(_(e_dictreq)); ! valid_dict = FALSE; ! } ! } ! ! if (l != NULL && action && valid_dict && set_errorlist(wp, l, action, ! (char_u *)(wp == NULL ? "setqflist()" : "setloclist()"), d) == OK) rettv->vval.v_number = 0; } #endif *************** *** 9586,9592 **** win = find_win_by_nr(&argvars[0], NULL); if (win != NULL) ! set_qf_ll_list(win, &argvars[1], &argvars[2], rettv); } /* --- 9632,9638 ---- win = find_win_by_nr(&argvars[0], NULL); if (win != NULL) ! set_qf_ll_list(win, &argvars[1], &argvars[2], &argvars[3], rettv); } /* *************** *** 9754,9760 **** static void f_setqflist(typval_T *argvars, typval_T *rettv) { ! set_qf_ll_list(NULL, &argvars[0], &argvars[1], rettv); } /* --- 9800,9806 ---- static void f_setqflist(typval_T *argvars, typval_T *rettv) { ! set_qf_ll_list(NULL, &argvars[0], &argvars[1], &argvars[2], rettv); } /* *** ../vim-7.4.2199/src/proto/quickfix.pro 2016-07-16 16:54:18.334699590 +0200 --- src/proto/quickfix.pro 2016-08-12 15:53:00.930579986 +0200 *************** *** 27,34 **** void ex_cfile(exarg_T *eap); void ex_vimgrep(exarg_T *eap); char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags); ! int get_errorlist(win_T *wp, list_T *list); ! int set_errorlist(win_T *wp, list_T *list, int action, char_u *title); void ex_cbuffer(exarg_T *eap); void ex_cexpr(exarg_T *eap); void ex_helpgrep(exarg_T *eap); --- 27,35 ---- void ex_cfile(exarg_T *eap); void ex_vimgrep(exarg_T *eap); char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags); ! int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict); ! int get_errorlist(win_T *wp, int qf_idx, list_T *list); ! int set_errorlist(win_T *wp, list_T *list, int action, char_u *title, dict_T *what); void ex_cbuffer(exarg_T *eap); void ex_cexpr(exarg_T *eap); void ex_helpgrep(exarg_T *eap); *** ../vim-7.4.2199/src/quickfix.c 2016-08-02 21:41:18.544944546 +0200 --- src/quickfix.c 2016-08-12 16:04:54.936128326 +0200 *************** *** 3141,3146 **** --- 3141,3164 ---- } /* + * Update the w:quickfix_title variable in the quickfix/location list window + */ + static void + qf_update_win_titlevar(qf_info_T *qi) + { + win_T *win; + win_T *curwin_save; + + if ((win = qf_find_win(qi)) != NULL) + { + curwin_save = curwin; + curwin = win; + qf_set_title_var(qi); + curwin = curwin_save; + } + } + + /* * Find the quickfix buffer. If it exists, update the contents. */ static void *************** *** 3148,3154 **** { buf_T *buf; win_T *win; - win_T *curwin_save; aco_save_T aco; /* Check if a buffer for the quickfix list exists. Update it. */ --- 3166,3171 ---- *************** *** 3161,3173 **** /* set curwin/curbuf to buf and save a few things */ aucmd_prepbuf(&aco, buf); ! if ((win = qf_find_win(qi)) != NULL) ! { ! curwin_save = curwin; ! curwin = win; ! qf_set_title_var(qi); ! curwin = curwin_save; ! } qf_fill_buffer(qi, buf, old_last); --- 3178,3184 ---- /* set curwin/curbuf to buf and save a few things */ aucmd_prepbuf(&aco, buf); ! qf_update_win_titlevar(qi); qf_fill_buffer(qi, buf, old_last); *************** *** 4532,4540 **** #if defined(FEAT_EVAL) || defined(PROTO) /* * Add each quickfix error to list "list" as a dictionary. */ int ! get_errorlist(win_T *wp, list_T *list) { qf_info_T *qi = &ql_info; dict_T *dict; --- 4543,4552 ---- #if defined(FEAT_EVAL) || defined(PROTO) /* * Add each quickfix error to list "list" as a dictionary. + * If qf_idx is -1, use the current list. Otherwise, use the specified list. */ int ! get_errorlist(win_T *wp, int qf_idx, list_T *list) { qf_info_T *qi = &ql_info; dict_T *dict; *************** *** 4550,4561 **** return FAIL; } ! if (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) { /* Handle entries with a non-existing buffer number. */ bufnum = qfp->qf_fnum; --- 4562,4576 ---- return FAIL; } ! if (qf_idx == -1) ! qf_idx = qi->qf_curlist; ! ! if (qf_idx >= qi->qf_listcount ! || qi->qf_lists[qf_idx].qf_count == 0) return FAIL; ! qfp = qi->qf_lists[qf_idx].qf_start; ! for (i = 1; !got_int && i <= qi->qf_lists[qf_idx].qf_count; ++i) { /* Handle entries with a non-existing buffer number. */ bufnum = qfp->qf_fnum; *************** *** 4590,4605 **** } /* ! * Populate the quickfix list with the items supplied in the list ! * of dictionaries. "title" will be copied to w:quickfix_title. ! * "action" is 'a' for add, 'r' for replace. Otherwise create a new list. */ int ! set_errorlist( ! win_T *wp, ! list_T *list, ! int action, ! char_u *title) { listitem_T *li; dict_T *d; --- 4605,4697 ---- } /* ! * Flags used by getqflist()/getloclist() to determine which fields to return. ! */ ! enum { ! QF_GETLIST_NONE = 0x0, ! QF_GETLIST_TITLE = 0x1, ! QF_GETLIST_ITEMS = 0x2, ! QF_GETLIST_NR = 0x4, ! QF_GETLIST_WINID = 0x8, ! QF_GETLIST_ALL = 0xFF ! }; ! ! /* ! * Return quickfix/location list details (title) as a ! * dictionary. 'what' contains the details to return. If 'list_idx' is -1, ! * then current list is used. Otherwise the specified list is used. */ int ! get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) ! { ! qf_info_T *qi = &ql_info; ! int status = OK; ! int qf_idx; ! dictitem_T *di; ! int flags = QF_GETLIST_NONE; ! ! if (wp != NULL) ! { ! qi = GET_LOC_LIST(wp); ! if (qi == NULL) ! return FAIL; ! } ! ! qf_idx = qi->qf_curlist; /* default is the current list */ ! if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) ! { ! /* Use the specified quickfix/location list */ ! if (di->di_tv.v_type == VAR_NUMBER) ! { ! qf_idx = di->di_tv.vval.v_number - 1; ! if (qf_idx < 0 || qf_idx >= qi->qf_listcount) ! return FAIL; ! flags |= QF_GETLIST_NR; ! } ! else ! return FAIL; ! } ! ! if (dict_find(what, (char_u *)"all", -1) != NULL) ! flags |= QF_GETLIST_ALL; ! ! if (dict_find(what, (char_u *)"title", -1) != NULL) ! flags |= QF_GETLIST_TITLE; ! ! if (dict_find(what, (char_u *)"winid", -1) != NULL) ! flags |= QF_GETLIST_WINID; ! ! if (flags & QF_GETLIST_TITLE) ! { ! char_u *t; ! t = qi->qf_lists[qf_idx].qf_title; ! if (t == NULL) ! t = (char_u *)""; ! status = dict_add_nr_str(retdict, "title", 0L, t); ! } ! if ((status == OK) && (flags & QF_GETLIST_NR)) ! status = dict_add_nr_str(retdict, "nr", qf_idx + 1, NULL); ! if ((status == OK) && (flags & QF_GETLIST_WINID)) ! { ! win_T *win; ! win = qf_find_win(qi); ! if (win != NULL) ! status = dict_add_nr_str(retdict, "winid", win->w_id, NULL); ! } ! ! return status; ! } ! ! /* ! * Add list of entries to quickfix/location list. Each list entry is ! * a dictionary with item information. ! */ ! static int ! qf_add_entries( ! qf_info_T *qi, ! list_T *list, ! char_u *title, ! int action) { listitem_T *li; dict_T *d; *************** *** 4613,4628 **** #endif int valid, status; int retval = OK; - qf_info_T *qi = &ql_info; int did_bufnr_emsg = FALSE; - if (wp != NULL) - { - qi = ll_get_or_alloc_list(wp); - if (qi == NULL) - return FAIL; - } - if (action == ' ' || qi->qf_curlist == qi->qf_listcount) /* make place for a new list */ qf_new_list(qi, title); --- 4705,4712 ---- *************** *** 4719,4724 **** --- 4803,4876 ---- return retval; } + + static int + qf_set_properties(qf_info_T *qi, dict_T *what) + { + dictitem_T *di; + int retval = FAIL; + int qf_idx; + + qf_idx = qi->qf_curlist; /* default is the current list */ + if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) + { + /* Use the specified quickfix/location list */ + if (di->di_tv.v_type == VAR_NUMBER) + { + qf_idx = di->di_tv.vval.v_number - 1; + if (qf_idx < 0 || qf_idx >= qi->qf_listcount) + return FAIL; + } + else + return FAIL; + } + + if ((di = dict_find(what, (char_u *)"title", -1)) != NULL) + { + if (di->di_tv.v_type == VAR_STRING) + { + vim_free(qi->qf_lists[qf_idx].qf_title); + qi->qf_lists[qf_idx].qf_title = + get_dict_string(what, (char_u *)"title", TRUE); + if (qf_idx == qi->qf_curlist) + qf_update_win_titlevar(qi); + retval = OK; + } + } + + return retval; + } + + /* + * Populate the quickfix list with the items supplied in the list + * of dictionaries. "title" will be copied to w:quickfix_title. + * "action" is 'a' for add, 'r' for replace. Otherwise create a new list. + */ + int + set_errorlist( + win_T *wp, + list_T *list, + int action, + char_u *title, + dict_T *what) + { + qf_info_T *qi = &ql_info; + int retval = OK; + + if (wp != NULL) + { + qi = ll_get_or_alloc_list(wp); + if (qi == NULL) + return FAIL; + } + + if (what != NULL) + retval = qf_set_properties(qi, what); + else + retval = qf_add_entries(qi, list, title, action); + + return retval; + } #endif /* *** ../vim-7.4.2199/src/tag.c 2016-07-01 17:17:13.298266645 +0200 --- src/tag.c 2016-08-12 15:53:00.930579986 +0200 *************** *** 916,922 **** } vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); ! set_errorlist(curwin, list, ' ', IObuff); list_free(list); vim_free(fname); --- 916,922 ---- } vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); ! set_errorlist(curwin, list, ' ', IObuff, NULL); list_free(list); vim_free(fname); *** ../vim-7.4.2199/src/testdir/test_quickfix.vim 2016-08-03 21:04:47.858847794 +0200 --- src/testdir/test_quickfix.vim 2016-08-12 15:53:00.930579986 +0200 *************** *** 1505,1507 **** --- 1505,1546 ---- call delete('Xgrepthis') endfunc + + " Quickfix/Location list set/get properties tests + function Xproperty_tests(cchar) + call s:setup_commands(a:cchar) + + " Error cases + call assert_fails('call g:Xgetlist(99)', 'E715:') + call assert_fails('call g:Xsetlist(99)', 'E714:') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') + + " Set and get the title + Xopen + wincmd p + call g:Xsetlist([{'filename':'foo', 'lnum':27}]) + call g:Xsetlist([], 'a', {'title' : 'Sample'}) + let d = g:Xgetlist({"title":1}) + call assert_equal('Sample', d.title) + + Xopen + call assert_equal('Sample', w:quickfix_title) + Xclose + + " Invalid arguments + call assert_fails('call g:Xgetlist([])', 'E715') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715') + let s = g:Xsetlist([], 'a', {'abc':1}) + call assert_equal(-1, s) + + call assert_equal({}, g:Xgetlist({'abc':1})) + + if a:cchar == 'l' + call assert_equal({}, getloclist(99, ['title'])) + endif + endfunction + + function Test_qf_property() + call Xproperty_tests('c') + call Xproperty_tests('l') + endfunction *** ../vim-7.4.2199/src/version.c 2016-08-12 14:08:20.682029419 +0200 --- src/version.c 2016-08-12 16:05:36.691751689 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2200, /**/ -- hundred-and-one symptoms of being an internet addict: 10. And even your night dreams are in HTML. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///