comparison src/quickfix.c @ 12477:68d7bc045dbe v8.0.1118

patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs commit https://github.com/vim/vim/commit/4033c55eca575777718c0701e26635a0cc47d907 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 16 20:54:51 2017 +0200 patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs Problem: FEAT_WINDOWS adds a lot of #ifdefs while it is nearly always enabled and only adds 7% to the binary size of the tiny build. Solution: Graduate FEAT_WINDOWS.
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Sep 2017 21:00:06 +0200
parents 805f7fd40e0d
children 4d40b2644e92
comparison
equal deleted inserted replaced
12476:2516383741e6 12477:68d7bc045dbe
143 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); 143 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack);
144 static char_u *qf_pop_dir(struct dir_stack_T **); 144 static char_u *qf_pop_dir(struct dir_stack_T **);
145 static char_u *qf_guess_filepath(qf_info_T *qi, int qf_idx, char_u *); 145 static char_u *qf_guess_filepath(qf_info_T *qi, int qf_idx, char_u *);
146 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); 146 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize);
147 static void qf_clean_dir_stack(struct dir_stack_T **); 147 static void qf_clean_dir_stack(struct dir_stack_T **);
148 #ifdef FEAT_WINDOWS
149 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); 148 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index);
150 static int is_qf_win(win_T *win, qf_info_T *qi); 149 static int is_qf_win(win_T *win, qf_info_T *qi);
151 static win_T *qf_find_win(qf_info_T *qi); 150 static win_T *qf_find_win(qf_info_T *qi);
152 static buf_T *qf_find_buf(qf_info_T *qi); 151 static buf_T *qf_find_buf(qf_info_T *qi);
153 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); 152 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last);
154 static void qf_set_title_var(qf_info_T *qi); 153 static void qf_set_title_var(qf_info_T *qi);
155 static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last); 154 static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last);
156 #endif
157 static char_u *get_mef_name(void); 155 static char_u *get_mef_name(void);
158 static void restore_start_dir(char_u *dirname_start); 156 static void restore_start_dir(char_u *dirname_start);
159 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); 157 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir);
160 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); 158 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start);
161 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); 159 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start);
1163 char_u *enc) 1161 char_u *enc)
1164 { 1162 {
1165 qf_list_T *qfl; 1163 qf_list_T *qfl;
1166 qfstate_T state; 1164 qfstate_T state;
1167 qffields_T fields; 1165 qffields_T fields;
1168 #ifdef FEAT_WINDOWS
1169 qfline_T *old_last = NULL; 1166 qfline_T *old_last = NULL;
1170 #endif
1171 int adding = FALSE; 1167 int adding = FALSE;
1172 static efm_T *fmt_first = NULL; 1168 static efm_T *fmt_first = NULL;
1173 char_u *efm; 1169 char_u *efm;
1174 static char_u *last_efm = NULL; 1170 static char_u *last_efm = NULL;
1175 int retval = -1; /* default: return error flag */ 1171 int retval = -1; /* default: return error flag */
1207 } 1203 }
1208 else 1204 else
1209 { 1205 {
1210 /* Adding to existing list, use last entry. */ 1206 /* Adding to existing list, use last entry. */
1211 adding = TRUE; 1207 adding = TRUE;
1212 #ifdef FEAT_WINDOWS
1213 if (qi->qf_lists[qf_idx].qf_count > 0) 1208 if (qi->qf_lists[qf_idx].qf_count > 0)
1214 old_last = qi->qf_lists[qf_idx].qf_last; 1209 old_last = qi->qf_lists[qf_idx].qf_last;
1215 #endif
1216 } 1210 }
1217 1211
1218 qfl = &qi->qf_lists[qf_idx]; 1212 qfl = &qi->qf_lists[qf_idx];
1219 1213
1220 /* Use the local value of 'errorformat' if it's set. */ 1214 /* Use the local value of 'errorformat' if it's set. */
1337 vim_free(fields.namebuf); 1331 vim_free(fields.namebuf);
1338 vim_free(fields.errmsg); 1332 vim_free(fields.errmsg);
1339 vim_free(fields.pattern); 1333 vim_free(fields.pattern);
1340 vim_free(state.growbuf); 1334 vim_free(state.growbuf);
1341 1335
1342 #ifdef FEAT_WINDOWS
1343 if (qf_idx == qi->qf_curlist) 1336 if (qf_idx == qi->qf_curlist)
1344 qf_update_buffer(qi, old_last); 1337 qf_update_buffer(qi, old_last);
1345 #endif
1346 #ifdef FEAT_MBYTE 1338 #ifdef FEAT_MBYTE
1347 if (state.vc.vc_type != CONV_NONE) 1339 if (state.vc.vc_type != CONV_NONE)
1348 convert_setup(&state.vc, NULL, NULL); 1340 convert_setup(&state.vc, NULL, NULL);
1349 #endif 1341 #endif
1350 1342
2099 2091
2100 *qf_index = qf_idx; 2092 *qf_index = qf_idx;
2101 return qf_ptr; 2093 return qf_ptr;
2102 } 2094 }
2103 2095
2104 #ifdef FEAT_WINDOWS
2105 /* 2096 /*
2106 * Find a help window or open one. 2097 * Find a help window or open one.
2107 */ 2098 */
2108 static int 2099 static int
2109 jump_to_help_window(qf_info_T *qi, int *opened_window) 2100 jump_to_help_window(qf_info_T *qi, int *opened_window)
2151 if (!p_im) 2142 if (!p_im)
2152 restart_edit = 0; /* don't want insert mode in help file */ 2143 restart_edit = 0; /* don't want insert mode in help file */
2153 2144
2154 return OK; 2145 return OK;
2155 } 2146 }
2156 #endif
2157 2147
2158 /* 2148 /*
2159 * jump to a quickfix line 2149 * jump to a quickfix line
2160 * if dir == FORWARD go "errornr" valid entries forward 2150 * if dir == FORWARD go "errornr" valid entries forward
2161 * if dir == BACKWARD go "errornr" valid entries backward 2151 * if dir == BACKWARD go "errornr" valid entries backward
2179 buf_T *old_curbuf; 2169 buf_T *old_curbuf;
2180 linenr_T old_lnum; 2170 linenr_T old_lnum;
2181 colnr_T screen_col; 2171 colnr_T screen_col;
2182 colnr_T char_col; 2172 colnr_T char_col;
2183 char_u *line; 2173 char_u *line;
2184 #ifdef FEAT_WINDOWS
2185 char_u *old_swb = p_swb; 2174 char_u *old_swb = p_swb;
2186 unsigned old_swb_flags = swb_flags; 2175 unsigned old_swb_flags = swb_flags;
2187 int opened_window = FALSE; 2176 int opened_window = FALSE;
2188 win_T *win; 2177 win_T *win;
2189 win_T *altwin; 2178 win_T *altwin;
2190 int flags; 2179 int flags;
2191 #endif
2192 win_T *oldwin = curwin; 2180 win_T *oldwin = curwin;
2193 int print_message = TRUE; 2181 int print_message = TRUE;
2194 int len; 2182 int len;
2195 #ifdef FEAT_FOLDING 2183 #ifdef FEAT_FOLDING
2196 int old_KeyTyped = KeyTyped; /* getting file may reset it */ 2184 int old_KeyTyped = KeyTyped; /* getting file may reset it */
2223 } 2211 }
2224 } 2212 }
2225 else if (errornr != 0) /* go to specified number */ 2213 else if (errornr != 0) /* go to specified number */
2226 qf_ptr = get_nth_entry(qi, errornr, qf_ptr, &qf_index); 2214 qf_ptr = get_nth_entry(qi, errornr, qf_ptr, &qf_index);
2227 2215
2228 #ifdef FEAT_WINDOWS
2229 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; 2216 qi->qf_lists[qi->qf_curlist].qf_index = qf_index;
2230 if (qf_win_pos_update(qi, old_qf_index)) 2217 if (qf_win_pos_update(qi, old_qf_index))
2231 /* No need to print the error message if it's visible in the error 2218 /* No need to print the error message if it's visible in the error
2232 * window */ 2219 * window */
2233 print_message = FALSE; 2220 print_message = FALSE;
2403 2390
2404 win_goto(win); 2391 win_goto(win);
2405 } 2392 }
2406 } 2393 }
2407 } 2394 }
2408 #endif
2409 2395
2410 /* 2396 /*
2411 * If there is a file name, 2397 * If there is a file name,
2412 * read the wanted file if needed, and check autowrite etc. 2398 * read the wanted file if needed, and check autowrite etc.
2413 */ 2399 */
2556 msg_scroll = i; 2542 msg_scroll = i;
2557 } 2543 }
2558 } 2544 }
2559 else 2545 else
2560 { 2546 {
2561 #ifdef FEAT_WINDOWS
2562 if (opened_window) 2547 if (opened_window)
2563 win_close(curwin, TRUE); /* Close opened window */ 2548 win_close(curwin, TRUE); /* Close opened window */
2564 #endif
2565 if (qf_ptr != NULL && qf_ptr->qf_fnum != 0) 2549 if (qf_ptr != NULL && qf_ptr->qf_fnum != 0)
2566 { 2550 {
2567 /* 2551 /*
2568 * Couldn't open file, so put index back where it was. This could 2552 * Couldn't open file, so put index back where it was. This could
2569 * happen if the file was readonly and we changed something. 2553 * happen if the file was readonly and we changed something.
2570 */ 2554 */
2571 #ifdef FEAT_WINDOWS
2572 failed: 2555 failed:
2573 #endif
2574 qf_ptr = old_qf_ptr; 2556 qf_ptr = old_qf_ptr;
2575 qf_index = old_qf_index; 2557 qf_index = old_qf_index;
2576 } 2558 }
2577 } 2559 }
2578 theend: 2560 theend:
2579 if (qi != NULL) 2561 if (qi != NULL)
2580 { 2562 {
2581 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; 2563 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr;
2582 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; 2564 qi->qf_lists[qi->qf_curlist].qf_index = qf_index;
2583 } 2565 }
2584 #ifdef FEAT_WINDOWS
2585 if (p_swb != old_swb && opened_window) 2566 if (p_swb != old_swb && opened_window)
2586 { 2567 {
2587 /* Restore old 'switchbuf' value, but not when an autocommand or 2568 /* Restore old 'switchbuf' value, but not when an autocommand or
2588 * modeline has changed the value. */ 2569 * modeline has changed the value. */
2589 if (p_swb == empty_option) 2570 if (p_swb == empty_option)
2592 swb_flags = old_swb_flags; 2573 swb_flags = old_swb_flags;
2593 } 2574 }
2594 else 2575 else
2595 free_string_option(old_swb); 2576 free_string_option(old_swb);
2596 } 2577 }
2597 #endif
2598 } 2578 }
2599 2579
2600 /* 2580 /*
2601 * ":clist": list all errors 2581 * ":clist": list all errors
2602 * ":llist": list all locations 2582 * ":llist": list all locations
2818 } 2798 }
2819 ++qi->qf_curlist; 2799 ++qi->qf_curlist;
2820 } 2800 }
2821 } 2801 }
2822 qf_msg(qi, qi->qf_curlist, ""); 2802 qf_msg(qi, qi->qf_curlist, "");
2823 #ifdef FEAT_WINDOWS
2824 qf_update_buffer(qi, NULL); 2803 qf_update_buffer(qi, NULL);
2825 #endif
2826 } 2804 }
2827 2805
2828 void 2806 void
2829 qf_history(exarg_T *eap) 2807 qf_history(exarg_T *eap)
2830 { 2808 {
2999 2977
3000 sprintf((char *)buf, "%s %3d", (char *)p, nr); 2978 sprintf((char *)buf, "%s %3d", (char *)p, nr);
3001 return buf; 2979 return buf;
3002 } 2980 }
3003 2981
3004 #if defined(FEAT_WINDOWS) || defined(PROTO)
3005 /* 2982 /*
3006 * ":cwindow": open the quickfix window if we have errors to display, 2983 * ":cwindow": open the quickfix window if we have errors to display,
3007 * close it if not. 2984 * close it if not.
3008 * ":lwindow": open the location list window if we have locations to display, 2985 * ":lwindow": open the location list window if we have locations to display,
3009 * close it if not. 2986 * close it if not.
3541 } 3518 }
3542 3519
3543 /* Restore KeyTyped, setting 'filetype' may reset it. */ 3520 /* Restore KeyTyped, setting 'filetype' may reset it. */
3544 KeyTyped = old_KeyTyped; 3521 KeyTyped = old_KeyTyped;
3545 } 3522 }
3546
3547 #endif /* FEAT_WINDOWS */
3548 3523
3549 /* 3524 /*
3550 * Return TRUE when using ":vimgrep" for ":grep". 3525 * Return TRUE when using ":vimgrep" for ":grep".
3551 */ 3526 */
3552 int 3527 int
4419 4394
4420 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; 4395 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
4421 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; 4396 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
4422 qi->qf_lists[qi->qf_curlist].qf_index = 1; 4397 qi->qf_lists[qi->qf_curlist].qf_index = 1;
4423 4398
4424 #ifdef FEAT_WINDOWS
4425 qf_update_buffer(qi, NULL); 4399 qf_update_buffer(qi, NULL);
4426 #endif
4427 4400
4428 #ifdef FEAT_AUTOCMD 4401 #ifdef FEAT_AUTOCMD
4429 if (au_name != NULL) 4402 if (au_name != NULL)
4430 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 4403 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
4431 curbuf->b_fname, TRUE, curbuf); 4404 curbuf->b_fname, TRUE, curbuf);
4974 char_u *filename, *pattern, *text, *type; 4947 char_u *filename, *pattern, *text, *type;
4975 int bufnum; 4948 int bufnum;
4976 long lnum; 4949 long lnum;
4977 int col, nr; 4950 int col, nr;
4978 int vcol; 4951 int vcol;
4979 #ifdef FEAT_WINDOWS
4980 qfline_T *old_last = NULL; 4952 qfline_T *old_last = NULL;
4981 #endif
4982 int valid, status; 4953 int valid, status;
4983 int retval = OK; 4954 int retval = OK;
4984 int did_bufnr_emsg = FALSE; 4955 int did_bufnr_emsg = FALSE;
4985 4956
4986 if (action == ' ' || qf_idx == qi->qf_listcount) 4957 if (action == ' ' || qf_idx == qi->qf_listcount)
4987 { 4958 {
4988 /* make place for a new list */ 4959 /* make place for a new list */
4989 qf_new_list(qi, title); 4960 qf_new_list(qi, title);
4990 qf_idx = qi->qf_curlist; 4961 qf_idx = qi->qf_curlist;
4991 } 4962 }
4992 #ifdef FEAT_WINDOWS
4993 else if (action == 'a' && qi->qf_lists[qf_idx].qf_count > 0) 4963 else if (action == 'a' && qi->qf_lists[qf_idx].qf_count > 0)
4994 /* Adding to existing list, use last entry. */ 4964 /* Adding to existing list, use last entry. */
4995 old_last = qi->qf_lists[qf_idx].qf_last; 4965 old_last = qi->qf_lists[qf_idx].qf_last;
4996 #endif
4997 else if (action == 'r') 4966 else if (action == 'r')
4998 { 4967 {
4999 qf_free_items(qi, qf_idx); 4968 qf_free_items(qi, qf_idx);
5000 qf_store_title(qi, qf_idx, title); 4969 qf_store_title(qi, qf_idx, title);
5001 } 4970 }
5079 qi->qf_lists[qf_idx].qf_start; 5048 qi->qf_lists[qf_idx].qf_start;
5080 if (qi->qf_lists[qf_idx].qf_count > 0) 5049 if (qi->qf_lists[qf_idx].qf_count > 0)
5081 qi->qf_lists[qf_idx].qf_index = 1; 5050 qi->qf_lists[qf_idx].qf_index = 1;
5082 } 5051 }
5083 5052
5084 #ifdef FEAT_WINDOWS
5085 /* Don't update the cursor in quickfix window when appending entries */ 5053 /* Don't update the cursor in quickfix window when appending entries */
5086 qf_update_buffer(qi, old_last); 5054 qf_update_buffer(qi, old_last);
5087 #endif
5088 5055
5089 return retval; 5056 return retval;
5090 } 5057 }
5091 5058
5092 static int 5059 static int
5752 p_cpo = save_cpo; 5719 p_cpo = save_cpo;
5753 else 5720 else
5754 /* Darn, some plugin changed the value. */ 5721 /* Darn, some plugin changed the value. */
5755 free_string_option(save_cpo); 5722 free_string_option(save_cpo);
5756 5723
5757 #ifdef FEAT_WINDOWS
5758 qf_update_buffer(qi, NULL); 5724 qf_update_buffer(qi, NULL);
5759 #endif
5760 5725
5761 #ifdef FEAT_AUTOCMD 5726 #ifdef FEAT_AUTOCMD
5762 if (au_name != NULL) 5727 if (au_name != NULL)
5763 { 5728 {
5764 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 5729 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,