comparison src/quickfix.c @ 11449:d2f00eb352b9 v8.0.0608

patch 8.0.0608: cannot manipulate other than the current quickfix list commit https://github.com/vim/vim/commit/a3921f48c6b31a035c80fda49925dd3b42df0dec Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 4 15:30:34 2017 +0200 patch 8.0.0608: cannot manipulate other than the current quickfix list Problem: Cannot manipulate other than the current quickfix list. Solution: Pass the list index to quickfix functions. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Jun 2017 15:45:04 +0200
parents 698ee9d4fe9f
children 46bbef0ee9a6
comparison
equal deleted inserted replaced
11448:acf70eb2caed 11449:d2f00eb352b9
116 }; 116 };
117 117
118 static efm_T *fmt_start = NULL; /* cached across qf_parse_line() calls */ 118 static efm_T *fmt_start = NULL; /* cached across qf_parse_line() calls */
119 119
120 static int qf_init_ext(qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title, char_u *enc); 120 static int qf_init_ext(qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title, char_u *enc);
121 static void qf_store_title(qf_info_T *qi, char_u *title); 121 static void qf_store_title(qf_info_T *qi, int qf_idx, char_u *title);
122 static void qf_new_list(qf_info_T *qi, char_u *qf_title); 122 static void qf_new_list(qf_info_T *qi, char_u *qf_title);
123 static void ll_free_all(qf_info_T **pqi); 123 static void ll_free_all(qf_info_T **pqi);
124 static int qf_add_entry(qf_info_T *qi, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid); 124 static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid);
125 static qf_info_T *ll_new_list(void); 125 static qf_info_T *ll_new_list(void);
126 static void qf_free(qf_info_T *qi, int idx); 126 static void qf_free(qf_info_T *qi, int idx);
127 static char_u *qf_types(int, int); 127 static char_u *qf_types(int, int);
128 static int qf_get_fnum(qf_info_T *qi, char_u *, char_u *); 128 static int qf_get_fnum(qf_info_T *qi, char_u *, char_u *);
129 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); 129 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack);
1275 goto qf_init_end; 1275 goto qf_init_end;
1276 if (status == QF_IGNORE_LINE) 1276 if (status == QF_IGNORE_LINE)
1277 continue; 1277 continue;
1278 1278
1279 if (qf_add_entry(qi, 1279 if (qf_add_entry(qi,
1280 qi->qf_curlist,
1280 qi->qf_directory, 1281 qi->qf_directory,
1281 (*fields.namebuf || qi->qf_directory != NULL) 1282 (*fields.namebuf || qi->qf_directory != NULL)
1282 ? fields.namebuf 1283 ? fields.namebuf
1283 : ((qi->qf_currfile != NULL && fields.valid) 1284 : ((qi->qf_currfile != NULL && fields.valid)
1284 ? qi->qf_currfile : (char_u *)NULL), 1285 ? qi->qf_currfile : (char_u *)NULL),
1342 1343
1343 return retval; 1344 return retval;
1344 } 1345 }
1345 1346
1346 static void 1347 static void
1347 qf_store_title(qf_info_T *qi, char_u *title) 1348 qf_store_title(qf_info_T *qi, int qf_idx, char_u *title)
1348 { 1349 {
1349 if (title != NULL) 1350 if (title != NULL)
1350 { 1351 {
1351 char_u *p = alloc((int)STRLEN(title) + 2); 1352 char_u *p = alloc((int)STRLEN(title) + 2);
1352 1353
1353 qi->qf_lists[qi->qf_curlist].qf_title = p; 1354 qi->qf_lists[qf_idx].qf_title = p;
1354 if (p != NULL) 1355 if (p != NULL)
1355 sprintf((char *)p, ":%s", (char *)title); 1356 sprintf((char *)p, ":%s", (char *)title);
1356 } 1357 }
1357 } 1358 }
1358 1359
1384 qi->qf_curlist = LISTCOUNT - 1; 1385 qi->qf_curlist = LISTCOUNT - 1;
1385 } 1386 }
1386 else 1387 else
1387 qi->qf_curlist = qi->qf_listcount++; 1388 qi->qf_curlist = qi->qf_listcount++;
1388 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); 1389 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T)));
1389 qf_store_title(qi, qf_title); 1390 qf_store_title(qi, qi->qf_curlist, qf_title);
1390 } 1391 }
1391 1392
1392 /* 1393 /*
1393 * Free a location list 1394 * Free a location list
1394 */ 1395 */
1436 * Returns OK or FAIL. 1437 * Returns OK or FAIL.
1437 */ 1438 */
1438 static int 1439 static int
1439 qf_add_entry( 1440 qf_add_entry(
1440 qf_info_T *qi, /* quickfix list */ 1441 qf_info_T *qi, /* quickfix list */
1442 int qf_idx, /* list index */
1441 char_u *dir, /* optional directory name */ 1443 char_u *dir, /* optional directory name */
1442 char_u *fname, /* file name or NULL */ 1444 char_u *fname, /* file name or NULL */
1443 int bufnum, /* buffer number or zero */ 1445 int bufnum, /* buffer number or zero */
1444 char_u *mesg, /* message */ 1446 char_u *mesg, /* message */
1445 long lnum, /* line number */ 1447 long lnum, /* line number */
1486 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ 1488 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */
1487 type = 0; 1489 type = 0;
1488 qfp->qf_type = type; 1490 qfp->qf_type = type;
1489 qfp->qf_valid = valid; 1491 qfp->qf_valid = valid;
1490 1492
1491 lastp = &qi->qf_lists[qi->qf_curlist].qf_last; 1493 lastp = &qi->qf_lists[qf_idx].qf_last;
1492 if (qi->qf_lists[qi->qf_curlist].qf_count == 0) 1494 if (qi->qf_lists[qf_idx].qf_count == 0)
1493 /* first element in the list */ 1495 /* first element in the list */
1494 { 1496 {
1495 qi->qf_lists[qi->qf_curlist].qf_start = qfp; 1497 qi->qf_lists[qf_idx].qf_start = qfp;
1496 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; 1498 qi->qf_lists[qf_idx].qf_ptr = qfp;
1497 qi->qf_lists[qi->qf_curlist].qf_index = 0; 1499 qi->qf_lists[qf_idx].qf_index = 0;
1498 qfp->qf_prev = NULL; 1500 qfp->qf_prev = NULL;
1499 } 1501 }
1500 else 1502 else
1501 { 1503 {
1502 qfp->qf_prev = *lastp; 1504 qfp->qf_prev = *lastp;
1503 (*lastp)->qf_next = qfp; 1505 (*lastp)->qf_next = qfp;
1504 } 1506 }
1505 qfp->qf_next = NULL; 1507 qfp->qf_next = NULL;
1506 qfp->qf_cleared = FALSE; 1508 qfp->qf_cleared = FALSE;
1507 *lastp = qfp; 1509 *lastp = qfp;
1508 ++qi->qf_lists[qi->qf_curlist].qf_count; 1510 ++qi->qf_lists[qf_idx].qf_count;
1509 if (qi->qf_lists[qi->qf_curlist].qf_index == 0 && qfp->qf_valid) 1511 if (qi->qf_lists[qf_idx].qf_index == 0 && qfp->qf_valid)
1510 /* first valid entry */ 1512 /* first valid entry */
1511 { 1513 {
1512 qi->qf_lists[qi->qf_curlist].qf_index = 1514 qi->qf_lists[qf_idx].qf_index =
1513 qi->qf_lists[qi->qf_curlist].qf_count; 1515 qi->qf_lists[qf_idx].qf_count;
1514 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; 1516 qi->qf_lists[qf_idx].qf_ptr = qfp;
1515 } 1517 }
1516 1518
1517 return OK; 1519 return OK;
1518 } 1520 }
1519 1521
1626 for (i = 0, from_qfp = from_qfl->qf_start; 1628 for (i = 0, from_qfp = from_qfl->qf_start;
1627 i < from_qfl->qf_count && from_qfp != NULL; 1629 i < from_qfl->qf_count && from_qfp != NULL;
1628 ++i, from_qfp = from_qfp->qf_next) 1630 ++i, from_qfp = from_qfp->qf_next)
1629 { 1631 {
1630 if (qf_add_entry(to->w_llist, 1632 if (qf_add_entry(to->w_llist,
1633 to->w_llist->qf_curlist,
1631 NULL, 1634 NULL,
1632 NULL, 1635 NULL,
1633 0, 1636 0,
1634 from_qfp->qf_text, 1637 from_qfp->qf_text,
1635 from_qfp->qf_lnum, 1638 from_qfp->qf_lnum,
4238 { 4241 {
4239 /* Pass the buffer number so that it gets used even for a 4242 /* Pass the buffer number so that it gets used even for a
4240 * dummy buffer, unless duplicate_name is set, then the 4243 * dummy buffer, unless duplicate_name is set, then the
4241 * buffer will be wiped out below. */ 4244 * buffer will be wiped out below. */
4242 if (qf_add_entry(qi, 4245 if (qf_add_entry(qi,
4246 qi->qf_curlist,
4243 NULL, /* dir */ 4247 NULL, /* dir */
4244 fname, 4248 fname,
4245 duplicate_name ? 0 : buf->b_fnum, 4249 duplicate_name ? 0 : buf->b_fnum,
4246 ml_get_buf(buf, 4250 ml_get_buf(buf,
4247 regmatch.startpos[0].lnum + lnum, FALSE), 4251 regmatch.startpos[0].lnum + lnum, FALSE),
4742 * a dictionary with item information. 4746 * a dictionary with item information.
4743 */ 4747 */
4744 static int 4748 static int
4745 qf_add_entries( 4749 qf_add_entries(
4746 qf_info_T *qi, 4750 qf_info_T *qi,
4751 int qf_idx,
4747 list_T *list, 4752 list_T *list,
4748 char_u *title, 4753 char_u *title,
4749 int action) 4754 int action)
4750 { 4755 {
4751 listitem_T *li; 4756 listitem_T *li;
4760 #endif 4765 #endif
4761 int valid, status; 4766 int valid, status;
4762 int retval = OK; 4767 int retval = OK;
4763 int did_bufnr_emsg = FALSE; 4768 int did_bufnr_emsg = FALSE;
4764 4769
4765 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) 4770 if (action == ' ' || qf_idx == qi->qf_listcount)
4771 {
4766 /* make place for a new list */ 4772 /* make place for a new list */
4767 qf_new_list(qi, title); 4773 qf_new_list(qi, title);
4774 qf_idx = qi->qf_curlist;
4775 }
4768 #ifdef FEAT_WINDOWS 4776 #ifdef FEAT_WINDOWS
4769 else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0) 4777 else if (action == 'a' && qi->qf_lists[qf_idx].qf_count > 0)
4770 /* Adding to existing list, use last entry. */ 4778 /* Adding to existing list, use last entry. */
4771 old_last = qi->qf_lists[qi->qf_curlist].qf_last; 4779 old_last = qi->qf_lists[qf_idx].qf_last;
4772 #endif 4780 #endif
4773 else if (action == 'r') 4781 else if (action == 'r')
4774 { 4782 {
4775 qf_free(qi, qi->qf_curlist); 4783 qf_free(qi, qf_idx);
4776 qf_store_title(qi, title); 4784 qf_store_title(qi, qf_idx, title);
4777 } 4785 }
4778 4786
4779 for (li = list->lv_first; li != NULL; li = li->li_next) 4787 for (li = list->lv_first; li != NULL; li = li->li_next)
4780 { 4788 {
4781 if (li->li_tv.v_type != VAR_DICT) 4789 if (li->li_tv.v_type != VAR_DICT)
4817 /* If the 'valid' field is present it overrules the detected value. */ 4825 /* If the 'valid' field is present it overrules the detected value. */
4818 if ((dict_find(d, (char_u *)"valid", -1)) != NULL) 4826 if ((dict_find(d, (char_u *)"valid", -1)) != NULL)
4819 valid = (int)get_dict_number(d, (char_u *)"valid"); 4827 valid = (int)get_dict_number(d, (char_u *)"valid");
4820 4828
4821 status = qf_add_entry(qi, 4829 status = qf_add_entry(qi,
4830 qf_idx,
4822 NULL, /* dir */ 4831 NULL, /* dir */
4823 filename, 4832 filename,
4824 bufnum, 4833 bufnum,
4825 text, 4834 text,
4826 lnum, 4835 lnum,
4841 retval = FAIL; 4850 retval = FAIL;
4842 break; 4851 break;
4843 } 4852 }
4844 } 4853 }
4845 4854
4846 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) 4855 if (qi->qf_lists[qf_idx].qf_index == 0)
4847 /* no valid entry */ 4856 /* no valid entry */
4848 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; 4857 qi->qf_lists[qf_idx].qf_nonevalid = TRUE;
4849 else 4858 else
4850 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; 4859 qi->qf_lists[qf_idx].qf_nonevalid = FALSE;
4851 if (action != 'a') 4860 if (action != 'a')
4852 { 4861 {
4853 qi->qf_lists[qi->qf_curlist].qf_ptr = 4862 qi->qf_lists[qf_idx].qf_ptr =
4854 qi->qf_lists[qi->qf_curlist].qf_start; 4863 qi->qf_lists[qf_idx].qf_start;
4855 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) 4864 if (qi->qf_lists[qf_idx].qf_count > 0)
4856 qi->qf_lists[qi->qf_curlist].qf_index = 1; 4865 qi->qf_lists[qf_idx].qf_index = 1;
4857 } 4866 }
4858 4867
4859 #ifdef FEAT_WINDOWS 4868 #ifdef FEAT_WINDOWS
4860 /* Don't update the cursor in quickfix window when appending entries */ 4869 /* Don't update the cursor in quickfix window when appending entries */
4861 qf_update_buffer(qi, old_last); 4870 qf_update_buffer(qi, old_last);
5022 qf_free_stack(wp, qi); 5031 qf_free_stack(wp, qi);
5023 } 5032 }
5024 else if (what != NULL) 5033 else if (what != NULL)
5025 retval = qf_set_properties(qi, what, action); 5034 retval = qf_set_properties(qi, what, action);
5026 else 5035 else
5027 retval = qf_add_entries(qi, list, title, action); 5036 retval = qf_add_entries(qi, qi->qf_curlist, list, title, action);
5028 5037
5029 return retval; 5038 return retval;
5030 } 5039 }
5031 5040
5032 static int 5041 static int
5385 /* remove trailing CR, LF, spaces, etc. */ 5394 /* remove trailing CR, LF, spaces, etc. */
5386 while (l > 0 && line[l - 1] <= ' ') 5395 while (l > 0 && line[l - 1] <= ' ')
5387 line[--l] = NUL; 5396 line[--l] = NUL;
5388 5397
5389 if (qf_add_entry(qi, 5398 if (qf_add_entry(qi,
5399 qi->qf_curlist,
5390 NULL, /* dir */ 5400 NULL, /* dir */
5391 fnames[fi], 5401 fnames[fi],
5392 0, 5402 0,
5393 line, 5403 line,
5394 lnum, 5404 lnum,