Mercurial > vim
comparison src/quickfix.c @ 16115:91da8cd462ef v8.1.1062
patch 8.1.1062: quickfix code is repeated
commit https://github.com/vim/vim/commit/a16123a666b4656543614cb5bdaa69ea69f35d30
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 28 20:31:07 2019 +0100
patch 8.1.1062: quickfix code is repeated
Problem: Quickfix code is repeated.
Solution: Define FOR_ALL_QFL_ITEMS(). Move some code to separate functions.
(Yegappan Lakshmanan, closes #4166)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 28 Mar 2019 20:45:05 +0100 |
parents | d1efe0dbe6b0 |
children | e12336bb8ced |
comparison
equal
deleted
inserted
replaced
16114:27b5c0cf863c | 16115:91da8cd462ef |
---|---|
192 /* | 192 /* |
193 * Return location list for window 'wp' | 193 * Return location list for window 'wp' |
194 * For location list window, return the referenced location list | 194 * For location list window, return the referenced location list |
195 */ | 195 */ |
196 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist) | 196 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist) |
197 | |
198 #define FOR_ALL_QFL_ITEMS(qfl, qfp, i) \ | |
199 for (i = 0, qfp = qfl->qf_start; \ | |
200 !got_int && i < qfl->qf_count && qfp != NULL; \ | |
201 ++i, qfp = qfp->qf_next) | |
197 | 202 |
198 /* | 203 /* |
199 * Looking up a buffer can be slow if there are many. Remember the last one | 204 * Looking up a buffer can be slow if there are many. Remember the last one |
200 * to make this a lot faster if there are multiple matches in the same file. | 205 * to make this a lot faster if there are multiple matches in the same file. |
201 */ | 206 */ |
2146 int i; | 2151 int i; |
2147 qfline_T *from_qfp; | 2152 qfline_T *from_qfp; |
2148 qfline_T *prevp; | 2153 qfline_T *prevp; |
2149 | 2154 |
2150 // copy all the location entries in this list | 2155 // copy all the location entries in this list |
2151 for (i = 0, from_qfp = from_qfl->qf_start; | 2156 FOR_ALL_QFL_ITEMS(from_qfl, from_qfp, i) |
2152 i < from_qfl->qf_count && from_qfp != NULL; | |
2153 ++i, from_qfp = from_qfp->qf_next) | |
2154 { | 2157 { |
2155 if (qf_add_entry(to_qfl, | 2158 if (qf_add_entry(to_qfl, |
2156 NULL, | 2159 NULL, |
2157 NULL, | 2160 NULL, |
2158 from_qfp->qf_module, | 2161 from_qfp->qf_module, |
2542 { | 2545 { |
2543 qfline_T *qfp; | 2546 qfline_T *qfp; |
2544 int i; | 2547 int i; |
2545 | 2548 |
2546 // Search for the entry in the current list | 2549 // Search for the entry in the current list |
2547 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count; | 2550 FOR_ALL_QFL_ITEMS(qfl, qfp, i) |
2548 ++i, qfp = qfp->qf_next) | 2551 if (qfp == qf_ptr) |
2549 if (qfp == NULL || qfp == qf_ptr) | |
2550 break; | 2552 break; |
2551 | 2553 |
2552 if (i == qfl->qf_count) // Entry is not found | 2554 if (i == qfl->qf_count) // Entry is not found |
2553 return FALSE; | 2555 return FALSE; |
2554 | 2556 |
3790 for (idx = 0; idx < qi->qf_listcount; ++idx) | 3792 for (idx = 0; idx < qi->qf_listcount; ++idx) |
3791 { | 3793 { |
3792 qf_list_T *qfl = qf_get_list(qi, idx); | 3794 qf_list_T *qfl = qf_get_list(qi, idx); |
3793 | 3795 |
3794 if (!qf_list_empty(qfl)) | 3796 if (!qf_list_empty(qfl)) |
3795 for (i = 0, qfp = qfl->qf_start; | 3797 FOR_ALL_QFL_ITEMS(qfl, qfp, i) |
3796 i < qfl->qf_count && qfp != NULL; | |
3797 ++i, qfp = qfp->qf_next) | |
3798 if (qfp->qf_fnum == curbuf->b_fnum) | 3798 if (qfp->qf_fnum == curbuf->b_fnum) |
3799 { | 3799 { |
3800 found_one = TRUE; | 3800 found_one = TRUE; |
3801 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) | 3801 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) |
3802 { | 3802 { |
4817 if (qi == NULL) | 4817 if (qi == NULL) |
4818 return 0; | 4818 return 0; |
4819 } | 4819 } |
4820 | 4820 |
4821 qfl = qf_get_curlist(qi); | 4821 qfl = qf_get_curlist(qi); |
4822 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count && qfp != NULL; | 4822 FOR_ALL_QFL_ITEMS(qfl, qfp, i) |
4823 ++i, qfp = qfp->qf_next) | |
4824 { | 4823 { |
4825 if (qfp->qf_valid) | 4824 if (qfp->qf_valid) |
4826 { | 4825 { |
4827 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) | 4826 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) |
4828 sz++; // Count all valid entries | 4827 sz++; // Count all valid entries |
5054 | 5053 |
5055 qf_jump(qi, dir, errornr, eap->forceit); | 5054 qf_jump(qi, dir, errornr, eap->forceit); |
5056 } | 5055 } |
5057 | 5056 |
5058 /* | 5057 /* |
5058 * Return the autocmd name for the :cfile Ex commands | |
5059 */ | |
5060 static char_u * | |
5061 cfile_get_auname(cmdidx_T cmdidx) | |
5062 { | |
5063 switch (cmdidx) | |
5064 { | |
5065 case CMD_cfile: return (char_u *)"cfile"; | |
5066 case CMD_cgetfile: return (char_u *)"cgetfile"; | |
5067 case CMD_caddfile: return (char_u *)"caddfile"; | |
5068 case CMD_lfile: return (char_u *)"lfile"; | |
5069 case CMD_lgetfile: return (char_u *)"lgetfile"; | |
5070 case CMD_laddfile: return (char_u *)"laddfile"; | |
5071 default: return NULL; | |
5072 } | |
5073 } | |
5074 | |
5075 /* | |
5059 * ":cfile"/":cgetfile"/":caddfile" commands. | 5076 * ":cfile"/":cgetfile"/":caddfile" commands. |
5060 * ":lfile"/":lgetfile"/":laddfile" commands. | 5077 * ":lfile"/":lgetfile"/":laddfile" commands. |
5061 */ | 5078 */ |
5062 void | 5079 void |
5063 ex_cfile(exarg_T *eap) | 5080 ex_cfile(exarg_T *eap) |
5067 qf_info_T *qi = &ql_info; | 5084 qf_info_T *qi = &ql_info; |
5068 char_u *au_name = NULL; | 5085 char_u *au_name = NULL; |
5069 int_u save_qfid = 0; // init for gcc | 5086 int_u save_qfid = 0; // init for gcc |
5070 int res; | 5087 int res; |
5071 | 5088 |
5072 switch (eap->cmdidx) | 5089 au_name = cfile_get_auname(eap->cmdidx); |
5073 { | |
5074 case CMD_cfile: au_name = (char_u *)"cfile"; break; | |
5075 case CMD_cgetfile: au_name = (char_u *)"cgetfile"; break; | |
5076 case CMD_caddfile: au_name = (char_u *)"caddfile"; break; | |
5077 case CMD_lfile: au_name = (char_u *)"lfile"; break; | |
5078 case CMD_lgetfile: au_name = (char_u *)"lgetfile"; break; | |
5079 case CMD_laddfile: au_name = (char_u *)"laddfile"; break; | |
5080 default: break; | |
5081 } | |
5082 if (au_name != NULL) | 5090 if (au_name != NULL) |
5083 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf); | 5091 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf); |
5092 | |
5084 enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc; | 5093 enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc; |
5085 #ifdef FEAT_BROWSE | 5094 #ifdef FEAT_BROWSE |
5086 if (cmdmod.browse) | 5095 if (cmdmod.browse) |
5087 { | 5096 { |
5088 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg, | 5097 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg, |
5830 } | 5839 } |
5831 } | 5840 } |
5832 | 5841 |
5833 #if defined(FEAT_EVAL) || defined(PROTO) | 5842 #if defined(FEAT_EVAL) || defined(PROTO) |
5834 /* | 5843 /* |
5844 * Copy the specified quickfix entry items into a new dict and appened the dict | |
5845 * to 'list'. Returns OK on success. | |
5846 */ | |
5847 static int | |
5848 get_qfline_items(qfline_T *qfp, list_T *list) | |
5849 { | |
5850 int bufnum; | |
5851 dict_T *dict; | |
5852 char_u buf[2]; | |
5853 | |
5854 // Handle entries with a non-existing buffer number. | |
5855 bufnum = qfp->qf_fnum; | |
5856 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
5857 bufnum = 0; | |
5858 | |
5859 if ((dict = dict_alloc()) == NULL) | |
5860 return FAIL; | |
5861 if (list_append_dict(list, dict) == FAIL) | |
5862 return FAIL; | |
5863 | |
5864 buf[0] = qfp->qf_type; | |
5865 buf[1] = NUL; | |
5866 if (dict_add_number(dict, "bufnr", (long)bufnum) == FAIL | |
5867 || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL | |
5868 || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL | |
5869 || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL | |
5870 || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL | |
5871 || dict_add_string(dict, "module", qfp->qf_module) == FAIL | |
5872 || dict_add_string(dict, "pattern", qfp->qf_pattern) == FAIL | |
5873 || dict_add_string(dict, "text", qfp->qf_text) == FAIL | |
5874 || dict_add_string(dict, "type", buf) == FAIL | |
5875 || dict_add_number(dict, "valid", (long)qfp->qf_valid) == FAIL) | |
5876 return FAIL; | |
5877 | |
5878 return OK; | |
5879 } | |
5880 | |
5881 /* | |
5835 * Add each quickfix error to list "list" as a dictionary. | 5882 * Add each quickfix error to list "list" as a dictionary. |
5836 * If qf_idx is -1, use the current list. Otherwise, use the specified list. | 5883 * If qf_idx is -1, use the current list. Otherwise, use the specified list. |
5837 */ | 5884 */ |
5838 int | 5885 int |
5839 get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) | 5886 get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) |
5840 { | 5887 { |
5841 qf_info_T *qi = qi_arg; | 5888 qf_info_T *qi = qi_arg; |
5842 qf_list_T *qfl; | 5889 qf_list_T *qfl; |
5843 dict_T *dict; | |
5844 char_u buf[2]; | |
5845 qfline_T *qfp; | 5890 qfline_T *qfp; |
5846 int i; | 5891 int i; |
5847 int bufnum; | |
5848 | 5892 |
5849 if (qi == NULL) | 5893 if (qi == NULL) |
5850 { | 5894 { |
5851 qi = &ql_info; | 5895 qi = &ql_info; |
5852 if (wp != NULL) | 5896 if (wp != NULL) |
5865 | 5909 |
5866 qfl = qf_get_list(qi, qf_idx); | 5910 qfl = qf_get_list(qi, qf_idx); |
5867 if (qf_list_empty(qfl)) | 5911 if (qf_list_empty(qfl)) |
5868 return FAIL; | 5912 return FAIL; |
5869 | 5913 |
5870 qfp = qfl->qf_start; | 5914 FOR_ALL_QFL_ITEMS(qfl, qfp, i) |
5871 for (i = 1; !got_int && i <= qfl->qf_count; ++i) | 5915 { |
5872 { | 5916 if (get_qfline_items(qfp, list) == FAIL) |
5873 // Handle entries with a non-existing buffer number. | |
5874 bufnum = qfp->qf_fnum; | |
5875 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
5876 bufnum = 0; | |
5877 | |
5878 if ((dict = dict_alloc()) == NULL) | |
5879 return FAIL; | 5917 return FAIL; |
5880 if (list_append_dict(list, dict) == FAIL) | 5918 } |
5881 return FAIL; | 5919 |
5882 | |
5883 buf[0] = qfp->qf_type; | |
5884 buf[1] = NUL; | |
5885 if ( dict_add_number(dict, "bufnr", (long)bufnum) == FAIL | |
5886 || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL | |
5887 || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL | |
5888 || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL | |
5889 || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL | |
5890 || dict_add_string(dict, "module", qfp->qf_module) == FAIL | |
5891 || dict_add_string(dict, "pattern", qfp->qf_pattern) == FAIL | |
5892 || dict_add_string(dict, "text", qfp->qf_text) == FAIL | |
5893 || dict_add_string(dict, "type", buf) == FAIL | |
5894 || dict_add_number(dict, "valid", (long)qfp->qf_valid) == FAIL) | |
5895 return FAIL; | |
5896 | |
5897 qfp = qfp->qf_next; | |
5898 if (qfp == NULL) | |
5899 break; | |
5900 } | |
5901 return OK; | 5920 return OK; |
5902 } | 5921 } |
5903 | 5922 |
5904 // Flags used by getqflist()/getloclist() to determine which fields to return. | 5923 // Flags used by getqflist()/getloclist() to determine which fields to return. |
5905 enum { | 5924 enum { |
6840 return abort; | 6859 return abort; |
6841 } | 6860 } |
6842 #endif | 6861 #endif |
6843 | 6862 |
6844 /* | 6863 /* |
6864 * Return the autocmd name for the :cbuffer Ex commands | |
6865 */ | |
6866 static char_u * | |
6867 cbuffer_get_auname(cmdidx_T cmdidx) | |
6868 { | |
6869 switch (cmdidx) | |
6870 { | |
6871 case CMD_cbuffer: return (char_u *)"cbuffer"; | |
6872 case CMD_cgetbuffer: return (char_u *)"cgetbuffer"; | |
6873 case CMD_caddbuffer: return (char_u *)"caddbuffer"; | |
6874 case CMD_lbuffer: return (char_u *)"lbuffer"; | |
6875 case CMD_lgetbuffer: return (char_u *)"lgetbuffer"; | |
6876 case CMD_laddbuffer: return (char_u *)"laddbuffer"; | |
6877 default: return NULL; | |
6878 } | |
6879 } | |
6880 | |
6881 /* | |
6882 * Process and validate the arguments passed to the :cbuffer, :caddbuffer, | |
6883 * :cgetbuffer, :lbuffer, :laddbuffer, :lgetbuffer Ex commands. | |
6884 */ | |
6885 static int | |
6886 cbuffer_process_args( | |
6887 exarg_T *eap, | |
6888 buf_T **bufp, | |
6889 linenr_T *line1, | |
6890 linenr_T *line2) | |
6891 { | |
6892 buf_T *buf = NULL; | |
6893 | |
6894 if (*eap->arg == NUL) | |
6895 buf = curbuf; | |
6896 else if (*skipwhite(skipdigits(eap->arg)) == NUL) | |
6897 buf = buflist_findnr(atoi((char *)eap->arg)); | |
6898 | |
6899 if (buf == NULL) | |
6900 { | |
6901 emsg(_(e_invarg)); | |
6902 return FAIL; | |
6903 } | |
6904 | |
6905 if (buf->b_ml.ml_mfp == NULL) | |
6906 { | |
6907 emsg(_("E681: Buffer is not loaded")); | |
6908 return FAIL; | |
6909 } | |
6910 | |
6911 if (eap->addr_count == 0) | |
6912 { | |
6913 eap->line1 = 1; | |
6914 eap->line2 = buf->b_ml.ml_line_count; | |
6915 } | |
6916 | |
6917 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count | |
6918 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) | |
6919 { | |
6920 emsg(_(e_invrange)); | |
6921 return FAIL; | |
6922 } | |
6923 | |
6924 *line1 = eap->line1; | |
6925 *line2 = eap->line2; | |
6926 *bufp = buf; | |
6927 | |
6928 return OK; | |
6929 } | |
6930 | |
6931 /* | |
6845 * ":[range]cbuffer [bufnr]" command. | 6932 * ":[range]cbuffer [bufnr]" command. |
6846 * ":[range]caddbuffer [bufnr]" command. | 6933 * ":[range]caddbuffer [bufnr]" command. |
6847 * ":[range]cgetbuffer [bufnr]" command. | 6934 * ":[range]cgetbuffer [bufnr]" command. |
6848 * ":[range]lbuffer [bufnr]" command. | 6935 * ":[range]lbuffer [bufnr]" command. |
6849 * ":[range]laddbuffer [bufnr]" command. | 6936 * ":[range]laddbuffer [bufnr]" command. |
6856 qf_info_T *qi = &ql_info; | 6943 qf_info_T *qi = &ql_info; |
6857 char_u *au_name = NULL; | 6944 char_u *au_name = NULL; |
6858 int res; | 6945 int res; |
6859 int_u save_qfid; | 6946 int_u save_qfid; |
6860 win_T *wp = NULL; | 6947 win_T *wp = NULL; |
6861 | 6948 char_u *qf_title; |
6862 switch (eap->cmdidx) | 6949 linenr_T line1; |
6863 { | 6950 linenr_T line2; |
6864 case CMD_cbuffer: au_name = (char_u *)"cbuffer"; break; | 6951 |
6865 case CMD_cgetbuffer: au_name = (char_u *)"cgetbuffer"; break; | 6952 au_name = cbuffer_get_auname(eap->cmdidx); |
6866 case CMD_caddbuffer: au_name = (char_u *)"caddbuffer"; break; | |
6867 case CMD_lbuffer: au_name = (char_u *)"lbuffer"; break; | |
6868 case CMD_lgetbuffer: au_name = (char_u *)"lgetbuffer"; break; | |
6869 case CMD_laddbuffer: au_name = (char_u *)"laddbuffer"; break; | |
6870 default: break; | |
6871 } | |
6872 if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | 6953 if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, |
6873 curbuf->b_fname, TRUE, curbuf)) | 6954 curbuf->b_fname, TRUE, curbuf)) |
6874 { | 6955 { |
6875 #ifdef FEAT_EVAL | 6956 #ifdef FEAT_EVAL |
6876 if (aborting()) | 6957 if (aborting()) |
6877 return; | 6958 return; |
6878 #endif | 6959 #endif |
6885 if (qi == NULL) | 6966 if (qi == NULL) |
6886 return; | 6967 return; |
6887 wp = curwin; | 6968 wp = curwin; |
6888 } | 6969 } |
6889 | 6970 |
6890 if (*eap->arg == NUL) | 6971 if (cbuffer_process_args(eap, &buf, &line1, &line2) == FAIL) |
6891 buf = curbuf; | 6972 return; |
6892 else if (*skipwhite(skipdigits(eap->arg)) == NUL) | 6973 |
6893 buf = buflist_findnr(atoi((char *)eap->arg)); | 6974 qf_title = qf_cmdtitle(*eap->cmdlinep); |
6894 if (buf == NULL) | 6975 |
6895 emsg(_(e_invarg)); | 6976 if (buf->b_sfname) |
6896 else if (buf->b_ml.ml_mfp == NULL) | 6977 { |
6897 emsg(_("E681: Buffer is not loaded")); | 6978 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)", |
6898 else | 6979 (char *)qf_title, (char *)buf->b_sfname); |
6899 { | 6980 qf_title = IObuff; |
6900 if (eap->addr_count == 0) | 6981 } |
6901 { | 6982 |
6902 eap->line1 = 1; | 6983 incr_quickfix_busy(); |
6903 eap->line2 = buf->b_ml.ml_line_count; | 6984 |
6904 } | 6985 res = qf_init_ext(qi, qi->qf_curlist, NULL, buf, NULL, p_efm, |
6905 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count | 6986 (eap->cmdidx != CMD_caddbuffer |
6906 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) | 6987 && eap->cmdidx != CMD_laddbuffer), |
6907 emsg(_(e_invrange)); | 6988 line1, line2, |
6908 else | 6989 qf_title, NULL); |
6909 { | 6990 if (qf_stack_empty(qi)) |
6910 char_u *qf_title = qf_cmdtitle(*eap->cmdlinep); | 6991 { |
6911 | 6992 decr_quickfix_busy(); |
6912 if (buf->b_sfname) | 6993 return; |
6913 { | 6994 } |
6914 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)", | 6995 if (res >= 0) |
6915 (char *)qf_title, (char *)buf->b_sfname); | 6996 qf_list_changed(qf_get_curlist(qi)); |
6916 qf_title = IObuff; | 6997 |
6917 } | 6998 // Remember the current quickfix list identifier, so that we can |
6918 | 6999 // check for autocommands changing the current quickfix list. |
6919 incr_quickfix_busy(); | 7000 save_qfid = qf_get_curlist(qi)->qf_id; |
6920 | 7001 if (au_name != NULL) |
6921 res = qf_init_ext(qi, qi->qf_curlist, NULL, buf, NULL, p_efm, | 7002 { |
6922 (eap->cmdidx != CMD_caddbuffer | 7003 buf_T *curbuf_old = curbuf; |
6923 && eap->cmdidx != CMD_laddbuffer), | 7004 |
6924 eap->line1, eap->line2, | 7005 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, curbuf->b_fname, |
6925 qf_title, NULL); | 7006 TRUE, curbuf); |
6926 if (qf_stack_empty(qi)) | 7007 if (curbuf != curbuf_old) |
6927 { | 7008 // Autocommands changed buffer, don't jump now, "qi" may |
6928 decr_quickfix_busy(); | 7009 // be invalid. |
6929 return; | 7010 res = 0; |
6930 } | 7011 } |
6931 if (res >= 0) | 7012 // Jump to the first error for a new list and if autocmds didn't |
6932 qf_list_changed(qf_get_curlist(qi)); | 7013 // free the list. |
6933 | 7014 if (res > 0 && (eap->cmdidx == CMD_cbuffer || |
6934 // Remember the current quickfix list identifier, so that we can | 7015 eap->cmdidx == CMD_lbuffer) |
6935 // check for autocommands changing the current quickfix list. | 7016 && qflist_valid(wp, save_qfid)) |
6936 save_qfid = qf_get_curlist(qi)->qf_id; | 7017 // display the first error |
6937 if (au_name != NULL) | 7018 qf_jump_first(qi, save_qfid, eap->forceit); |
6938 { | 7019 |
6939 buf_T *curbuf_old = curbuf; | 7020 decr_quickfix_busy(); |
6940 | |
6941 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
6942 curbuf->b_fname, TRUE, curbuf); | |
6943 if (curbuf != curbuf_old) | |
6944 // Autocommands changed buffer, don't jump now, "qi" may | |
6945 // be invalid. | |
6946 res = 0; | |
6947 } | |
6948 // Jump to the first error for a new list and if autocmds didn't | |
6949 // free the list. | |
6950 if (res > 0 && (eap->cmdidx == CMD_cbuffer || | |
6951 eap->cmdidx == CMD_lbuffer) | |
6952 && qflist_valid(wp, save_qfid)) | |
6953 // display the first error | |
6954 qf_jump_first(qi, save_qfid, eap->forceit); | |
6955 | |
6956 decr_quickfix_busy(); | |
6957 } | |
6958 } | |
6959 } | 7021 } |
6960 | 7022 |
6961 #if defined(FEAT_EVAL) || defined(PROTO) | 7023 #if defined(FEAT_EVAL) || defined(PROTO) |
7024 /* | |
7025 * Return the autocmd name for the :cexpr Ex commands. | |
7026 */ | |
7027 static char_u * | |
7028 cexpr_get_auname(cmdidx_T cmdidx) | |
7029 { | |
7030 switch (cmdidx) | |
7031 { | |
7032 case CMD_cexpr: return (char_u *)"cexpr"; | |
7033 case CMD_cgetexpr: return (char_u *)"cgetexpr"; | |
7034 case CMD_caddexpr: return (char_u *)"caddexpr"; | |
7035 case CMD_lexpr: return (char_u *)"lexpr"; | |
7036 case CMD_lgetexpr: return (char_u *)"lgetexpr"; | |
7037 case CMD_laddexpr: return (char_u *)"laddexpr"; | |
7038 default: return NULL; | |
7039 } | |
7040 } | |
7041 | |
6962 /* | 7042 /* |
6963 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command. | 7043 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command. |
6964 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command. | 7044 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command. |
6965 */ | 7045 */ |
6966 void | 7046 void |
6971 char_u *au_name = NULL; | 7051 char_u *au_name = NULL; |
6972 int res; | 7052 int res; |
6973 int_u save_qfid; | 7053 int_u save_qfid; |
6974 win_T *wp = NULL; | 7054 win_T *wp = NULL; |
6975 | 7055 |
6976 switch (eap->cmdidx) | 7056 au_name = cexpr_get_auname(eap->cmdidx); |
6977 { | |
6978 case CMD_cexpr: au_name = (char_u *)"cexpr"; break; | |
6979 case CMD_cgetexpr: au_name = (char_u *)"cgetexpr"; break; | |
6980 case CMD_caddexpr: au_name = (char_u *)"caddexpr"; break; | |
6981 case CMD_lexpr: au_name = (char_u *)"lexpr"; break; | |
6982 case CMD_lgetexpr: au_name = (char_u *)"lgetexpr"; break; | |
6983 case CMD_laddexpr: au_name = (char_u *)"laddexpr"; break; | |
6984 default: break; | |
6985 } | |
6986 if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | 7057 if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, |
6987 curbuf->b_fname, TRUE, curbuf)) | 7058 curbuf->b_fname, TRUE, curbuf)) |
6988 { | 7059 { |
6989 #ifdef FEAT_EVAL | 7060 #ifdef FEAT_EVAL |
6990 if (aborting()) | 7061 if (aborting()) |
7255 if (aborting()) | 7326 if (aborting()) |
7256 return; | 7327 return; |
7257 #endif | 7328 #endif |
7258 } | 7329 } |
7259 | 7330 |
7331 if (is_loclist_cmd(eap->cmdidx)) | |
7332 { | |
7333 qi = hgr_get_ll(&new_qi); | |
7334 if (qi == NULL) | |
7335 return; | |
7336 } | |
7337 | |
7260 // Make 'cpoptions' empty, the 'l' flag should not be used here. | 7338 // Make 'cpoptions' empty, the 'l' flag should not be used here. |
7261 save_cpo = p_cpo; | 7339 save_cpo = p_cpo; |
7262 p_cpo = empty_option; | 7340 p_cpo = empty_option; |
7263 | |
7264 if (is_loclist_cmd(eap->cmdidx)) | |
7265 { | |
7266 qi = hgr_get_ll(&new_qi); | |
7267 if (qi == NULL) | |
7268 return; | |
7269 } | |
7270 | 7341 |
7271 incr_quickfix_busy(); | 7342 incr_quickfix_busy(); |
7272 | 7343 |
7273 #ifdef FEAT_MULTI_LANG | 7344 #ifdef FEAT_MULTI_LANG |
7274 // Check for a specified language | 7345 // Check for a specified language |