mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch:8.0.0634: cannot easily get to the last quickfix list
Problem:    Cannot easily get to the last quickfix list.
Solution:   Add "$" as a value for the "nr" argument of getqflist() and
            setqflist(). (Yegappan Lakshmanan)
875feea6ce
			
			
This commit is contained in:
		| @@ -4329,12 +4329,16 @@ getqflist([{what}])					*getqflist()* | |||||||
| 		following string items are supported in {what}: | 		following string items are supported in {what}: | ||||||
| 			context	get the context stored with |setqflist()| | 			context	get the context stored with |setqflist()| | ||||||
| 			nr	get information for this quickfix list; zero | 			nr	get information for this quickfix list; zero | ||||||
| 				means the current quickfix list | 				means the current quickfix list and '$' means | ||||||
|  | 				the last quickfix list | ||||||
| 			title	get the list title | 			title	get the list title | ||||||
| 			winid	get the |window-ID| (if opened) | 			winid	get the |window-ID| (if opened) | ||||||
| 			all	all of the above quickfix properties | 			all	all of the above quickfix properties | ||||||
| 		Non-string items in {what} are ignored. | 		Non-string items in {what} are ignored. | ||||||
| 		If "nr" is not present then the current quickfix list is used. | 		If "nr" is not present then the current quickfix list is used. | ||||||
|  | 		To get the number of lists in the quickfix stack, set 'nr' to | ||||||
|  | 		'$' in {what}. The 'nr' value in the returned dictionary | ||||||
|  | 		contains the quickfix stack size. | ||||||
| 		In case of error processing {what}, an empty dictionary is | 		In case of error processing {what}, an empty dictionary is | ||||||
| 		returned. | 		returned. | ||||||
|  |  | ||||||
| @@ -6888,7 +6892,9 @@ setqflist({list} [, {action}[, {what}]])		*setqflist()* | |||||||
| 		argument is ignored.  The following items can be specified in | 		argument is ignored.  The following items can be specified in | ||||||
| 		{what}: | 		{what}: | ||||||
| 		    context	any Vim type can be stored as a context | 		    context	any Vim type can be stored as a context | ||||||
| 		    nr		list number in the quickfix stack | 		    nr		list number in the quickfix stack; zero | ||||||
|  | 				means the current quickfix list and '$' means | ||||||
|  | 				the last quickfix list | ||||||
| 		    title	quickfix list title text | 		    title	quickfix list title text | ||||||
| 		Unsupported keys in {what} are ignored. | 		Unsupported keys in {what} are ignored. | ||||||
| 		If the "nr" item is not present, then the current quickfix list | 		If the "nr" item is not present, then the current quickfix list | ||||||
| @@ -6993,18 +6999,22 @@ shellescape({string} [, {special}])			*shellescape()* | |||||||
| 		quotes within {string}. | 		quotes within {string}. | ||||||
| 		Otherwise, it will enclose {string} in single quotes and | 		Otherwise, it will enclose {string} in single quotes and | ||||||
| 		replace all "'" with "'\''". | 		replace all "'" with "'\''". | ||||||
|  |  | ||||||
| 		When the {special} argument is present and it's a non-zero | 		When the {special} argument is present and it's a non-zero | ||||||
| 		Number or a non-empty String (|non-zero-arg|), then special | 		Number or a non-empty String (|non-zero-arg|), then special | ||||||
| 		items such as "!", "%", "#" and "<cword>" will be preceded by | 		items such as "!", "%", "#" and "<cword>" will be preceded by | ||||||
| 		a backslash.  This backslash will be removed again by the |:!| | 		a backslash.  This backslash will be removed again by the |:!| | ||||||
| 		command. | 		command. | ||||||
|  |  | ||||||
| 		The "!" character will be escaped (again with a |non-zero-arg| | 		The "!" character will be escaped (again with a |non-zero-arg| | ||||||
| 		{special}) when 'shell' contains "csh" in the tail.  That is | 		{special}) when 'shell' contains "csh" in the tail.  That is | ||||||
| 		because for csh and tcsh "!" is used for history replacement | 		because for csh and tcsh "!" is used for history replacement | ||||||
| 		even when inside single quotes. | 		even when inside single quotes. | ||||||
| 		The <NL> character is also escaped.  With a |non-zero-arg| |  | ||||||
| 		{special} and 'shell' containing "csh" in the tail it's | 		With a |non-zero-arg| {special} the <NL> character is also | ||||||
|  | 		escaped.  When 'shell' containing "csh" in the tail it's | ||||||
| 		escaped a second time. | 		escaped a second time. | ||||||
|  |  | ||||||
| 		Example of use with a |:!| command: > | 		Example of use with a |:!| command: > | ||||||
| 		    :exe '!dir ' . shellescape(expand('<cfile>'), 1) | 		    :exe '!dir ' . shellescape(expand('<cfile>'), 1) | ||||||
| <		This results in a directory listing for the file under the | <		This results in a directory listing for the file under the | ||||||
|   | |||||||
| @@ -4088,16 +4088,22 @@ enum { | |||||||
| int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) | int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) | ||||||
| { | { | ||||||
|   qf_info_T *qi = &ql_info; |   qf_info_T *qi = &ql_info; | ||||||
|  |   dictitem_T *di; | ||||||
|  |  | ||||||
|   if (wp != NULL) { |   if (wp != NULL) { | ||||||
|     qi = GET_LOC_LIST(wp); |     qi = GET_LOC_LIST(wp); | ||||||
|     if (qi == NULL) { |     if (qi == NULL) { | ||||||
|  |       // If querying for the size of the location list, return 0 | ||||||
|  |       if (((di = tv_dict_find(what, S_LEN("nr"))) != NULL) | ||||||
|  |           && (di->di_tv.v_type == VAR_STRING) | ||||||
|  |           && strequal((const char *)di->di_tv.vval.v_string, "$")) { | ||||||
|  |         return tv_dict_add_nr(retdict, S_LEN("nr"), 0); | ||||||
|  |       } | ||||||
|       return FAIL; |       return FAIL; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   int status = OK; |   int status = OK; | ||||||
|   dictitem_T *di; |  | ||||||
|   int flags = QF_GETLIST_NONE; |   int flags = QF_GETLIST_NONE; | ||||||
|  |  | ||||||
|   int qf_idx = qi->qf_curlist;  // default is the current list |   int qf_idx = qi->qf_curlist;  // default is the current list | ||||||
| @@ -4110,6 +4116,17 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) | |||||||
|         if (qf_idx < 0 || qf_idx >= qi->qf_listcount) { |         if (qf_idx < 0 || qf_idx >= qi->qf_listcount) { | ||||||
|           return FAIL; |           return FAIL; | ||||||
|         } |         } | ||||||
|  |       } else if (qi->qf_listcount == 0) {  // stack is empty | ||||||
|  |         return FAIL; | ||||||
|  |       } | ||||||
|  |       flags |= QF_GETLIST_NR; | ||||||
|  |     } else if (di->di_tv.v_type == VAR_STRING | ||||||
|  |                && strequal((const char *)di->di_tv.vval.v_string, "$")) { | ||||||
|  |       // Get the last quickfix list number | ||||||
|  |       if (qi->qf_listcount > 0) { | ||||||
|  |         qf_idx = qi->qf_listcount - 1; | ||||||
|  |       } else { | ||||||
|  |         qf_idx = -1;  // Quickfix stack is empty | ||||||
|       } |       } | ||||||
|       flags |= QF_GETLIST_NR; |       flags |= QF_GETLIST_NR; | ||||||
|     } else { |     } else { | ||||||
| @@ -4117,6 +4134,7 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (qf_idx != -1) { | ||||||
|     if (tv_dict_find(what, S_LEN("all")) != NULL) { |     if (tv_dict_find(what, S_LEN("all")) != NULL) { | ||||||
|       flags |= QF_GETLIST_ALL; |       flags |= QF_GETLIST_ALL; | ||||||
|     } |     } | ||||||
| @@ -4132,6 +4150,7 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) | |||||||
|     if (tv_dict_find(what, S_LEN("context")) != NULL) { |     if (tv_dict_find(what, S_LEN("context")) != NULL) { | ||||||
|       flags |= QF_GETLIST_CONTEXT; |       flags |= QF_GETLIST_CONTEXT; | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   if (flags & QF_GETLIST_TITLE) { |   if (flags & QF_GETLIST_TITLE) { | ||||||
|     char_u *t = qi->qf_lists[qf_idx].qf_title; |     char_u *t = qi->qf_lists[qf_idx].qf_title; | ||||||
| @@ -4296,6 +4315,10 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action) | |||||||
|       if (qf_idx < 0 || qf_idx >= qi->qf_listcount) { |       if (qf_idx < 0 || qf_idx >= qi->qf_listcount) { | ||||||
|         return FAIL; |         return FAIL; | ||||||
|       } |       } | ||||||
|  |     } else if (di->di_tv.v_type == VAR_STRING | ||||||
|  |                && strequal((const char *)di->di_tv.vval.v_string, "$") | ||||||
|  |                && qi->qf_listcount > 0) { | ||||||
|  |       qf_idx = qi->qf_listcount - 1; | ||||||
|     } else { |     } else { | ||||||
|       return FAIL; |       return FAIL; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2102,3 +2102,43 @@ func Test_bufoverflow() | |||||||
|   set efm&vim |   set efm&vim | ||||||
| endfunc | endfunc | ||||||
|  |  | ||||||
|  | func Test_cclose_from_copen() | ||||||
|  |     augroup QF_Test | ||||||
|  | 	au! | ||||||
|  | 	au FileType qf :cclose | ||||||
|  |     augroup END | ||||||
|  |     copen | ||||||
|  |     augroup QF_Test | ||||||
|  | 	au! | ||||||
|  |     augroup END | ||||||
|  |     augroup! QF_Test | ||||||
|  | endfunc | ||||||
|  |  | ||||||
|  | " Tests for getting the quickfix stack size | ||||||
|  | func XsizeTests(cchar) | ||||||
|  |   call s:setup_commands(a:cchar) | ||||||
|  |  | ||||||
|  |   call g:Xsetlist([], 'f') | ||||||
|  |   call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) | ||||||
|  |   call assert_equal(1, len(g:Xgetlist({'nr':'$', 'all':1}))) | ||||||
|  |   call assert_equal(0, len(g:Xgetlist({'nr':0}))) | ||||||
|  |  | ||||||
|  |   Xexpr "File1:10:Line1" | ||||||
|  |   Xexpr "File2:20:Line2" | ||||||
|  |   Xexpr "File3:30:Line3" | ||||||
|  |   Xolder | Xolder | ||||||
|  |   call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) | ||||||
|  |   call g:Xsetlist([], 'f') | ||||||
|  |  | ||||||
|  |   Xexpr "File1:10:Line1" | ||||||
|  |   Xexpr "File2:20:Line2" | ||||||
|  |   Xexpr "File3:30:Line3" | ||||||
|  |   Xolder | Xolder | ||||||
|  |   call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'}) | ||||||
|  |   call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title) | ||||||
|  | endfunc | ||||||
|  |  | ||||||
|  | func Test_Qf_Size() | ||||||
|  |   call XsizeTests('c') | ||||||
|  |   call XsizeTests('l') | ||||||
|  | endfunc | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 James McCoy
					James McCoy