Mercurial > vim
comparison src/quickfix.c @ 16050:c19853508d3e v8.1.1030
patch 8.1.1030: quickfix function arguments are inconsistent
commit https://github.com/vim/vim/commit/0398e00a1bf79e85223fb26938c8dd0d54883b77
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 21 21:12:49 2019 +0100
patch 8.1.1030: quickfix function arguments are inconsistent
Problem: Quickfix function arguments are inconsistent.
Solution: Pass a list pointer instead of info and index. (Yegappan
Lakshmanan, closes #4135)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 21 Mar 2019 21:15:06 +0100 |
parents | 096b8ccd855e |
children | d1efe0dbe6b0 |
comparison
equal
deleted
inserted
replaced
16049:75c99104f6b5 | 16050:c19853508d3e |
---|---|
158 static int quickfix_busy = 0; | 158 static int quickfix_busy = 0; |
159 | 159 |
160 static efm_T *fmt_start = NULL; // cached across qf_parse_line() calls | 160 static efm_T *fmt_start = NULL; // cached across qf_parse_line() calls |
161 | 161 |
162 static void qf_new_list(qf_info_T *qi, char_u *qf_title); | 162 static void qf_new_list(qf_info_T *qi, char_u *qf_title); |
163 static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname, char_u *module, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid); | 163 static int qf_add_entry(qf_list_T *qfl, char_u *dir, char_u *fname, char_u *module, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid); |
164 static void qf_free(qf_list_T *qfl); | 164 static void qf_free(qf_list_T *qfl); |
165 static char_u *qf_types(int, int); | 165 static char_u *qf_types(int, int); |
166 static int qf_get_fnum(qf_info_T *qi, int qf_idx, char_u *, char_u *); | 166 static int qf_get_fnum(qf_list_T *qfl, char_u *, char_u *); |
167 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); | 167 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); |
168 static char_u *qf_pop_dir(struct dir_stack_T **); | 168 static char_u *qf_pop_dir(struct dir_stack_T **); |
169 static char_u *qf_guess_filepath(qf_list_T *qfl, char_u *); | 169 static char_u *qf_guess_filepath(qf_list_T *qfl, char_u *); |
170 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); | 170 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); |
171 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); | 171 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); |
1320 /* | 1320 /* |
1321 * Parse multi-line error format prefixes (%C and %Z) | 1321 * Parse multi-line error format prefixes (%C and %Z) |
1322 */ | 1322 */ |
1323 static int | 1323 static int |
1324 qf_parse_multiline_pfx( | 1324 qf_parse_multiline_pfx( |
1325 qf_info_T *qi, | |
1326 int qf_idx, | |
1327 int idx, | 1325 int idx, |
1328 qf_list_T *qfl, | 1326 qf_list_T *qfl, |
1329 qffields_T *fields) | 1327 qffields_T *fields) |
1330 { | 1328 { |
1331 char_u *ptr; | 1329 char_u *ptr; |
1359 qfprev->qf_lnum = fields->lnum; | 1357 qfprev->qf_lnum = fields->lnum; |
1360 if (!qfprev->qf_col) | 1358 if (!qfprev->qf_col) |
1361 qfprev->qf_col = fields->col; | 1359 qfprev->qf_col = fields->col; |
1362 qfprev->qf_viscol = fields->use_viscol; | 1360 qfprev->qf_viscol = fields->use_viscol; |
1363 if (!qfprev->qf_fnum) | 1361 if (!qfprev->qf_fnum) |
1364 qfprev->qf_fnum = qf_get_fnum(qi, qf_idx, | 1362 qfprev->qf_fnum = qf_get_fnum(qfl, |
1365 qfl->qf_directory, | 1363 qfl->qf_directory, |
1366 *fields->namebuf || qfl->qf_directory != NULL | 1364 *fields->namebuf || qfl->qf_directory != NULL |
1367 ? fields->namebuf | 1365 ? fields->namebuf |
1368 : qfl->qf_currfile != NULL && fields->valid | 1366 : qfl->qf_currfile != NULL && fields->valid |
1369 ? qfl->qf_currfile : 0); | 1367 ? qfl->qf_currfile : 0); |
1379 * Parse a line and get the quickfix fields. | 1377 * Parse a line and get the quickfix fields. |
1380 * Return the QF_ status. | 1378 * Return the QF_ status. |
1381 */ | 1379 */ |
1382 static int | 1380 static int |
1383 qf_parse_line( | 1381 qf_parse_line( |
1384 qf_info_T *qi, | 1382 qf_list_T *qfl, |
1385 int qf_idx, | |
1386 char_u *linebuf, | 1383 char_u *linebuf, |
1387 int linelen, | 1384 int linelen, |
1388 efm_T *fmt_first, | 1385 efm_T *fmt_first, |
1389 qffields_T *fields) | 1386 qffields_T *fields) |
1390 { | 1387 { |
1391 efm_T *fmt_ptr; | 1388 efm_T *fmt_ptr; |
1392 int idx = 0; | 1389 int idx = 0; |
1393 char_u *tail = NULL; | 1390 char_u *tail = NULL; |
1394 qf_list_T *qfl = &qi->qf_lists[qf_idx]; | |
1395 int status; | 1391 int status; |
1396 | 1392 |
1397 restofline: | 1393 restofline: |
1398 // If there was no %> item start at the first pattern | 1394 // If there was no %> item start at the first pattern |
1399 if (fmt_start == NULL) | 1395 if (fmt_start == NULL) |
1448 qfl->qf_multiline = TRUE; // start of a multi-line message | 1444 qfl->qf_multiline = TRUE; // start of a multi-line message |
1449 qfl->qf_multiignore = FALSE;// reset continuation | 1445 qfl->qf_multiignore = FALSE;// reset continuation |
1450 } | 1446 } |
1451 else if (vim_strchr((char_u *)"CZ", idx) != NULL) | 1447 else if (vim_strchr((char_u *)"CZ", idx) != NULL) |
1452 { // continuation of multi-line msg | 1448 { // continuation of multi-line msg |
1453 status = qf_parse_multiline_pfx(qi, qf_idx, idx, qfl, fields); | 1449 status = qf_parse_multiline_pfx(idx, qfl, fields); |
1454 if (status != QF_OK) | 1450 if (status != QF_OK) |
1455 return status; | 1451 return status; |
1456 } | 1452 } |
1457 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) | 1453 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) |
1458 { // global file names | 1454 { // global file names |
1483 | 1479 |
1484 /* | 1480 /* |
1485 * Returns TRUE if the specified quickfix/location list is empty. | 1481 * Returns TRUE if the specified quickfix/location list is empty. |
1486 */ | 1482 */ |
1487 static int | 1483 static int |
1488 qf_list_empty(qf_info_T *qi, int qf_idx) | 1484 qf_list_empty(qf_list_T *qfl) |
1489 { | 1485 { |
1490 if (qi == NULL || qf_idx < 0 || qf_idx >= LISTCOUNT) | 1486 return qfl == NULL || qfl->qf_count <= 0; |
1491 return TRUE; | 1487 } |
1492 return qi->qf_lists[qf_idx].qf_count <= 0; | 1488 |
1489 /* | |
1490 * Return a pointer to a list in the specified quickfix stack | |
1491 */ | |
1492 static qf_list_T * | |
1493 qf_get_list(qf_info_T *qi, int idx) | |
1494 { | |
1495 return &qi->qf_lists[idx]; | |
1493 } | 1496 } |
1494 | 1497 |
1495 /* | 1498 /* |
1496 * Allocate the fields used for parsing lines and populating a quickfix list. | 1499 * Allocate the fields used for parsing lines and populating a quickfix list. |
1497 */ | 1500 */ |
1629 } | 1632 } |
1630 else | 1633 else |
1631 { | 1634 { |
1632 // Adding to existing list, use last entry. | 1635 // Adding to existing list, use last entry. |
1633 adding = TRUE; | 1636 adding = TRUE; |
1634 if (!qf_list_empty(qi, qf_idx)) | 1637 if (!qf_list_empty(qf_get_list(qi, qf_idx))) |
1635 old_last = qi->qf_lists[qf_idx].qf_last; | 1638 old_last = qi->qf_lists[qf_idx].qf_last; |
1636 } | 1639 } |
1637 | 1640 |
1638 qfl = &qi->qf_lists[qf_idx]; | 1641 qfl = qf_get_list(qi, qf_idx); |
1639 | 1642 |
1640 // Use the local value of 'errorformat' if it's set. | 1643 // Use the local value of 'errorformat' if it's set. |
1641 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) | 1644 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) |
1642 efm = buf->b_p_efm; | 1645 efm = buf->b_p_efm; |
1643 else | 1646 else |
1673 if (status == QF_NOMEM) // memory alloc failure | 1676 if (status == QF_NOMEM) // memory alloc failure |
1674 goto qf_init_end; | 1677 goto qf_init_end; |
1675 if (status == QF_END_OF_INPUT) // end of input | 1678 if (status == QF_END_OF_INPUT) // end of input |
1676 break; | 1679 break; |
1677 | 1680 |
1678 status = qf_parse_line(qi, qf_idx, state.linebuf, state.linelen, | 1681 status = qf_parse_line(qfl, state.linebuf, state.linelen, |
1679 fmt_first, &fields); | 1682 fmt_first, &fields); |
1680 if (status == QF_FAIL) | 1683 if (status == QF_FAIL) |
1681 goto error2; | 1684 goto error2; |
1682 if (status == QF_NOMEM) | 1685 if (status == QF_NOMEM) |
1683 goto qf_init_end; | 1686 goto qf_init_end; |
1684 if (status == QF_IGNORE_LINE) | 1687 if (status == QF_IGNORE_LINE) |
1685 continue; | 1688 continue; |
1686 | 1689 |
1687 if (qf_add_entry(qi, | 1690 if (qf_add_entry(qfl, |
1688 qf_idx, | |
1689 qfl->qf_directory, | 1691 qfl->qf_directory, |
1690 (*fields.namebuf || qfl->qf_directory != NULL) | 1692 (*fields.namebuf || qfl->qf_directory != NULL) |
1691 ? fields.namebuf | 1693 ? fields.namebuf |
1692 : ((qfl->qf_currfile != NULL && fields.valid) | 1694 : ((qfl->qf_currfile != NULL && fields.valid) |
1693 ? qfl->qf_currfile : (char_u *)NULL), | 1695 ? qfl->qf_currfile : (char_u *)NULL), |
1806 * Return a pointer to the current list in the specified quickfix stack | 1808 * Return a pointer to the current list in the specified quickfix stack |
1807 */ | 1809 */ |
1808 static qf_list_T * | 1810 static qf_list_T * |
1809 qf_get_curlist(qf_info_T *qi) | 1811 qf_get_curlist(qf_info_T *qi) |
1810 { | 1812 { |
1811 return &qi->qf_lists[qi->qf_curlist]; | 1813 return qf_get_list(qi, qi->qf_curlist); |
1812 } | 1814 } |
1813 | 1815 |
1814 /* | 1816 /* |
1815 * Prepare for adding a new quickfix list. If the current list is in the | 1817 * Prepare for adding a new quickfix list. If the current list is in the |
1816 * middle of the stack, then all the following lists are freed and then | 1818 * middle of the stack, then all the following lists are freed and then |
1922 // No references to this location list. | 1924 // No references to this location list. |
1923 // If the quickfix window buffer is loaded, then wipe it | 1925 // If the quickfix window buffer is loaded, then wipe it |
1924 wipe_qf_buffer(qi); | 1926 wipe_qf_buffer(qi); |
1925 | 1927 |
1926 for (i = 0; i < qi->qf_listcount; ++i) | 1928 for (i = 0; i < qi->qf_listcount; ++i) |
1927 qf_free(&qi->qf_lists[i]); | 1929 qf_free(qf_get_list(qi, i)); |
1928 vim_free(qi); | 1930 vim_free(qi); |
1929 } | 1931 } |
1930 } | 1932 } |
1931 | 1933 |
1932 /* | 1934 /* |
1945 ll_free_all(&wp->w_llist_ref); | 1947 ll_free_all(&wp->w_llist_ref); |
1946 } | 1948 } |
1947 else | 1949 else |
1948 // quickfix list | 1950 // quickfix list |
1949 for (i = 0; i < qi->qf_listcount; ++i) | 1951 for (i = 0; i < qi->qf_listcount; ++i) |
1950 qf_free(&qi->qf_lists[i]); | 1952 qf_free(qf_get_list(qi, i)); |
1951 } | 1953 } |
1952 | 1954 |
1953 /* | 1955 /* |
1954 * Delay freeing of location list stacks when the quickfix code is running. | 1956 * Delay freeing of location list stacks when the quickfix code is running. |
1955 * Used to avoid problems with autocmds freeing location list stacks when the | 1957 * Used to avoid problems with autocmds freeing location list stacks when the |
2008 * Add an entry to the end of the list of errors. | 2010 * Add an entry to the end of the list of errors. |
2009 * Returns OK or FAIL. | 2011 * Returns OK or FAIL. |
2010 */ | 2012 */ |
2011 static int | 2013 static int |
2012 qf_add_entry( | 2014 qf_add_entry( |
2013 qf_info_T *qi, // quickfix list | 2015 qf_list_T *qfl, // quickfix list entry |
2014 int qf_idx, // list index | |
2015 char_u *dir, // optional directory name | 2016 char_u *dir, // optional directory name |
2016 char_u *fname, // file name or NULL | 2017 char_u *fname, // file name or NULL |
2017 char_u *module, // module name or NULL | 2018 char_u *module, // module name or NULL |
2018 int bufnum, // buffer number or zero | 2019 int bufnum, // buffer number or zero |
2019 char_u *mesg, // message | 2020 char_u *mesg, // message |
2023 char_u *pattern, // search pattern | 2024 char_u *pattern, // search pattern |
2024 int nr, // error number | 2025 int nr, // error number |
2025 int type, // type character | 2026 int type, // type character |
2026 int valid) // valid entry | 2027 int valid) // valid entry |
2027 { | 2028 { |
2028 qf_list_T *qfl = &qi->qf_lists[qf_idx]; | |
2029 qfline_T *qfp; | 2029 qfline_T *qfp; |
2030 qfline_T **lastp; // pointer to qf_last or NULL | 2030 qfline_T **lastp; // pointer to qf_last or NULL |
2031 | 2031 |
2032 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) | 2032 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) |
2033 return FAIL; | 2033 return FAIL; |
2039 if (buf != NULL) | 2039 if (buf != NULL) |
2040 buf->b_has_qf_entry |= | 2040 buf->b_has_qf_entry |= |
2041 IS_QF_LIST(qfl) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; | 2041 IS_QF_LIST(qfl) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; |
2042 } | 2042 } |
2043 else | 2043 else |
2044 qfp->qf_fnum = qf_get_fnum(qi, qf_idx, dir, fname); | 2044 qfp->qf_fnum = qf_get_fnum(qfl, dir, fname); |
2045 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) | 2045 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) |
2046 { | 2046 { |
2047 vim_free(qfp); | 2047 vim_free(qfp); |
2048 return FAIL; | 2048 return FAIL; |
2049 } | 2049 } |
2072 type = 0; | 2072 type = 0; |
2073 qfp->qf_type = type; | 2073 qfp->qf_type = type; |
2074 qfp->qf_valid = valid; | 2074 qfp->qf_valid = valid; |
2075 | 2075 |
2076 lastp = &qfl->qf_last; | 2076 lastp = &qfl->qf_last; |
2077 if (qf_list_empty(qi, qf_idx)) // first element in the list | 2077 if (qf_list_empty(qfl)) // first element in the list |
2078 { | 2078 { |
2079 qfl->qf_start = qfp; | 2079 qfl->qf_start = qfp; |
2080 qfl->qf_ptr = qfp; | 2080 qfl->qf_ptr = qfp; |
2081 qfl->qf_index = 0; | 2081 qfl->qf_index = 0; |
2082 qfp->qf_prev = NULL; | 2082 qfp->qf_prev = NULL; |
2139 | 2139 |
2140 /* | 2140 /* |
2141 * Copy location list entries from 'from_qfl' to 'to_qfl'. | 2141 * Copy location list entries from 'from_qfl' to 'to_qfl'. |
2142 */ | 2142 */ |
2143 static int | 2143 static int |
2144 copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi) | 2144 copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl) |
2145 { | 2145 { |
2146 int i; | 2146 int i; |
2147 qfline_T *from_qfp; | 2147 qfline_T *from_qfp; |
2148 qfline_T *prevp; | 2148 qfline_T *prevp; |
2149 | 2149 |
2150 // copy all the location entries in this list | 2150 // copy all the location entries in this list |
2151 for (i = 0, from_qfp = from_qfl->qf_start; | 2151 for (i = 0, from_qfp = from_qfl->qf_start; |
2152 i < from_qfl->qf_count && from_qfp != NULL; | 2152 i < from_qfl->qf_count && from_qfp != NULL; |
2153 ++i, from_qfp = from_qfp->qf_next) | 2153 ++i, from_qfp = from_qfp->qf_next) |
2154 { | 2154 { |
2155 if (qf_add_entry(to_qi, | 2155 if (qf_add_entry(to_qfl, |
2156 to_qi->qf_curlist, | |
2157 NULL, | 2156 NULL, |
2158 NULL, | 2157 NULL, |
2159 from_qfp->qf_module, | 2158 from_qfp->qf_module, |
2160 0, | 2159 0, |
2161 from_qfp->qf_text, | 2160 from_qfp->qf_text, |
2183 | 2182 |
2184 /* | 2183 /* |
2185 * Copy the specified location list 'from_qfl' to 'to_qfl'. | 2184 * Copy the specified location list 'from_qfl' to 'to_qfl'. |
2186 */ | 2185 */ |
2187 static int | 2186 static int |
2188 copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi) | 2187 copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl) |
2189 { | 2188 { |
2190 // Some of the fields are populated by qf_add_entry() | 2189 // Some of the fields are populated by qf_add_entry() |
2191 to_qfl->qfl_type = from_qfl->qfl_type; | 2190 to_qfl->qfl_type = from_qfl->qfl_type; |
2192 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; | 2191 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; |
2193 to_qfl->qf_count = 0; | 2192 to_qfl->qf_count = 0; |
2207 } | 2206 } |
2208 else | 2207 else |
2209 to_qfl->qf_ctx = NULL; | 2208 to_qfl->qf_ctx = NULL; |
2210 | 2209 |
2211 if (from_qfl->qf_count) | 2210 if (from_qfl->qf_count) |
2212 if (copy_loclist_entries(from_qfl, to_qfl, to_qi) == FAIL) | 2211 if (copy_loclist_entries(from_qfl, to_qfl) == FAIL) |
2213 return FAIL; | 2212 return FAIL; |
2214 | 2213 |
2215 to_qfl->qf_index = from_qfl->qf_index; // current index in the list | 2214 to_qfl->qf_index = from_qfl->qf_index; // current index in the list |
2216 | 2215 |
2217 // Assign a new ID for the location list | 2216 // Assign a new ID for the location list |
2258 // Copy the location lists one at a time | 2257 // Copy the location lists one at a time |
2259 for (idx = 0; idx < qi->qf_listcount; ++idx) | 2258 for (idx = 0; idx < qi->qf_listcount; ++idx) |
2260 { | 2259 { |
2261 to->w_llist->qf_curlist = idx; | 2260 to->w_llist->qf_curlist = idx; |
2262 | 2261 |
2263 if (copy_loclist(&qi->qf_lists[idx], | 2262 if (copy_loclist(qf_get_list(qi, idx), |
2264 &to->w_llist->qf_lists[idx], to->w_llist) == FAIL) | 2263 qf_get_list(to->w_llist, idx)) == FAIL) |
2265 { | 2264 { |
2266 qf_free_all(to); | 2265 qf_free_all(to); |
2267 return; | 2266 return; |
2268 } | 2267 } |
2269 } | 2268 } |
2274 /* | 2273 /* |
2275 * Get buffer number for file "directory/fname". | 2274 * Get buffer number for file "directory/fname". |
2276 * Also sets the b_has_qf_entry flag. | 2275 * Also sets the b_has_qf_entry flag. |
2277 */ | 2276 */ |
2278 static int | 2277 static int |
2279 qf_get_fnum(qf_info_T *qi, int qf_idx, char_u *directory, char_u *fname) | 2278 qf_get_fnum(qf_list_T *qfl, char_u *directory, char_u *fname) |
2280 { | 2279 { |
2281 qf_list_T *qfl = &qi->qf_lists[qf_idx]; | |
2282 char_u *ptr = NULL; | 2280 char_u *ptr = NULL; |
2283 buf_T *buf; | 2281 buf_T *buf; |
2284 char_u *bufname; | 2282 char_u *bufname; |
2285 | 2283 |
2286 if (fname == NULL || *fname == NUL) // no file name | 2284 if (fname == NULL || *fname == NUL) // no file name |
2904 } | 2902 } |
2905 win_goto(win); | 2903 win_goto(win); |
2906 | 2904 |
2907 // If the location list for the window is not set, then set it | 2905 // If the location list for the window is not set, then set it |
2908 // to the location list from the location window | 2906 // to the location list from the location window |
2909 if (win->w_llist == NULL) | 2907 if (win->w_llist == NULL && ll_ref != NULL) |
2910 win_set_loclist(win, ll_ref); | 2908 win_set_loclist(win, ll_ref); |
2911 } | 2909 } |
2912 | 2910 |
2913 /* | 2911 /* |
2914 * Go to a window that contains the specified buffer 'qf_fnum'. If a window is | 2912 * Go to a window that contains the specified buffer 'qf_fnum'. If a window is |
3310 int retval = OK; | 3308 int retval = OK; |
3311 | 3309 |
3312 if (qi == NULL) | 3310 if (qi == NULL) |
3313 qi = &ql_info; | 3311 qi = &ql_info; |
3314 | 3312 |
3315 if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) | 3313 if (qf_stack_empty(qi) || qf_list_empty(qf_get_curlist(qi))) |
3316 { | 3314 { |
3317 emsg(_(e_quickfix)); | 3315 emsg(_(e_quickfix)); |
3318 return; | 3316 return; |
3319 } | 3317 } |
3320 | 3318 |
3504 emsg(_(e_loclist)); | 3502 emsg(_(e_loclist)); |
3505 return; | 3503 return; |
3506 } | 3504 } |
3507 } | 3505 } |
3508 | 3506 |
3509 if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) | 3507 if (qf_stack_empty(qi) || qf_list_empty(qf_get_curlist(qi))) |
3510 { | 3508 { |
3511 emsg(_(e_quickfix)); | 3509 emsg(_(e_quickfix)); |
3512 return; | 3510 return; |
3513 } | 3511 } |
3514 if (*arg == '+') | 3512 if (*arg == '+') |
3788 return; | 3786 return; |
3789 qi = wp->w_llist; | 3787 qi = wp->w_llist; |
3790 } | 3788 } |
3791 | 3789 |
3792 for (idx = 0; idx < qi->qf_listcount; ++idx) | 3790 for (idx = 0; idx < qi->qf_listcount; ++idx) |
3793 if (!qf_list_empty(qi, idx)) | 3791 { |
3794 for (i = 0, qfp = qi->qf_lists[idx].qf_start; | 3792 qf_list_T *qfl = qf_get_list(qi, idx); |
3795 i < qi->qf_lists[idx].qf_count && qfp != NULL; | 3793 |
3794 if (!qf_list_empty(qfl)) | |
3795 for (i = 0, qfp = qfl->qf_start; | |
3796 i < qfl->qf_count && qfp != NULL; | |
3796 ++i, qfp = qfp->qf_next) | 3797 ++i, qfp = qfp->qf_next) |
3797 if (qfp->qf_fnum == curbuf->b_fnum) | 3798 if (qfp->qf_fnum == curbuf->b_fnum) |
3798 { | 3799 { |
3799 found_one = TRUE; | 3800 found_one = TRUE; |
3800 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) | 3801 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) |
3805 qfp->qf_lnum += amount; | 3806 qfp->qf_lnum += amount; |
3806 } | 3807 } |
3807 else if (amount_after && qfp->qf_lnum > line2) | 3808 else if (amount_after && qfp->qf_lnum > line2) |
3808 qfp->qf_lnum += amount_after; | 3809 qfp->qf_lnum += amount_after; |
3809 } | 3810 } |
3811 } | |
3810 | 3812 |
3811 if (!found_one) | 3813 if (!found_one) |
3812 curbuf->b_has_qf_entry &= ~buf_has_flag; | 3814 curbuf->b_has_qf_entry &= ~buf_has_flag; |
3813 } | 3815 } |
3814 | 3816 |
3870 return; | 3872 return; |
3871 | 3873 |
3872 if (IS_LL_WINDOW(curwin)) | 3874 if (IS_LL_WINDOW(curwin)) |
3873 qi = GET_LOC_LIST(curwin); | 3875 qi = GET_LOC_LIST(curwin); |
3874 | 3876 |
3875 if (qf_list_empty(qi, qi->qf_curlist)) | 3877 if (qf_list_empty(qf_get_curlist(qi))) |
3876 { | 3878 { |
3877 emsg(_(e_quickfix)); | 3879 emsg(_(e_quickfix)); |
3878 return; | 3880 return; |
3879 } | 3881 } |
3880 | 3882 |
3917 // If a quickfix window is open but we have no errors to display, | 3919 // If a quickfix window is open but we have no errors to display, |
3918 // close the window. If a quickfix window is not open, then open | 3920 // close the window. If a quickfix window is not open, then open |
3919 // it if we have errors; otherwise, leave it closed. | 3921 // it if we have errors; otherwise, leave it closed. |
3920 if (qf_stack_empty(qi) | 3922 if (qf_stack_empty(qi) |
3921 || qfl->qf_nonevalid | 3923 || qfl->qf_nonevalid |
3922 || qf_list_empty(qi, qi->qf_curlist)) | 3924 || qf_list_empty(qf_get_curlist(qi))) |
3923 { | 3925 { |
3924 if (win != NULL) | 3926 if (win != NULL) |
3925 ex_cclose(eap); | 3927 ex_cclose(eap); |
3926 } | 3928 } |
3927 else if (win == NULL) | 3929 else if (win == NULL) |
4578 { | 4580 { |
4579 if (qf_restore_list(qi, save_qfid) == FAIL) | 4581 if (qf_restore_list(qi, save_qfid) == FAIL) |
4580 return; | 4582 return; |
4581 | 4583 |
4582 // Autocommands might have cleared the list, check for that. | 4584 // Autocommands might have cleared the list, check for that. |
4583 if (!qf_list_empty(qi, qi->qf_curlist)) | 4585 if (!qf_list_empty(qf_get_curlist(qi))) |
4584 qf_jump(qi, 0, 0, forceit); | 4586 qf_jump(qi, 0, 0, forceit); |
4585 } | 4587 } |
4586 | 4588 |
4587 /* | 4589 /* |
4588 * Return TRUE when using ":vimgrep" for ":grep". | 4590 * Return TRUE when using ":vimgrep" for ":grep". |
5303 col, NULL, NULL) > 0) | 5305 col, NULL, NULL) > 0) |
5304 { | 5306 { |
5305 // Pass the buffer number so that it gets used even for a | 5307 // Pass the buffer number so that it gets used even for a |
5306 // dummy buffer, unless duplicate_name is set, then the | 5308 // dummy buffer, unless duplicate_name is set, then the |
5307 // buffer will be wiped out below. | 5309 // buffer will be wiped out below. |
5308 if (qf_add_entry(qi, | 5310 if (qf_add_entry(qf_get_curlist(qi), |
5309 qi->qf_curlist, | |
5310 NULL, // dir | 5311 NULL, // dir |
5311 fname, | 5312 fname, |
5312 NULL, | 5313 NULL, |
5313 duplicate_name ? 0 : buf->b_fnum, | 5314 duplicate_name ? 0 : buf->b_fnum, |
5314 ml_get_buf(buf, | 5315 ml_get_buf(buf, |
5622 decr_quickfix_busy(); | 5623 decr_quickfix_busy(); |
5623 goto theend; | 5624 goto theend; |
5624 } | 5625 } |
5625 | 5626 |
5626 // Jump to first match. | 5627 // Jump to first match. |
5627 if (!qf_list_empty(qi, qi->qf_curlist)) | 5628 if (!qf_list_empty(qf_get_curlist(qi))) |
5628 { | 5629 { |
5629 if ((flags & VGR_NOJUMP) == 0) | 5630 if ((flags & VGR_NOJUMP) == 0) |
5630 vgr_jump_to_match(qi, eap->forceit, &redraw_for_dummy, | 5631 vgr_jump_to_match(qi, eap->forceit, &redraw_for_dummy, |
5631 first_match_buf, target_dir); | 5632 first_match_buf, target_dir); |
5632 } | 5633 } |
5835 */ | 5836 */ |
5836 int | 5837 int |
5837 get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) | 5838 get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) |
5838 { | 5839 { |
5839 qf_info_T *qi = qi_arg; | 5840 qf_info_T *qi = qi_arg; |
5841 qf_list_T *qfl; | |
5840 dict_T *dict; | 5842 dict_T *dict; |
5841 char_u buf[2]; | 5843 char_u buf[2]; |
5842 qfline_T *qfp; | 5844 qfline_T *qfp; |
5843 int i; | 5845 int i; |
5844 int bufnum; | 5846 int bufnum; |
5855 } | 5857 } |
5856 | 5858 |
5857 if (qf_idx == INVALID_QFIDX) | 5859 if (qf_idx == INVALID_QFIDX) |
5858 qf_idx = qi->qf_curlist; | 5860 qf_idx = qi->qf_curlist; |
5859 | 5861 |
5860 if (qf_idx >= qi->qf_listcount || qf_list_empty(qi, qf_idx)) | 5862 if (qf_idx >= qi->qf_listcount) |
5861 return FAIL; | 5863 return FAIL; |
5862 | 5864 |
5863 qfp = qi->qf_lists[qf_idx].qf_start; | 5865 qfl = qf_get_list(qi, qf_idx); |
5864 for (i = 1; !got_int && i <= qi->qf_lists[qf_idx].qf_count; ++i) | 5866 if (qf_list_empty(qfl)) |
5867 return FAIL; | |
5868 | |
5869 qfp = qfl->qf_start; | |
5870 for (i = 1; !got_int && i <= qfl->qf_count; ++i) | |
5865 { | 5871 { |
5866 // Handle entries with a non-existing buffer number. | 5872 // Handle entries with a non-existing buffer number. |
5867 bufnum = qfp->qf_fnum; | 5873 bufnum = qfp->qf_fnum; |
5868 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | 5874 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) |
5869 bufnum = 0; | 5875 bufnum = 0; |
6213 | 6219 |
6214 /* | 6220 /* |
6215 * Return the current quickfix list index as 'idx' in retdict | 6221 * Return the current quickfix list index as 'idx' in retdict |
6216 */ | 6222 */ |
6217 static int | 6223 static int |
6218 qf_getprop_idx(qf_info_T *qi, int qf_idx, dict_T *retdict) | 6224 qf_getprop_idx(qf_list_T *qfl, dict_T *retdict) |
6219 { | 6225 { |
6220 int curidx = qi->qf_lists[qf_idx].qf_index; | 6226 int curidx = qfl->qf_index; |
6221 if (qf_list_empty(qi, qf_idx)) | 6227 if (qf_list_empty(qfl)) |
6222 // For empty lists, current index is set to 0 | 6228 // For empty lists, current index is set to 0 |
6223 curidx = 0; | 6229 curidx = 0; |
6224 return dict_add_number(retdict, "idx", curidx); | 6230 return dict_add_number(retdict, "idx", curidx); |
6225 } | 6231 } |
6226 | 6232 |
6252 | 6258 |
6253 // List is not present or is empty | 6259 // List is not present or is empty |
6254 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) | 6260 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) |
6255 return qf_getprop_defaults(qi, flags, wp != NULL, retdict); | 6261 return qf_getprop_defaults(qi, flags, wp != NULL, retdict); |
6256 | 6262 |
6257 qfl = &qi->qf_lists[qf_idx]; | 6263 qfl = qf_get_list(qi, qf_idx); |
6258 | 6264 |
6259 if (flags & QF_GETLIST_TITLE) | 6265 if (flags & QF_GETLIST_TITLE) |
6260 status = qf_getprop_title(qfl, retdict); | 6266 status = qf_getprop_title(qfl, retdict); |
6261 if ((status == OK) && (flags & QF_GETLIST_NR)) | 6267 if ((status == OK) && (flags & QF_GETLIST_NR)) |
6262 status = dict_add_number(retdict, "nr", qf_idx + 1); | 6268 status = dict_add_number(retdict, "nr", qf_idx + 1); |
6267 if ((status == OK) && (flags & QF_GETLIST_CONTEXT)) | 6273 if ((status == OK) && (flags & QF_GETLIST_CONTEXT)) |
6268 status = qf_getprop_ctx(qfl, retdict); | 6274 status = qf_getprop_ctx(qfl, retdict); |
6269 if ((status == OK) && (flags & QF_GETLIST_ID)) | 6275 if ((status == OK) && (flags & QF_GETLIST_ID)) |
6270 status = dict_add_number(retdict, "id", qfl->qf_id); | 6276 status = dict_add_number(retdict, "id", qfl->qf_id); |
6271 if ((status == OK) && (flags & QF_GETLIST_IDX)) | 6277 if ((status == OK) && (flags & QF_GETLIST_IDX)) |
6272 status = qf_getprop_idx(qi, qf_idx, retdict); | 6278 status = qf_getprop_idx(qfl, retdict); |
6273 if ((status == OK) && (flags & QF_GETLIST_SIZE)) | 6279 if ((status == OK) && (flags & QF_GETLIST_SIZE)) |
6274 status = dict_add_number(retdict, "size", qfl->qf_count); | 6280 status = dict_add_number(retdict, "size", qfl->qf_count); |
6275 if ((status == OK) && (flags & QF_GETLIST_TICK)) | 6281 if ((status == OK) && (flags & QF_GETLIST_TICK)) |
6276 status = dict_add_number(retdict, "changedtick", qfl->qf_changedtick); | 6282 status = dict_add_number(retdict, "changedtick", qfl->qf_changedtick); |
6277 if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID)) | 6283 if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID)) |
6287 * items in the dict 'd'. If it is a valid error entry, then set 'valid_entry' | 6293 * items in the dict 'd'. If it is a valid error entry, then set 'valid_entry' |
6288 * to TRUE. | 6294 * to TRUE. |
6289 */ | 6295 */ |
6290 static int | 6296 static int |
6291 qf_add_entry_from_dict( | 6297 qf_add_entry_from_dict( |
6292 qf_info_T *qi, | 6298 qf_list_T *qfl, |
6293 int qf_idx, | |
6294 dict_T *d, | 6299 dict_T *d, |
6295 int first_entry, | 6300 int first_entry, |
6296 int *valid_entry) | 6301 int *valid_entry) |
6297 { | 6302 { |
6298 static int did_bufnr_emsg; | 6303 static int did_bufnr_emsg; |
6335 | 6340 |
6336 // If the 'valid' field is present it overrules the detected value. | 6341 // If the 'valid' field is present it overrules the detected value. |
6337 if ((dict_find(d, (char_u *)"valid", -1)) != NULL) | 6342 if ((dict_find(d, (char_u *)"valid", -1)) != NULL) |
6338 valid = (int)dict_get_number(d, (char_u *)"valid"); | 6343 valid = (int)dict_get_number(d, (char_u *)"valid"); |
6339 | 6344 |
6340 status = qf_add_entry(qi, | 6345 status = qf_add_entry(qfl, |
6341 qf_idx, | |
6342 NULL, // dir | 6346 NULL, // dir |
6343 filename, | 6347 filename, |
6344 module, | 6348 module, |
6345 bufnum, | 6349 bufnum, |
6346 text, | 6350 text, |
6374 int qf_idx, | 6378 int qf_idx, |
6375 list_T *list, | 6379 list_T *list, |
6376 char_u *title, | 6380 char_u *title, |
6377 int action) | 6381 int action) |
6378 { | 6382 { |
6379 qf_list_T *qfl = &qi->qf_lists[qf_idx]; | 6383 qf_list_T *qfl = qf_get_list(qi, qf_idx); |
6380 listitem_T *li; | 6384 listitem_T *li; |
6381 dict_T *d; | 6385 dict_T *d; |
6382 qfline_T *old_last = NULL; | 6386 qfline_T *old_last = NULL; |
6383 int retval = OK; | 6387 int retval = OK; |
6384 int valid_entry = FALSE; | 6388 int valid_entry = FALSE; |
6386 if (action == ' ' || qf_idx == qi->qf_listcount) | 6390 if (action == ' ' || qf_idx == qi->qf_listcount) |
6387 { | 6391 { |
6388 // make place for a new list | 6392 // make place for a new list |
6389 qf_new_list(qi, title); | 6393 qf_new_list(qi, title); |
6390 qf_idx = qi->qf_curlist; | 6394 qf_idx = qi->qf_curlist; |
6391 qfl = &qi->qf_lists[qf_idx]; | 6395 qfl = qf_get_list(qi, qf_idx); |
6392 } | 6396 } |
6393 else if (action == 'a' && !qf_list_empty(qi, qf_idx)) | 6397 else if (action == 'a' && !qf_list_empty(qfl)) |
6394 // Adding to existing list, use last entry. | 6398 // Adding to existing list, use last entry. |
6395 old_last = qfl->qf_last; | 6399 old_last = qfl->qf_last; |
6396 else if (action == 'r') | 6400 else if (action == 'r') |
6397 { | 6401 { |
6398 qf_free_items(qfl); | 6402 qf_free_items(qfl); |
6406 | 6410 |
6407 d = li->li_tv.vval.v_dict; | 6411 d = li->li_tv.vval.v_dict; |
6408 if (d == NULL) | 6412 if (d == NULL) |
6409 continue; | 6413 continue; |
6410 | 6414 |
6411 retval = qf_add_entry_from_dict(qi, qf_idx, d, li == list->lv_first, | 6415 retval = qf_add_entry_from_dict(qfl, d, li == list->lv_first, |
6412 &valid_entry); | 6416 &valid_entry); |
6413 if (retval == FAIL) | 6417 if (retval == FAIL) |
6414 break; | 6418 break; |
6415 } | 6419 } |
6416 | 6420 |
6425 if (action != 'a') | 6429 if (action != 'a') |
6426 qfl->qf_ptr = qfl->qf_start; | 6430 qfl->qf_ptr = qfl->qf_start; |
6427 | 6431 |
6428 // Update the current error index if not appending to the list or if the | 6432 // Update the current error index if not appending to the list or if the |
6429 // list was empty before and it is not empty now. | 6433 // list was empty before and it is not empty now. |
6430 if ((action != 'a' || qfl->qf_index == 0) && !qf_list_empty(qi, qf_idx)) | 6434 if ((action != 'a' || qfl->qf_index == 0) && !qf_list_empty(qfl)) |
6431 qfl->qf_index = 1; | 6435 qfl->qf_index = 1; |
6432 | 6436 |
6433 // Don't update the cursor in quickfix window when appending entries | 6437 // Don't update the cursor in quickfix window when appending entries |
6434 qf_update_buffer(qi, old_last); | 6438 qf_update_buffer(qi, old_last); |
6435 | 6439 |
6502 * Set the quickfix list title. | 6506 * Set the quickfix list title. |
6503 */ | 6507 */ |
6504 static int | 6508 static int |
6505 qf_setprop_title(qf_info_T *qi, int qf_idx, dict_T *what, dictitem_T *di) | 6509 qf_setprop_title(qf_info_T *qi, int qf_idx, dict_T *what, dictitem_T *di) |
6506 { | 6510 { |
6507 qf_list_T *qfl = &qi->qf_lists[qf_idx]; | 6511 qf_list_T *qfl = qf_get_list(qi, qf_idx); |
6508 | 6512 |
6509 if (di->di_tv.v_type != VAR_STRING) | 6513 if (di->di_tv.v_type != VAR_STRING) |
6510 return FAIL; | 6514 return FAIL; |
6511 | 6515 |
6512 vim_free(qfl->qf_title); | 6516 vim_free(qfl->qf_title); |
6661 qi->qf_curlist = qf_idx; | 6665 qi->qf_curlist = qf_idx; |
6662 qf_new_list(qi, title); | 6666 qf_new_list(qi, title); |
6663 qf_idx = qi->qf_curlist; | 6667 qf_idx = qi->qf_curlist; |
6664 } | 6668 } |
6665 | 6669 |
6666 qfl = &qi->qf_lists[qf_idx]; | 6670 qfl = qf_get_list(qi, qf_idx); |
6667 if ((di = dict_find(what, (char_u *)"title", -1)) != NULL) | 6671 if ((di = dict_find(what, (char_u *)"title", -1)) != NULL) |
6668 retval = qf_setprop_title(qi, qf_idx, what, di); | 6672 retval = qf_setprop_title(qi, qf_idx, what, di); |
6669 if ((di = dict_find(what, (char_u *)"items", -1)) != NULL) | 6673 if ((di = dict_find(what, (char_u *)"items", -1)) != NULL) |
6670 retval = qf_setprop_items(qi, qf_idx, di, action); | 6674 retval = qf_setprop_items(qi, qf_idx, di, action); |
6671 if ((di = dict_find(what, (char_u *)"lines", -1)) != NULL) | 6675 if ((di = dict_find(what, (char_u *)"lines", -1)) != NULL) |
7111 | 7115 |
7112 // remove trailing CR, LF, spaces, etc. | 7116 // remove trailing CR, LF, spaces, etc. |
7113 while (l > 0 && line[l - 1] <= ' ') | 7117 while (l > 0 && line[l - 1] <= ' ') |
7114 line[--l] = NUL; | 7118 line[--l] = NUL; |
7115 | 7119 |
7116 if (qf_add_entry(qi, | 7120 if (qf_add_entry(qf_get_curlist(qi), |
7117 qi->qf_curlist, | |
7118 NULL, // dir | 7121 NULL, // dir |
7119 fname, | 7122 fname, |
7120 NULL, | 7123 NULL, |
7121 0, | 7124 0, |
7122 line, | 7125 line, |
7308 return; | 7311 return; |
7309 } | 7312 } |
7310 } | 7313 } |
7311 | 7314 |
7312 // Jump to first match. | 7315 // Jump to first match. |
7313 if (!qf_list_empty(qi, qi->qf_curlist)) | 7316 if (!qf_list_empty(qf_get_curlist(qi))) |
7314 qf_jump(qi, 0, 0, FALSE); | 7317 qf_jump(qi, 0, 0, FALSE); |
7315 else | 7318 else |
7316 semsg(_(e_nomatch2), eap->arg); | 7319 semsg(_(e_nomatch2), eap->arg); |
7317 | 7320 |
7318 decr_quickfix_busy(); | 7321 decr_quickfix_busy(); |