0
0
mirror of https://github.com/vim/vim.git synced 2025-09-10 22:33:40 -04:00

patch 8.0.1093: various small quickfix issues

Problem:    Various small quickfix issues.
Solution:   Remove ":" prefix from title set by a user. Add the qf_id2nr().
            function. Add a couple more tests.  Update documentation.
            (Yegappan Lakshmanan)
This commit is contained in:
Bram Moolenaar 2017-09-11 19:31:28 +02:00
parent 45d5f26d11
commit b4d5fbabc9
7 changed files with 90 additions and 32 deletions

View File

@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.0. Last change: 2017 Aug 13 *eval.txt* For Vim version 8.0. Last change: 2017 Sep 11
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -1449,7 +1449,7 @@ v:beval_text The text under or after the mouse pointer. Usually a word as
but a dot and "->" before the position is included. When on a but a dot and "->" before the position is included. When on a
']' the text before it is used, including the matching '[' and ']' the text before it is used, including the matching '[' and
word before it. When on a Visual area within one line the word before it. When on a Visual area within one line the
highlighted text is used. highlighted text is used. Also see |<cexpr>|.
Only valid while evaluating the 'balloonexpr' option. Only valid while evaluating the 'balloonexpr' option.
*v:beval_winnr* *beval_winnr-variable* *v:beval_winnr* *beval_winnr-variable*
@ -3301,7 +3301,7 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()*
When {ic} is given and it's |TRUE| then case is ignored. When {ic} is given and it's |TRUE| then case is ignored.
When {comp} is a string then the number of not overlapping When {comp} is a string then the number of not overlapping
occurences of {expr} is returned. occurrences of {expr} is returned.
*cscope_connection()* *cscope_connection()*
@ -3467,7 +3467,7 @@ escape({string}, {chars}) *escape()*
:echo escape('c:\program files\vim', ' \') :echo escape('c:\program files\vim', ' \')
< results in: > < results in: >
c:\\program\ files\\vim c:\\program\ files\\vim
< Also see |shellescape()|. < Also see |shellescape()| and |fnameescape()|.
*eval()* *eval()*
eval({string}) Evaluate {string} and return the result. Especially useful to eval({string}) Evaluate {string} and return the result. Especially useful to
@ -3887,7 +3887,7 @@ float2nr({expr}) *float2nr()*
When the value of {expr} is out of range for a |Number| the When the value of {expr} is out of range for a |Number| the
result is truncated to 0x7fffffff or -0x7fffffff (or when result is truncated to 0x7fffffff or -0x7fffffff (or when
64-bit Number support is enabled, 0x7fffffffffffffff or 64-bit Number support is enabled, 0x7fffffffffffffff or
-0x7fffffffffffffff. NaN results in -0x80000000 (or when -0x7fffffffffffffff). NaN results in -0x80000000 (or when
64-bit Number support is enabled, -0x8000000000000000). 64-bit Number support is enabled, -0x8000000000000000).
Examples: > Examples: >
echo float2nr(3.95) echo float2nr(3.95)
@ -4657,12 +4657,12 @@ getqflist([{what}]) *getqflist()*
If "nr" is not present then the current quickfix list is used. If "nr" is not present then the current quickfix list is used.
If both "nr" and a non-zero "id" are specified, then the list If both "nr" and a non-zero "id" are specified, then the list
specified by "id" is used. specified by "id" is used.
To get the number of lists in the quickfix stack, set 'nr' to To get the number of lists in the quickfix stack, set "nr" to
'$' in {what}. The 'nr' value in the returned dictionary "$" in {what}. The "nr" value in the returned dictionary
contains the quickfix stack size. contains the quickfix stack size.
When 'text' is specified, all the other items are ignored. The When "lines" is specified, all the other items except "efm"
returned dictionary contains the entry 'items' with the list are ignored. The returned dictionary contains the entry
of entries. "items" with the list of entries.
In case of error processing {what}, an empty dictionary is In case of error processing {what}, an empty dictionary is
returned. returned.
@ -6967,6 +6967,7 @@ setline({lnum}, {text}) *setline()*
:for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
: call setline(n, l) : call setline(n, l)
:endfor :endfor
< Note: The '[ and '] marks are not set. < Note: The '[ and '] marks are not set.
setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()* setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()*
@ -7164,16 +7165,17 @@ setreg({regname}, {value} [, {options}])
:call setreg('a', "1\n2\n3", 'b5') :call setreg('a', "1\n2\n3", 'b5')
< This example shows using the functions to save and restore a < This example shows using the functions to save and restore a
register (note: you may not reliably restore register value register: >
without using the third argument to |getreg()| as without it
newlines are represented as newlines AND Nul bytes are
represented as newlines as well, see |NL-used-for-Nul|). >
:let var_a = getreg('a', 1, 1) :let var_a = getreg('a', 1, 1)
:let var_amode = getregtype('a') :let var_amode = getregtype('a')
.... ....
:call setreg('a', var_a, var_amode) :call setreg('a', var_a, var_amode)
< Note: you may not reliably restore register value
without using the third argument to |getreg()| as without it
newlines are represented as newlines AND Nul bytes are
represented as newlines as well, see |NL-used-for-Nul|.
< You can also change the type of a register by appending You can also change the type of a register by appending
nothing: > nothing: >
:call setreg('a', '', 'al') :call setreg('a', '', 'al')
@ -8145,7 +8147,7 @@ term_start({cmd}, {options}) *term_start()*
are supported: are supported:
all timeout options all timeout options
"stoponexit" "stoponexit"
"out_cb", "err_cb" "callback", "out_cb", "err_cb"
"exit_cb", "close_cb" "exit_cb", "close_cb"
"in_io", "in_top", "in_bot", "in_name", "in_buf" "in_io", "in_top", "in_bot", "in_name", "in_buf"
"out_io", "out_name", "out_buf", "out_modifiable", "out_msg" "out_io", "out_name", "out_buf", "out_modifiable", "out_msg"
@ -8165,6 +8167,7 @@ term_start({cmd}, {options}) *term_start()*
"curwin" use the current window, do not split the "curwin" use the current window, do not split the
window; fails if the current buffer window; fails if the current buffer
cannot be |abandon|ed cannot be |abandon|ed
"hidden" do not open a window
"term_finish" What to do when the job is finished: "term_finish" What to do when the job is finished:
"close": close any windows "close": close any windows
"open": open window if needed "open": open window if needed
@ -8562,7 +8565,7 @@ win_getid([{win} [, {tab}]]) *win_getid()*
Get the |window-ID| for the specified window. Get the |window-ID| for the specified window.
When {win} is missing use the current window. When {win} is missing use the current window.
With {win} this is the window number. The top window has With {win} this is the window number. The top window has
number 1. number 1. Use `win_getid(winnr())` for the current window.
Without {tab} use the current tab, otherwise the tab with Without {tab} use the current tab, otherwise the tab with
number {tab}. The first tab has number one. number {tab}. The first tab has number one.
Return zero if the window cannot be found. Return zero if the window cannot be found.

View File

@ -44,6 +44,18 @@ From inside Vim an easy way to run a command and handle the output is with the
The 'errorformat' option should be set to match the error messages from your The 'errorformat' option should be set to match the error messages from your
compiler (see |errorformat| below). compiler (see |errorformat| below).
*quickfix-ID*
Each quickfix list has a unique identifier called the quickfix ID and this
number will not change within a Vim session. The getqflist() function can be
used to get the identifier assigned to a list.
*quickfix-ID*
Each quickfix list has a unique identifier called the quickfix ID and this
number will not change within a Vim session. The getqflist() function can be
used to get the identifier assigned to a list. There is also a quickfix list
number which may change whenever more than ten lists are added to a quickfix
stack.
*location-list* *E776* *location-list* *E776*
A location list is a window-local quickfix list. You get one after commands A location list is a window-local quickfix list. You get one after commands
like `:lvimgrep`, `:lgrep`, `:lhelpgrep`, `:lmake`, etc., which create a like `:lvimgrep`, `:lgrep`, `:lhelpgrep`, `:lmake`, etc., which create a

View File

@ -4826,7 +4826,7 @@ get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv)
dict_T *d = what_arg->vval.v_dict; dict_T *d = what_arg->vval.v_dict;
if (d != NULL) if (d != NULL)
get_errorlist_properties(wp, d, rettv->vval.v_dict); qf_get_properties(wp, d, rettv->vval.v_dict);
} }
else else
EMSG(_(e_dictreq)); EMSG(_(e_dictreq));

View File

@ -22,7 +22,7 @@ void ex_cnext(exarg_T *eap);
void ex_cfile(exarg_T *eap); void ex_cfile(exarg_T *eap);
void ex_vimgrep(exarg_T *eap); void ex_vimgrep(exarg_T *eap);
int get_errorlist(qf_info_T *qi, win_T *wp, int qf_idx, list_T *list); int get_errorlist(qf_info_T *qi, win_T *wp, int qf_idx, list_T *list);
int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict); int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict);
int set_errorlist(win_T *wp, list_T *list, int action, char_u *title, dict_T *what); int set_errorlist(win_T *wp, list_T *list, int action, char_u *title, dict_T *what);
int set_ref_in_quickfix(int copyID); int set_ref_in_quickfix(int copyID);
void ex_cbuffer(exarg_T *eap); void ex_cbuffer(exarg_T *eap);

View File

@ -4690,13 +4690,28 @@ qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
return status; return status;
} }
/*
* Return the quickfix/location list number with the given identifier.
* Returns -1 if list is not found.
*/
static int
qf_id2nr(qf_info_T *qi, int_u qfid)
{
int qf_idx;
for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++)
if (qi->qf_lists[qf_idx].qf_id == qfid)
return qf_idx;
return -1;
}
/* /*
* Return quickfix/location list details (title) as a * Return quickfix/location list details (title) as a
* dictionary. 'what' contains the details to return. If 'list_idx' is -1, * dictionary. 'what' contains the details to return. If 'list_idx' is -1,
* then current list is used. Otherwise the specified list is used. * then current list is used. Otherwise the specified list is used.
*/ */
int int
get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
{ {
qf_info_T *qi = &ql_info; qf_info_T *qi = &ql_info;
int status = OK; int status = OK;
@ -4752,12 +4767,8 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
/* For zero, use the current list or the list specifed by 'nr' */ /* For zero, use the current list or the list specifed by 'nr' */
if (di->di_tv.vval.v_number != 0) if (di->di_tv.vval.v_number != 0)
{ {
for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number);
{ if (qf_idx == -1)
if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number)
break;
}
if (qf_idx == qi->qf_listcount)
return FAIL; /* List not found */ return FAIL; /* List not found */
} }
flags |= QF_GETLIST_ID; flags |= QF_GETLIST_ID;
@ -5024,10 +5035,8 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
/* Use the quickfix/location list with the specified id */ /* Use the quickfix/location list with the specified id */
if (di->di_tv.v_type == VAR_NUMBER) if (di->di_tv.v_type == VAR_NUMBER)
{ {
for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number);
if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number) if (qf_idx == -1)
break;
if (qf_idx == qi->qf_listcount)
return FAIL; /* List not found */ return FAIL; /* List not found */
} }
else else
@ -5062,6 +5071,16 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
retval = qf_add_entries(qi, qf_idx, di->di_tv.vval.v_list, retval = qf_add_entries(qi, qf_idx, di->di_tv.vval.v_list,
title_save, action == ' ' ? 'a' : action); title_save, action == ' ' ? 'a' : action);
if (action == 'r')
{
/*
* When replacing the quickfix list entries using
* qf_add_entries(), the title is set with a ':' prefix.
* Restore the title with the saved title.
*/
vim_free(qi->qf_lists[qf_idx].qf_title);
qi->qf_lists[qf_idx].qf_title = vim_strsave(title_save);
}
vim_free(title_save); vim_free(title_save);
} }
} }

View File

@ -487,6 +487,19 @@ func s:test_xhelpgrep(cchar)
" This wipes out the buffer, make sure that doesn't cause trouble. " This wipes out the buffer, make sure that doesn't cause trouble.
Xclose Xclose
if a:cchar == 'l'
" When a help window is present, running :lhelpgrep should reuse the
" help window and not the current window
new | only
call g:Xsetlist([], 'f')
help index.txt
wincmd w
lhelpgrep quickfix
call assert_equal(1, winnr())
call assert_notequal([], getloclist(1))
call assert_equal([], getloclist(2))
endif
new | only new | only
" Search for non existing help string " Search for non existing help string
@ -1684,6 +1697,10 @@ func HistoryTest(cchar)
call assert_equal(' error list 1 of 3; 1 ' . common, res[0]) call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
call assert_equal(' error list 2 of 3; 2 ' . common, res[1]) call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
call assert_equal('> error list 3 of 3; 3 ' . common, res[2]) call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
call g:Xsetlist([], 'f')
let l = split(execute(a:cchar . 'hist'), "\n")
call assert_equal('No entries', l[0])
endfunc endfunc
func Test_history() func Test_history()
@ -1862,6 +1879,11 @@ func Xproperty_tests(cchar)
let l = g:Xgetlist({'items':1}) let l = g:Xgetlist({'items':1})
call assert_equal(0, len(l.items)) call assert_equal(0, len(l.items))
call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
" The following used to crash Vim with address sanitizer " The following used to crash Vim with address sanitizer
call g:Xsetlist([], 'f') call g:Xsetlist([], 'f')
call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
@ -1904,10 +1926,10 @@ func Xproperty_tests(cchar)
call g:Xsetlist([], 'r', l2) call g:Xsetlist([], 'r', l2)
let newl1=g:Xgetlist({'nr':1,'all':1}) let newl1=g:Xgetlist({'nr':1,'all':1})
let newl2=g:Xgetlist({'nr':2,'all':1}) let newl2=g:Xgetlist({'nr':2,'all':1})
call assert_equal(':Fruits', newl1.title) call assert_equal('Fruits', newl1.title)
call assert_equal(['Fruits'], newl1.context) call assert_equal(['Fruits'], newl1.context)
call assert_equal('Line20', newl1.items[0].text) call assert_equal('Line20', newl1.items[0].text)
call assert_equal(':Colors', newl2.title) call assert_equal('Colors', newl2.title)
call assert_equal(['Colors'], newl2.context) call assert_equal(['Colors'], newl2.context)
call assert_equal('Line10', newl2.items[0].text) call assert_equal('Line10', newl2.items[0].text)
call g:Xsetlist([], 'f') call g:Xsetlist([], 'f')

View File

@ -769,6 +769,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1093,
/**/ /**/
1092, 1092,
/**/ /**/