Hi Bram,
On Sun, Aug 27, 2017 at 6:23 AM, Bram Moolenaar <[email protected]> wrote:
>
> Yegappan Lakshmanan wrote:
>
>> Currently all the available quickfix commands and functions that parse
>> text using 'erroformat' add the resulting entries to a quickfix list in the
>> stack. There have been several requests in the past to add support for
>> parsing text using 'erroformat' without modifying the quickfix lists in
>> the stack. This is useful for Vim plugins that deal with quickfix lists.
>> I am attaching a patch to add this feature.
>>
>> To parse text without modifying the quickfix lists, the getqflist() function
>> can be used as shown below:
>>
>> echo getqflist({'text': "File10:10:Line10\nFile20:20:Line20"})
>> or
>> echo getqflist({'text': ["File10:10:Line10", "File10:20:Line20"]})
>>
>> The above call returns a dictionary where the 'items' key will contain
>> all the parsed entries.
>>
>> The getloclist() function can also be used instead of getqflist().
>
> Thanks, I'll include it.
>
> This still uses the existing 'errorformat'. Would there be use in
> passing another 'errorformat' for this?
>
I am attaching a patch to support specifying a 'efm' for parsing
the text. If the 'efm' key is not supplied, then 'errorformat' option
value is used.
- 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 7205c89a8..d074712fb 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -4612,6 +4612,7 @@ getqflist([{what}])
*getqflist()*
returns only the items listed in {what} as a dictionary. The
following string items are supported in {what}:
context get the context stored with |setqflist()|
+ efm errorformat to use when parsing 'text'
items quickfix list entries
nr get information for this quickfix list; zero
means the current quickfix list and '$' means
@@ -4620,7 +4621,9 @@ getqflist([{what}])
*getqflist()*
text and return the resulting entries. The
value can be a string with one line or a list
with multiple lines. The current quickfix list
- is not modified.
+ is not modified. If 'efm' is supplied in
+ {what}, then it is used to parse the text
+ instead of 'errorformat'.
title get the list title
winid get the |window-ID| (if opened)
all all of the above quickfix properties
@@ -4645,6 +4648,7 @@ getqflist([{what}])
*getqflist()*
Examples: >
:echo getqflist({'all': 1})
:echo getqflist({'nr': 2, 'title': 1})
+ :echo getqflist({'text' : 'File1:10:Line10'})
<
getreg([{regname} [, 1 [, {list}]]]) *getreg()*
diff --git a/src/quickfix.c b/src/quickfix.c
index 71270d9b9..204dae993 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4635,23 +4635,38 @@ enum {
* Parse text from 'di' and return the quickfix list items
*/
static int
-qf_get_list_from_text(dictitem_T *di, dict_T *retdict)
+qf_get_list_from_text(dict_T *what, dictitem_T *di, dict_T *retdict)
{
int status = FAIL;
qf_info_T *qi;
+ char_u *errorformat = NULL;
+ dictitem_T *efm_di;
/* Only string and list values are supported */
if ((di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
|| (di->di_tv.v_type == VAR_LIST
&& di->di_tv.vval.v_list != NULL))
{
+ /* If errorformat is supplied then use it, otherwise use the 'efm'
+ * option setting
+ */
+ if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL)
+ {
+ if (efm_di->di_tv.v_type != VAR_STRING ||
+ efm_di->di_tv.vval.v_string == NULL)
+ return FAIL;
+ errorformat = efm_di->di_tv.vval.v_string;
+ }
+ else
+ errorformat = p_efm;
+
qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
if (qi != NULL)
{
vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
qi->qf_refcount++;
- if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
+ if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
{
list_T *l = list_alloc();
@@ -4685,7 +4700,7 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T
*retdict)
int flags = QF_GETLIST_NONE;
if ((di = dict_find(what, (char_u *)"text", -1)) != NULL)
- return qf_get_list_from_text(di, retdict);
+ return qf_get_list_from_text(what, di, retdict);
if (wp != NULL)
{
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 32b04c34e..880701c39 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -2525,6 +2525,7 @@ endfunc
func XgetListFromText(cchar)
call s:setup_commands(a:cchar)
call g:Xsetlist([], 'f')
+ set efm&
let l = g:Xgetlist({'text' : "File1:10:Line10"}).items
call assert_equal(1, len(l))
@@ -2537,6 +2538,16 @@ func XgetListFromText(cchar)
call assert_equal({}, g:Xgetlist({'text' : 10}))
call assert_equal({}, g:Xgetlist({'text' : []}))
+ " Parse text using a special efm
+ let l = g:Xgetlist({'text' : 'File3#30#Line30', 'efm' : '%f#%l#%m'}).items
+ call assert_equal('Line30', l[0].text)
+ let l = g:Xgetlist({'text' : 'File3:30:Line30', 'efm' : '%f-%l-%m'}).items
+ call assert_equal('File3:30:Line30', l[0].text)
+ let l = g:Xgetlist({'text' : 'File3:30:Line30', 'efm' : [1,2]})
+ call assert_equal({}, l)
+ call assert_fails("call g:Xgetlist({'text' : 'abc', 'efm' : '%2'})", 'E376:')
+ call assert_fails("call g:Xgetlist({'text' : 'abc', 'efm' : ''})", 'E378:')
+
" Make sure that the quickfix stack is not modified
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
endfunc