Mercurial > vim
comparison src/quickfix.c @ 16001:416e067411ab v8.1.1006
patch 8.1.1006: repeated code in quickfix support
commit https://github.com/vim/vim/commit/4aa47b28f453b40d3b93ef209a3447c62b6f855b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 13 06:51:53 2019 +0100
patch 8.1.1006: repeated code in quickfix support
Problem: Repeated code in quickfix support.
Solution: Move code to functions. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4091)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 Mar 2019 07:00:07 +0100 |
parents | f376cd250b07 |
children | 096b8ccd855e |
comparison
equal
deleted
inserted
replaced
16000:4a614fe36b8d | 16001:416e067411ab |
---|---|
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); |
172 static win_T *qf_find_win(qf_info_T *qi); | 172 static win_T *qf_find_win(qf_info_T *qi); |
173 static buf_T *qf_find_buf(qf_info_T *qi); | 173 static buf_T *qf_find_buf(qf_info_T *qi); |
174 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); | 174 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); |
175 static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last); | 175 static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last); |
176 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); | 176 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); |
177 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); | 177 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); |
178 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); | 178 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); |
179 static qf_info_T *ll_get_or_alloc_list(win_T *); | 179 static qf_info_T *ll_get_or_alloc_list(win_T *); |
180 | 180 |
1801 vim_snprintf((char *)qftitle_str, IOSIZE, ":%s", (char *)cmd); | 1801 vim_snprintf((char *)qftitle_str, IOSIZE, ":%s", (char *)cmd); |
1802 return qftitle_str; | 1802 return qftitle_str; |
1803 } | 1803 } |
1804 | 1804 |
1805 /* | 1805 /* |
1806 * Return a pointer to the current list in the specified quickfix stack | |
1807 */ | |
1808 static qf_list_T * | |
1809 qf_get_curlist(qf_info_T *qi) | |
1810 { | |
1811 return &qi->qf_lists[qi->qf_curlist]; | |
1812 } | |
1813 | |
1814 /* | |
1806 * Prepare for adding a new quickfix list. If the current list is in the | 1815 * Prepare for adding a new quickfix list. If the current list is in the |
1807 * middle of the stack, then all the following lists are freed and then | 1816 * middle of the stack, then all the following lists are freed and then |
1808 * the new list is added. | 1817 * the new list is added. |
1809 */ | 1818 */ |
1810 static void | 1819 static void |
1828 qi->qf_lists[i - 1] = qi->qf_lists[i]; | 1837 qi->qf_lists[i - 1] = qi->qf_lists[i]; |
1829 qi->qf_curlist = LISTCOUNT - 1; | 1838 qi->qf_curlist = LISTCOUNT - 1; |
1830 } | 1839 } |
1831 else | 1840 else |
1832 qi->qf_curlist = qi->qf_listcount++; | 1841 qi->qf_curlist = qi->qf_listcount++; |
1833 qfl = &qi->qf_lists[qi->qf_curlist]; | 1842 qfl = qf_get_curlist(qi); |
1834 vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T))); | 1843 vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T))); |
1835 qf_store_title(qfl, qf_title); | 1844 qf_store_title(qfl, qf_title); |
1836 qfl->qfl_type = qi->qfl_type; | 1845 qfl->qfl_type = qi->qfl_type; |
1837 qfl->qf_id = ++last_qf_id; | 1846 qfl->qf_id = ++last_qf_id; |
1838 } | 1847 } |
2724 | 2733 |
2725 return NULL; | 2734 return NULL; |
2726 } | 2735 } |
2727 | 2736 |
2728 /* | 2737 /* |
2738 * Set the location list for the specified window to 'qi'. | |
2739 */ | |
2740 static void | |
2741 win_set_loclist(win_T *wp, qf_info_T *qi) | |
2742 { | |
2743 wp->w_llist = qi; | |
2744 qi->qf_refcount++; | |
2745 } | |
2746 | |
2747 /* | |
2729 * Find a help window or open one. If 'newwin' is TRUE, then open a new help | 2748 * Find a help window or open one. If 'newwin' is TRUE, then open a new help |
2730 * window. | 2749 * window. |
2731 */ | 2750 */ |
2732 static int | 2751 static int |
2733 jump_to_help_window(qf_info_T *qi, int newwin, int *opened_window) | 2752 jump_to_help_window(qf_info_T *qi, int newwin, int *opened_window) |
2764 | 2783 |
2765 // When using location list, the new window should use the supplied | 2784 // When using location list, the new window should use the supplied |
2766 // location list. If the user asks to open a new window, then the new | 2785 // location list. If the user asks to open a new window, then the new |
2767 // window will get a copy of the location list. | 2786 // window will get a copy of the location list. |
2768 if (IS_LL_STACK(qi) && !newwin) | 2787 if (IS_LL_STACK(qi) && !newwin) |
2769 { | 2788 win_set_loclist(curwin, qi); |
2770 curwin->w_llist = qi; | |
2771 qi->qf_refcount++; | |
2772 } | |
2773 } | 2789 } |
2774 | 2790 |
2775 if (!p_im) | 2791 if (!p_im) |
2776 restart_edit = 0; // don't want insert mode in help file | 2792 restart_edit = 0; // don't want insert mode in help file |
2777 | 2793 |
2846 return FAIL; // not enough room for window | 2862 return FAIL; // not enough room for window |
2847 p_swb = empty_option; // don't split again | 2863 p_swb = empty_option; // don't split again |
2848 swb_flags = 0; | 2864 swb_flags = 0; |
2849 RESET_BINDING(curwin); | 2865 RESET_BINDING(curwin); |
2850 if (ll_ref != NULL) | 2866 if (ll_ref != NULL) |
2851 { | |
2852 // The new window should use the location list from the | 2867 // The new window should use the location list from the |
2853 // location list window | 2868 // location list window |
2854 curwin->w_llist = ll_ref; | 2869 win_set_loclist(curwin, ll_ref); |
2855 ll_ref->qf_refcount++; | |
2856 } | |
2857 return OK; | 2870 return OK; |
2858 } | 2871 } |
2859 | 2872 |
2860 /* | 2873 /* |
2861 * Go to a window that shows the right buffer. If the window is not found, go | 2874 * Go to a window that shows the right buffer. If the window is not found, go |
2892 win_goto(win); | 2905 win_goto(win); |
2893 | 2906 |
2894 // If the location list for the window is not set, then set it | 2907 // If the location list for the window is not set, then set it |
2895 // to the location list from the location window | 2908 // to the location list from the location window |
2896 if (win->w_llist == NULL) | 2909 if (win->w_llist == NULL) |
2897 { | 2910 win_set_loclist(win, ll_ref); |
2898 win->w_llist = ll_ref; | |
2899 if (ll_ref != NULL) | |
2900 ll_ref->qf_refcount++; | |
2901 } | |
2902 } | 2911 } |
2903 | 2912 |
2904 /* | 2913 /* |
2905 * Go to a window that contains the specified buffer 'qf_fnum'. If a window is | 2914 * Go to a window that contains the specified buffer 'qf_fnum'. If a window is |
2906 * not found, then go to the window just above the quickfix window. This is | 2915 * not found, then go to the window just above the quickfix window. This is |
3020 qfline_T *qf_ptr, | 3029 qfline_T *qf_ptr, |
3021 int forceit, | 3030 int forceit, |
3022 int prev_winid, | 3031 int prev_winid, |
3023 int *opened_window) | 3032 int *opened_window) |
3024 { | 3033 { |
3025 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; | 3034 qf_list_T *qfl = qf_get_curlist(qi); |
3026 qfltype_T qfl_type = qfl->qfl_type; | 3035 qfltype_T qfl_type = qfl->qfl_type; |
3027 int retval = OK; | 3036 int retval = OK; |
3028 int old_qf_curlist = qi->qf_curlist; | 3037 int old_qf_curlist = qi->qf_curlist; |
3029 int save_qfid = qfl->qf_id; | 3038 int save_qfid = qfl->qf_id; |
3030 | 3039 |
3144 // Update the screen before showing the message, unless the screen | 3153 // Update the screen before showing the message, unless the screen |
3145 // scrolled up. | 3154 // scrolled up. |
3146 if (!msg_scrolled) | 3155 if (!msg_scrolled) |
3147 update_topline_redraw(); | 3156 update_topline_redraw(); |
3148 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, | 3157 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, |
3149 qi->qf_lists[qi->qf_curlist].qf_count, | 3158 qf_get_curlist(qi)->qf_count, |
3150 qf_ptr->qf_cleared ? _(" (line deleted)") : "", | 3159 qf_ptr->qf_cleared ? _(" (line deleted)") : "", |
3151 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); | 3160 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); |
3152 // Add the message, skipping leading whitespace and newlines. | 3161 // Add the message, skipping leading whitespace and newlines. |
3153 len = (int)STRLEN(IObuff); | 3162 len = (int)STRLEN(IObuff); |
3154 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); | 3163 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); |
3309 return; | 3318 return; |
3310 } | 3319 } |
3311 | 3320 |
3312 incr_quickfix_busy(); | 3321 incr_quickfix_busy(); |
3313 | 3322 |
3314 qfl = &qi->qf_lists[qi->qf_curlist]; | 3323 qfl = qf_get_curlist(qi); |
3315 | 3324 |
3316 qf_ptr = qfl->qf_ptr; | 3325 qf_ptr = qfl->qf_ptr; |
3317 old_qf_ptr = qf_ptr; | 3326 old_qf_ptr = qf_ptr; |
3318 qf_index = qfl->qf_index; | 3327 qf_index = qfl->qf_index; |
3319 old_qf_index = qf_index; | 3328 old_qf_index = qf_index; |
3510 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) | 3519 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) |
3511 { | 3520 { |
3512 emsg(_(e_trailing)); | 3521 emsg(_(e_trailing)); |
3513 return; | 3522 return; |
3514 } | 3523 } |
3515 qfl = &qi->qf_lists[qi->qf_curlist]; | 3524 qfl = qf_get_curlist(qi); |
3516 if (plus) | 3525 if (plus) |
3517 { | 3526 { |
3518 i = qfl->qf_index; | 3527 i = qfl->qf_index; |
3519 idx2 = i + idx1; | 3528 idx2 = i + idx1; |
3520 idx1 = i; | 3529 idx1 = i; |
3898 qi = GET_LOC_LIST(curwin); | 3907 qi = GET_LOC_LIST(curwin); |
3899 if (qi == NULL) | 3908 if (qi == NULL) |
3900 return; | 3909 return; |
3901 } | 3910 } |
3902 | 3911 |
3903 qfl = &qi->qf_lists[qi->qf_curlist]; | 3912 qfl = qf_get_curlist(qi); |
3904 | 3913 |
3905 // Look for an existing quickfix window. | 3914 // Look for an existing quickfix window. |
3906 win = qf_find_win(qi); | 3915 win = qf_find_win(qi); |
3907 | 3916 |
3908 // If a quickfix window is open but we have no errors to display, | 3917 // If a quickfix window is open but we have no errors to display, |
4118 { | 4127 { |
4119 decr_quickfix_busy(); | 4128 decr_quickfix_busy(); |
4120 return; | 4129 return; |
4121 } | 4130 } |
4122 | 4131 |
4123 qfl = &qi->qf_lists[qi->qf_curlist]; | 4132 qfl = qf_get_curlist(qi); |
4124 qf_set_title_var(qfl); | 4133 qf_set_title_var(qfl); |
4125 // Save the current index here, as updating the quickfix buffer may free | 4134 // Save the current index here, as updating the quickfix buffer may free |
4126 // the quickfix list | 4135 // the quickfix list |
4127 lnum = qfl->qf_index; | 4136 lnum = qfl->qf_index; |
4128 | 4137 |
4129 // Fill the buffer with the quickfix list. | 4138 // Fill the buffer with the quickfix list. |
4130 qf_fill_buffer(qi, curbuf, NULL); | 4139 qf_fill_buffer(qfl, curbuf, NULL); |
4131 | 4140 |
4132 decr_quickfix_busy(); | 4141 decr_quickfix_busy(); |
4133 | 4142 |
4134 curwin->w_cursor.lnum = lnum; | 4143 curwin->w_cursor.lnum = lnum; |
4135 curwin->w_cursor.col = 0; | 4144 curwin->w_cursor.col = 0; |
4193 | 4202 |
4194 if (IS_LL_WINDOW(wp)) | 4203 if (IS_LL_WINDOW(wp)) |
4195 // In the location list window, use the referenced location list | 4204 // In the location list window, use the referenced location list |
4196 qi = wp->w_llist_ref; | 4205 qi = wp->w_llist_ref; |
4197 | 4206 |
4198 return qi->qf_lists[qi->qf_curlist].qf_index; | 4207 return qf_get_curlist(qi)->qf_index; |
4199 } | 4208 } |
4200 | 4209 |
4201 /* | 4210 /* |
4202 * Update the cursor position in the quickfix window to the current error. | 4211 * Update the cursor position in the quickfix window to the current error. |
4203 * Return TRUE if there is a quickfix window. | 4212 * Return TRUE if there is a quickfix window. |
4206 qf_win_pos_update( | 4215 qf_win_pos_update( |
4207 qf_info_T *qi, | 4216 qf_info_T *qi, |
4208 int old_qf_index) // previous qf_index or zero | 4217 int old_qf_index) // previous qf_index or zero |
4209 { | 4218 { |
4210 win_T *win; | 4219 win_T *win; |
4211 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index; | 4220 int qf_index = qf_get_curlist(qi)->qf_index; |
4212 | 4221 |
4213 // Put the cursor on the current error in the quickfix window, so that | 4222 // Put the cursor on the current error in the quickfix window, so that |
4214 // it's viewable. | 4223 // it's viewable. |
4215 win = qf_find_win(qi); | 4224 win = qf_find_win(qi); |
4216 if (win != NULL | 4225 if (win != NULL |
4304 | 4313 |
4305 if ((win = qf_find_win(qi)) != NULL) | 4314 if ((win = qf_find_win(qi)) != NULL) |
4306 { | 4315 { |
4307 curwin_save = curwin; | 4316 curwin_save = curwin; |
4308 curwin = win; | 4317 curwin = win; |
4309 qf_set_title_var(&qi->qf_lists[qi->qf_curlist]); | 4318 qf_set_title_var(qf_get_curlist(qi)); |
4310 curwin = curwin_save; | 4319 curwin = curwin_save; |
4311 } | 4320 } |
4312 } | 4321 } |
4313 | 4322 |
4314 /* | 4323 /* |
4331 // set curwin/curbuf to buf and save a few things | 4340 // set curwin/curbuf to buf and save a few things |
4332 aucmd_prepbuf(&aco, buf); | 4341 aucmd_prepbuf(&aco, buf); |
4333 | 4342 |
4334 qf_update_win_titlevar(qi); | 4343 qf_update_win_titlevar(qi); |
4335 | 4344 |
4336 qf_fill_buffer(qi, buf, old_last); | 4345 qf_fill_buffer(qf_get_curlist(qi), buf, old_last); |
4337 ++CHANGEDTICK(buf); | 4346 ++CHANGEDTICK(buf); |
4338 | 4347 |
4339 if (old_last == NULL) | 4348 if (old_last == NULL) |
4340 { | 4349 { |
4341 (void)qf_win_pos_update(qi, 0); | 4350 (void)qf_win_pos_update(qi, 0); |
4431 * If "old_last" is not NULL append the items after this one. | 4440 * If "old_last" is not NULL append the items after this one. |
4432 * When "old_last" is NULL then "buf" must equal "curbuf"! Because | 4441 * When "old_last" is NULL then "buf" must equal "curbuf"! Because |
4433 * ml_delete() is used and autocommands will be triggered. | 4442 * ml_delete() is used and autocommands will be triggered. |
4434 */ | 4443 */ |
4435 static void | 4444 static void |
4436 qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last) | 4445 qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last) |
4437 { | 4446 { |
4438 linenr_T lnum; | 4447 linenr_T lnum; |
4439 qfline_T *qfp; | 4448 qfline_T *qfp; |
4440 int old_KeyTyped = KeyTyped; | 4449 int old_KeyTyped = KeyTyped; |
4441 | 4450 |
4451 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) | 4460 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) |
4452 (void)ml_delete((linenr_T)1, FALSE); | 4461 (void)ml_delete((linenr_T)1, FALSE); |
4453 } | 4462 } |
4454 | 4463 |
4455 // Check if there is anything to display | 4464 // Check if there is anything to display |
4456 if (!qf_stack_empty(qi)) | 4465 if (qfl != NULL) |
4457 { | 4466 { |
4458 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; | |
4459 char_u dirname[MAXPATHL]; | 4467 char_u dirname[MAXPATHL]; |
4460 | 4468 |
4461 *dirname = NUL; | 4469 *dirname = NUL; |
4462 | 4470 |
4463 // Add one line for each error | 4471 // Add one line for each error |
4549 static int | 4557 static int |
4550 qf_restore_list(qf_info_T *qi, int_u save_qfid) | 4558 qf_restore_list(qf_info_T *qi, int_u save_qfid) |
4551 { | 4559 { |
4552 int curlist; | 4560 int curlist; |
4553 | 4561 |
4554 if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) | 4562 if (qf_get_curlist(qi)->qf_id != save_qfid) |
4555 { | 4563 { |
4556 curlist = qf_id2nr(qi, save_qfid); | 4564 curlist = qf_id2nr(qi, save_qfid); |
4557 if (curlist < 0) | 4565 if (curlist < 0) |
4558 // list is not present | 4566 // list is not present |
4559 return FAIL; | 4567 return FAIL; |
4767 qi = GET_LOC_LIST(wp); | 4775 qi = GET_LOC_LIST(wp); |
4768 if (qi == NULL) | 4776 if (qi == NULL) |
4769 goto cleanup; | 4777 goto cleanup; |
4770 } | 4778 } |
4771 if (res >= 0) | 4779 if (res >= 0) |
4772 qf_list_changed(&qi->qf_lists[qi->qf_curlist]); | 4780 qf_list_changed(qf_get_curlist(qi)); |
4773 | 4781 |
4774 // Remember the current quickfix list identifier, so that we can | 4782 // Remember the current quickfix list identifier, so that we can |
4775 // check for autocommands changing the current quickfix list. | 4783 // check for autocommands changing the current quickfix list. |
4776 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 4784 save_qfid = qf_get_curlist(qi)->qf_id; |
4777 if (au_name != NULL) | 4785 if (au_name != NULL) |
4778 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | 4786 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
4779 curbuf->b_fname, TRUE, curbuf); | 4787 curbuf->b_fname, TRUE, curbuf); |
4780 if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid)) | 4788 if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid)) |
4781 // display the first error | 4789 // display the first error |
4806 qi = GET_LOC_LIST(curwin); | 4814 qi = GET_LOC_LIST(curwin); |
4807 if (qi == NULL) | 4815 if (qi == NULL) |
4808 return 0; | 4816 return 0; |
4809 } | 4817 } |
4810 | 4818 |
4811 qfl = &qi->qf_lists[qi->qf_curlist]; | 4819 qfl = qf_get_curlist(qi); |
4812 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count && qfp != NULL; | 4820 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count && qfp != NULL; |
4813 ++i, qfp = qfp->qf_next) | 4821 ++i, qfp = qfp->qf_next) |
4814 { | 4822 { |
4815 if (qfp->qf_valid) | 4823 if (qfp->qf_valid) |
4816 { | 4824 { |
4843 qi = GET_LOC_LIST(curwin); | 4851 qi = GET_LOC_LIST(curwin); |
4844 if (qi == NULL) | 4852 if (qi == NULL) |
4845 return 0; | 4853 return 0; |
4846 } | 4854 } |
4847 | 4855 |
4848 return qi->qf_lists[qi->qf_curlist].qf_index; | 4856 return qf_get_curlist(qi)->qf_index; |
4849 } | 4857 } |
4850 | 4858 |
4851 /* | 4859 /* |
4852 * Returns the current index in the quickfix/location list (counting only valid | 4860 * Returns the current index in the quickfix/location list (counting only valid |
4853 * entries). If no valid entries are in the list, then returns 1. | 4861 * entries). If no valid entries are in the list, then returns 1. |
4867 qi = GET_LOC_LIST(curwin); | 4875 qi = GET_LOC_LIST(curwin); |
4868 if (qi == NULL) | 4876 if (qi == NULL) |
4869 return 1; | 4877 return 1; |
4870 } | 4878 } |
4871 | 4879 |
4872 qfl = &qi->qf_lists[qi->qf_curlist]; | 4880 qfl = qf_get_curlist(qi); |
4873 qfp = qfl->qf_start; | 4881 qfp = qfl->qf_start; |
4874 | 4882 |
4875 // check if the list has valid errors | 4883 // check if the list has valid errors |
4876 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) | 4884 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) |
4877 return 1; | 4885 return 1; |
4983 | 4991 |
4984 // For cdo and ldo commands, jump to the nth valid error. | 4992 // For cdo and ldo commands, jump to the nth valid error. |
4985 // For cfdo and lfdo commands, jump to the nth valid file entry. | 4993 // For cfdo and lfdo commands, jump to the nth valid file entry. |
4986 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo | 4994 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo |
4987 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) | 4995 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
4988 errornr = qf_get_nth_valid_entry(&qi->qf_lists[qi->qf_curlist], | 4996 errornr = qf_get_nth_valid_entry(qf_get_curlist(qi), |
4989 eap->addr_count > 0 ? (int)eap->line1 : 1, | 4997 eap->addr_count > 0 ? (int)eap->line1 : 1, |
4990 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo); | 4998 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo); |
4991 | 4999 |
4992 qf_jump(qi, 0, errornr, eap->forceit); | 5000 qf_jump(qi, 0, errornr, eap->forceit); |
4993 } | 5001 } |
5112 decr_quickfix_busy(); | 5120 decr_quickfix_busy(); |
5113 return; | 5121 return; |
5114 } | 5122 } |
5115 } | 5123 } |
5116 if (res >= 0) | 5124 if (res >= 0) |
5117 qf_list_changed(&qi->qf_lists[qi->qf_curlist]); | 5125 qf_list_changed(qf_get_curlist(qi)); |
5118 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 5126 save_qfid = qf_get_curlist(qi)->qf_id; |
5119 if (au_name != NULL) | 5127 if (au_name != NULL) |
5120 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | 5128 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); |
5121 | 5129 |
5122 // Jump to the first error for a new list and if autocmds didn't | 5130 // Jump to the first error for a new list and if autocmds didn't |
5123 // free the list. | 5131 // free the list. |
5234 | 5242 |
5235 return buf; | 5243 return buf; |
5236 } | 5244 } |
5237 | 5245 |
5238 /* | 5246 /* |
5239 * Check whether a quickfix/location list valid. Autocmds may remove or change | 5247 * Check whether a quickfix/location list is valid. Autocmds may remove or |
5240 * a quickfix list when vimgrep is running. If the list is not found, create a | 5248 * change a quickfix list when vimgrep is running. If the list is not found, |
5241 * new list. | 5249 * create a new list. |
5242 */ | 5250 */ |
5243 static int | 5251 static int |
5244 vgr_qflist_valid( | 5252 vgr_qflist_valid( |
5245 win_T *wp, | 5253 win_T *wp, |
5246 qf_info_T *qi, | 5254 qf_info_T *qi, |
5477 | 5485 |
5478 incr_quickfix_busy(); | 5486 incr_quickfix_busy(); |
5479 | 5487 |
5480 // Remember the current quickfix list identifier, so that we can check for | 5488 // Remember the current quickfix list identifier, so that we can check for |
5481 // autocommands changing the current quickfix list. | 5489 // autocommands changing the current quickfix list. |
5482 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 5490 save_qfid = qf_get_curlist(qi)->qf_id; |
5483 | 5491 |
5484 seconds = (time_t)0; | 5492 seconds = (time_t)0; |
5485 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) | 5493 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) |
5486 { | 5494 { |
5487 fname = shorten_fname1(fnames[fi]); | 5495 fname = shorten_fname1(fnames[fi]); |
5513 { | 5521 { |
5514 FreeWild(fcount, fnames); | 5522 FreeWild(fcount, fnames); |
5515 decr_quickfix_busy(); | 5523 decr_quickfix_busy(); |
5516 goto theend; | 5524 goto theend; |
5517 } | 5525 } |
5518 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 5526 save_qfid = qf_get_curlist(qi)->qf_id; |
5519 | 5527 |
5520 if (buf == NULL) | 5528 if (buf == NULL) |
5521 { | 5529 { |
5522 if (!got_int) | 5530 if (!got_int) |
5523 smsg(_("Cannot open file \"%s\""), fname); | 5531 smsg(_("Cannot open file \"%s\""), fname); |
5593 } | 5601 } |
5594 } | 5602 } |
5595 | 5603 |
5596 FreeWild(fcount, fnames); | 5604 FreeWild(fcount, fnames); |
5597 | 5605 |
5598 qfl = &qi->qf_lists[qi->qf_curlist]; | 5606 qfl = qf_get_curlist(qi); |
5599 qfl->qf_nonevalid = FALSE; | 5607 qfl->qf_nonevalid = FALSE; |
5600 qfl->qf_ptr = qfl->qf_start; | 5608 qfl->qf_ptr = qfl->qf_start; |
5601 qfl->qf_index = 1; | 5609 qfl->qf_index = 1; |
5602 qf_list_changed(qfl); | 5610 qf_list_changed(qfl); |
5603 | 5611 |
6600 qfl->qf_ptr = qf_ptr; | 6608 qfl->qf_ptr = qf_ptr; |
6601 qfl->qf_index = newidx; | 6609 qfl->qf_index = newidx; |
6602 | 6610 |
6603 // If the current list is modified and it is displayed in the quickfix | 6611 // If the current list is modified and it is displayed in the quickfix |
6604 // window, then Update it. | 6612 // window, then Update it. |
6605 if (qi->qf_lists[qi->qf_curlist].qf_id == qfl->qf_id) | 6613 if (qf_get_curlist(qi)->qf_id == qfl->qf_id) |
6606 qf_win_pos_update(qi, old_qfidx); | 6614 qf_win_pos_update(qi, old_qfidx); |
6607 | 6615 |
6608 return OK; | 6616 return OK; |
6609 } | 6617 } |
6610 | 6618 |
6666 | 6674 |
6667 if (qfwin != NULL) | 6675 if (qfwin != NULL) |
6668 { | 6676 { |
6669 // If the quickfix/location list window is open, then clear it | 6677 // If the quickfix/location list window is open, then clear it |
6670 if (qi->qf_curlist < qi->qf_listcount) | 6678 if (qi->qf_curlist < qi->qf_listcount) |
6671 qf_free(&qi->qf_lists[qi->qf_curlist]); | 6679 qf_free(qf_get_curlist(qi)); |
6672 qf_update_buffer(qi, NULL); | 6680 qf_update_buffer(qi, NULL); |
6673 } | 6681 } |
6674 | 6682 |
6675 if (wp != NULL && IS_LL_WINDOW(wp)) | 6683 if (wp != NULL && IS_LL_WINDOW(wp)) |
6676 { | 6684 { |
6698 // first free the list reference in the location list window | 6706 // first free the list reference in the location list window |
6699 ll_free_all(&qfwin->w_llist_ref); | 6707 ll_free_all(&qfwin->w_llist_ref); |
6700 | 6708 |
6701 qfwin->w_llist_ref = new_ll; | 6709 qfwin->w_llist_ref = new_ll; |
6702 if (wp != qfwin) | 6710 if (wp != qfwin) |
6703 { | 6711 win_set_loclist(wp, new_ll); |
6704 wp->w_llist = new_ll; | |
6705 new_ll->qf_refcount++; | |
6706 } | |
6707 } | 6712 } |
6708 } | 6713 } |
6709 | 6714 |
6710 /* | 6715 /* |
6711 * Populate the quickfix list with the items supplied in the list | 6716 * Populate the quickfix list with the items supplied in the list |
6743 retval = qf_set_properties(qi, what, action, title); | 6748 retval = qf_set_properties(qi, what, action, title); |
6744 else | 6749 else |
6745 { | 6750 { |
6746 retval = qf_add_entries(qi, qi->qf_curlist, list, title, action); | 6751 retval = qf_add_entries(qi, qi->qf_curlist, list, title, action); |
6747 if (retval == OK) | 6752 if (retval == OK) |
6748 qf_list_changed(&qi->qf_lists[qi->qf_curlist]); | 6753 qf_list_changed(qf_get_curlist(qi)); |
6749 } | 6754 } |
6750 | 6755 |
6751 decr_quickfix_busy(); | 6756 decr_quickfix_busy(); |
6752 | 6757 |
6753 return retval; | 6758 return retval; |
6898 { | 6903 { |
6899 decr_quickfix_busy(); | 6904 decr_quickfix_busy(); |
6900 return; | 6905 return; |
6901 } | 6906 } |
6902 if (res >= 0) | 6907 if (res >= 0) |
6903 qf_list_changed(&qi->qf_lists[qi->qf_curlist]); | 6908 qf_list_changed(qf_get_curlist(qi)); |
6904 | 6909 |
6905 // Remember the current quickfix list identifier, so that we can | 6910 // Remember the current quickfix list identifier, so that we can |
6906 // check for autocommands changing the current quickfix list. | 6911 // check for autocommands changing the current quickfix list. |
6907 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 6912 save_qfid = qf_get_curlist(qi)->qf_id; |
6908 if (au_name != NULL) | 6913 if (au_name != NULL) |
6909 { | 6914 { |
6910 buf_T *curbuf_old = curbuf; | 6915 buf_T *curbuf_old = curbuf; |
6911 | 6916 |
6912 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | 6917 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
6989 { | 6994 { |
6990 decr_quickfix_busy(); | 6995 decr_quickfix_busy(); |
6991 goto cleanup; | 6996 goto cleanup; |
6992 } | 6997 } |
6993 if (res >= 0) | 6998 if (res >= 0) |
6994 qf_list_changed(&qi->qf_lists[qi->qf_curlist]); | 6999 qf_list_changed(qf_get_curlist(qi)); |
6995 | 7000 |
6996 // Remember the current quickfix list identifier, so that we can | 7001 // Remember the current quickfix list identifier, so that we can |
6997 // check for autocommands changing the current quickfix list. | 7002 // check for autocommands changing the current quickfix list. |
6998 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; | 7003 save_qfid = qf_get_curlist(qi)->qf_id; |
6999 if (au_name != NULL) | 7004 if (au_name != NULL) |
7000 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | 7005 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
7001 curbuf->b_fname, TRUE, curbuf); | 7006 curbuf->b_fname, TRUE, curbuf); |
7002 | 7007 |
7003 // Jump to the first error for a new list and if autocmds didn't | 7008 // Jump to the first error for a new list and if autocmds didn't |
7257 | 7262 |
7258 hgr_search_in_rtp(qi, ®match, lang); | 7263 hgr_search_in_rtp(qi, ®match, lang); |
7259 | 7264 |
7260 vim_regfree(regmatch.regprog); | 7265 vim_regfree(regmatch.regprog); |
7261 | 7266 |
7262 qfl = &qi->qf_lists[qi->qf_curlist]; | 7267 qfl = qf_get_curlist(qi); |
7263 qfl->qf_nonevalid = FALSE; | 7268 qfl->qf_nonevalid = FALSE; |
7264 qfl->qf_ptr = qfl->qf_start; | 7269 qfl->qf_ptr = qfl->qf_start; |
7265 qfl->qf_index = 1; | 7270 qfl->qf_index = 1; |
7266 qf_list_changed(qfl); | 7271 qf_list_changed(qfl); |
7267 qf_update_buffer(qi, NULL); | 7272 qf_update_buffer(qi, NULL); |