Mercurial > vim
comparison src/quickfix.c @ 9850:67781bb0a61a v7.4.2200
commit https://github.com/vim/vim/commit/d823fa910cca43fec3c31c030ee908a14c272640
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 12 16:29:27 2016 +0200
patch 7.4.2200
Problem: Cannot get all information about a quickfix list.
Solution: Add an optional argument to get/set loc/qf list(). (Yegappan
Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 12 Aug 2016 16:30:07 +0200 |
parents | 6818e3c96473 |
children | adef2643c576 |
comparison
equal
deleted
inserted
replaced
9849:6efcd77f235a | 9850:67781bb0a61a |
---|---|
3139 | 3139 |
3140 return NULL; | 3140 return NULL; |
3141 } | 3141 } |
3142 | 3142 |
3143 /* | 3143 /* |
3144 * Update the w:quickfix_title variable in the quickfix/location list window | |
3145 */ | |
3146 static void | |
3147 qf_update_win_titlevar(qf_info_T *qi) | |
3148 { | |
3149 win_T *win; | |
3150 win_T *curwin_save; | |
3151 | |
3152 if ((win = qf_find_win(qi)) != NULL) | |
3153 { | |
3154 curwin_save = curwin; | |
3155 curwin = win; | |
3156 qf_set_title_var(qi); | |
3157 curwin = curwin_save; | |
3158 } | |
3159 } | |
3160 | |
3161 /* | |
3144 * Find the quickfix buffer. If it exists, update the contents. | 3162 * Find the quickfix buffer. If it exists, update the contents. |
3145 */ | 3163 */ |
3146 static void | 3164 static void |
3147 qf_update_buffer(qf_info_T *qi, qfline_T *old_last) | 3165 qf_update_buffer(qf_info_T *qi, qfline_T *old_last) |
3148 { | 3166 { |
3149 buf_T *buf; | 3167 buf_T *buf; |
3150 win_T *win; | 3168 win_T *win; |
3151 win_T *curwin_save; | |
3152 aco_save_T aco; | 3169 aco_save_T aco; |
3153 | 3170 |
3154 /* Check if a buffer for the quickfix list exists. Update it. */ | 3171 /* Check if a buffer for the quickfix list exists. Update it. */ |
3155 buf = qf_find_buf(qi); | 3172 buf = qf_find_buf(qi); |
3156 if (buf != NULL) | 3173 if (buf != NULL) |
3159 | 3176 |
3160 if (old_last == NULL) | 3177 if (old_last == NULL) |
3161 /* set curwin/curbuf to buf and save a few things */ | 3178 /* set curwin/curbuf to buf and save a few things */ |
3162 aucmd_prepbuf(&aco, buf); | 3179 aucmd_prepbuf(&aco, buf); |
3163 | 3180 |
3164 if ((win = qf_find_win(qi)) != NULL) | 3181 qf_update_win_titlevar(qi); |
3165 { | |
3166 curwin_save = curwin; | |
3167 curwin = win; | |
3168 qf_set_title_var(qi); | |
3169 curwin = curwin_save; | |
3170 } | |
3171 | 3182 |
3172 qf_fill_buffer(qi, buf, old_last); | 3183 qf_fill_buffer(qi, buf, old_last); |
3173 | 3184 |
3174 if (old_last == NULL) | 3185 if (old_last == NULL) |
3175 { | 3186 { |
4530 } | 4541 } |
4531 | 4542 |
4532 #if defined(FEAT_EVAL) || defined(PROTO) | 4543 #if defined(FEAT_EVAL) || defined(PROTO) |
4533 /* | 4544 /* |
4534 * Add each quickfix error to list "list" as a dictionary. | 4545 * Add each quickfix error to list "list" as a dictionary. |
4546 * If qf_idx is -1, use the current list. Otherwise, use the specified list. | |
4535 */ | 4547 */ |
4536 int | 4548 int |
4537 get_errorlist(win_T *wp, list_T *list) | 4549 get_errorlist(win_T *wp, int qf_idx, list_T *list) |
4538 { | 4550 { |
4539 qf_info_T *qi = &ql_info; | 4551 qf_info_T *qi = &ql_info; |
4540 dict_T *dict; | 4552 dict_T *dict; |
4541 char_u buf[2]; | 4553 char_u buf[2]; |
4542 qfline_T *qfp; | 4554 qfline_T *qfp; |
4548 qi = GET_LOC_LIST(wp); | 4560 qi = GET_LOC_LIST(wp); |
4549 if (qi == NULL) | 4561 if (qi == NULL) |
4550 return FAIL; | 4562 return FAIL; |
4551 } | 4563 } |
4552 | 4564 |
4553 if (qi->qf_curlist >= qi->qf_listcount | 4565 if (qf_idx == -1) |
4554 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | 4566 qf_idx = qi->qf_curlist; |
4567 | |
4568 if (qf_idx >= qi->qf_listcount | |
4569 || qi->qf_lists[qf_idx].qf_count == 0) | |
4555 return FAIL; | 4570 return FAIL; |
4556 | 4571 |
4557 qfp = qi->qf_lists[qi->qf_curlist].qf_start; | 4572 qfp = qi->qf_lists[qf_idx].qf_start; |
4558 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i) | 4573 for (i = 1; !got_int && i <= qi->qf_lists[qf_idx].qf_count; ++i) |
4559 { | 4574 { |
4560 /* Handle entries with a non-existing buffer number. */ | 4575 /* Handle entries with a non-existing buffer number. */ |
4561 bufnum = qfp->qf_fnum; | 4576 bufnum = qfp->qf_fnum; |
4562 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | 4577 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) |
4563 bufnum = 0; | 4578 bufnum = 0; |
4588 } | 4603 } |
4589 return OK; | 4604 return OK; |
4590 } | 4605 } |
4591 | 4606 |
4592 /* | 4607 /* |
4593 * Populate the quickfix list with the items supplied in the list | 4608 * Flags used by getqflist()/getloclist() to determine which fields to return. |
4594 * of dictionaries. "title" will be copied to w:quickfix_title. | 4609 */ |
4595 * "action" is 'a' for add, 'r' for replace. Otherwise create a new list. | 4610 enum { |
4611 QF_GETLIST_NONE = 0x0, | |
4612 QF_GETLIST_TITLE = 0x1, | |
4613 QF_GETLIST_ITEMS = 0x2, | |
4614 QF_GETLIST_NR = 0x4, | |
4615 QF_GETLIST_WINID = 0x8, | |
4616 QF_GETLIST_ALL = 0xFF | |
4617 }; | |
4618 | |
4619 /* | |
4620 * Return quickfix/location list details (title) as a | |
4621 * dictionary. 'what' contains the details to return. If 'list_idx' is -1, | |
4622 * then current list is used. Otherwise the specified list is used. | |
4596 */ | 4623 */ |
4597 int | 4624 int |
4598 set_errorlist( | 4625 get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) |
4599 win_T *wp, | 4626 { |
4600 list_T *list, | 4627 qf_info_T *qi = &ql_info; |
4601 int action, | 4628 int status = OK; |
4602 char_u *title) | 4629 int qf_idx; |
4630 dictitem_T *di; | |
4631 int flags = QF_GETLIST_NONE; | |
4632 | |
4633 if (wp != NULL) | |
4634 { | |
4635 qi = GET_LOC_LIST(wp); | |
4636 if (qi == NULL) | |
4637 return FAIL; | |
4638 } | |
4639 | |
4640 qf_idx = qi->qf_curlist; /* default is the current list */ | |
4641 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) | |
4642 { | |
4643 /* Use the specified quickfix/location list */ | |
4644 if (di->di_tv.v_type == VAR_NUMBER) | |
4645 { | |
4646 qf_idx = di->di_tv.vval.v_number - 1; | |
4647 if (qf_idx < 0 || qf_idx >= qi->qf_listcount) | |
4648 return FAIL; | |
4649 flags |= QF_GETLIST_NR; | |
4650 } | |
4651 else | |
4652 return FAIL; | |
4653 } | |
4654 | |
4655 if (dict_find(what, (char_u *)"all", -1) != NULL) | |
4656 flags |= QF_GETLIST_ALL; | |
4657 | |
4658 if (dict_find(what, (char_u *)"title", -1) != NULL) | |
4659 flags |= QF_GETLIST_TITLE; | |
4660 | |
4661 if (dict_find(what, (char_u *)"winid", -1) != NULL) | |
4662 flags |= QF_GETLIST_WINID; | |
4663 | |
4664 if (flags & QF_GETLIST_TITLE) | |
4665 { | |
4666 char_u *t; | |
4667 t = qi->qf_lists[qf_idx].qf_title; | |
4668 if (t == NULL) | |
4669 t = (char_u *)""; | |
4670 status = dict_add_nr_str(retdict, "title", 0L, t); | |
4671 } | |
4672 if ((status == OK) && (flags & QF_GETLIST_NR)) | |
4673 status = dict_add_nr_str(retdict, "nr", qf_idx + 1, NULL); | |
4674 if ((status == OK) && (flags & QF_GETLIST_WINID)) | |
4675 { | |
4676 win_T *win; | |
4677 win = qf_find_win(qi); | |
4678 if (win != NULL) | |
4679 status = dict_add_nr_str(retdict, "winid", win->w_id, NULL); | |
4680 } | |
4681 | |
4682 return status; | |
4683 } | |
4684 | |
4685 /* | |
4686 * Add list of entries to quickfix/location list. Each list entry is | |
4687 * a dictionary with item information. | |
4688 */ | |
4689 static int | |
4690 qf_add_entries( | |
4691 qf_info_T *qi, | |
4692 list_T *list, | |
4693 char_u *title, | |
4694 int action) | |
4603 { | 4695 { |
4604 listitem_T *li; | 4696 listitem_T *li; |
4605 dict_T *d; | 4697 dict_T *d; |
4606 char_u *filename, *pattern, *text, *type; | 4698 char_u *filename, *pattern, *text, *type; |
4607 int bufnum; | 4699 int bufnum; |
4611 #ifdef FEAT_WINDOWS | 4703 #ifdef FEAT_WINDOWS |
4612 qfline_T *old_last = NULL; | 4704 qfline_T *old_last = NULL; |
4613 #endif | 4705 #endif |
4614 int valid, status; | 4706 int valid, status; |
4615 int retval = OK; | 4707 int retval = OK; |
4616 qf_info_T *qi = &ql_info; | |
4617 int did_bufnr_emsg = FALSE; | 4708 int did_bufnr_emsg = FALSE; |
4618 | |
4619 if (wp != NULL) | |
4620 { | |
4621 qi = ll_get_or_alloc_list(wp); | |
4622 if (qi == NULL) | |
4623 return FAIL; | |
4624 } | |
4625 | 4709 |
4626 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) | 4710 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) |
4627 /* make place for a new list */ | 4711 /* make place for a new list */ |
4628 qf_new_list(qi, title); | 4712 qf_new_list(qi, title); |
4629 #ifdef FEAT_WINDOWS | 4713 #ifdef FEAT_WINDOWS |
4714 | 4798 |
4715 #ifdef FEAT_WINDOWS | 4799 #ifdef FEAT_WINDOWS |
4716 /* Don't update the cursor in quickfix window when appending entries */ | 4800 /* Don't update the cursor in quickfix window when appending entries */ |
4717 qf_update_buffer(qi, old_last); | 4801 qf_update_buffer(qi, old_last); |
4718 #endif | 4802 #endif |
4803 | |
4804 return retval; | |
4805 } | |
4806 | |
4807 static int | |
4808 qf_set_properties(qf_info_T *qi, dict_T *what) | |
4809 { | |
4810 dictitem_T *di; | |
4811 int retval = FAIL; | |
4812 int qf_idx; | |
4813 | |
4814 qf_idx = qi->qf_curlist; /* default is the current list */ | |
4815 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) | |
4816 { | |
4817 /* Use the specified quickfix/location list */ | |
4818 if (di->di_tv.v_type == VAR_NUMBER) | |
4819 { | |
4820 qf_idx = di->di_tv.vval.v_number - 1; | |
4821 if (qf_idx < 0 || qf_idx >= qi->qf_listcount) | |
4822 return FAIL; | |
4823 } | |
4824 else | |
4825 return FAIL; | |
4826 } | |
4827 | |
4828 if ((di = dict_find(what, (char_u *)"title", -1)) != NULL) | |
4829 { | |
4830 if (di->di_tv.v_type == VAR_STRING) | |
4831 { | |
4832 vim_free(qi->qf_lists[qf_idx].qf_title); | |
4833 qi->qf_lists[qf_idx].qf_title = | |
4834 get_dict_string(what, (char_u *)"title", TRUE); | |
4835 if (qf_idx == qi->qf_curlist) | |
4836 qf_update_win_titlevar(qi); | |
4837 retval = OK; | |
4838 } | |
4839 } | |
4840 | |
4841 return retval; | |
4842 } | |
4843 | |
4844 /* | |
4845 * Populate the quickfix list with the items supplied in the list | |
4846 * of dictionaries. "title" will be copied to w:quickfix_title. | |
4847 * "action" is 'a' for add, 'r' for replace. Otherwise create a new list. | |
4848 */ | |
4849 int | |
4850 set_errorlist( | |
4851 win_T *wp, | |
4852 list_T *list, | |
4853 int action, | |
4854 char_u *title, | |
4855 dict_T *what) | |
4856 { | |
4857 qf_info_T *qi = &ql_info; | |
4858 int retval = OK; | |
4859 | |
4860 if (wp != NULL) | |
4861 { | |
4862 qi = ll_get_or_alloc_list(wp); | |
4863 if (qi == NULL) | |
4864 return FAIL; | |
4865 } | |
4866 | |
4867 if (what != NULL) | |
4868 retval = qf_set_properties(qi, what); | |
4869 else | |
4870 retval = qf_add_entries(qi, list, title, action); | |
4719 | 4871 |
4720 return retval; | 4872 return retval; |
4721 } | 4873 } |
4722 #endif | 4874 #endif |
4723 | 4875 |