Mercurial > vim
comparison src/window.c @ 13380:69517d67421f v8.0.1564
patch 8.0.1564: too many #ifdefs
commit https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 4 18:08:14 2018 +0100
patch 8.0.1564: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and
increases code size of tiny Vim by only 40 Kbyte.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 04 Mar 2018 18:15:08 +0100 |
parents | ae312df8d0ab |
children | 6740c499de13 |
comparison
equal
deleted
inserted
replaced
13379:0f9dd1b43244 | 13380:69517d67421f |
---|---|
1435 * add status line now, otherwise first window will be too big | 1435 * add status line now, otherwise first window will be too big |
1436 */ | 1436 */ |
1437 if (count > 1) | 1437 if (count > 1) |
1438 last_status(TRUE); | 1438 last_status(TRUE); |
1439 | 1439 |
1440 #ifdef FEAT_AUTOCMD | |
1441 /* | 1440 /* |
1442 * Don't execute autocommands while creating the windows. Must do that | 1441 * Don't execute autocommands while creating the windows. Must do that |
1443 * when putting the buffers in the windows. | 1442 * when putting the buffers in the windows. |
1444 */ | 1443 */ |
1445 block_autocmds(); | 1444 block_autocmds(); |
1446 #endif | |
1447 | 1445 |
1448 /* todo is number of windows left to create */ | 1446 /* todo is number of windows left to create */ |
1449 for (todo = count - 1; todo > 0; --todo) | 1447 for (todo = count - 1; todo > 0; --todo) |
1450 if (vertical) | 1448 if (vertical) |
1451 { | 1449 { |
1459 * STATUS_HEIGHT) / (todo + 1) | 1457 * STATUS_HEIGHT) / (todo + 1) |
1460 - STATUS_HEIGHT, WSP_ABOVE) == FAIL) | 1458 - STATUS_HEIGHT, WSP_ABOVE) == FAIL) |
1461 break; | 1459 break; |
1462 } | 1460 } |
1463 | 1461 |
1464 #ifdef FEAT_AUTOCMD | |
1465 unblock_autocmds(); | 1462 unblock_autocmds(); |
1466 #endif | |
1467 | 1463 |
1468 /* return actual number of windows */ | 1464 /* return actual number of windows */ |
1469 return (count - todo); | 1465 return (count - todo); |
1470 } | 1466 } |
1471 | 1467 |
2102 int keep_curwin) /* don't close "curwin" */ | 2098 int keep_curwin) /* don't close "curwin" */ |
2103 { | 2099 { |
2104 win_T *wp; | 2100 win_T *wp; |
2105 tabpage_T *tp, *nexttp; | 2101 tabpage_T *tp, *nexttp; |
2106 int h = tabline_height(); | 2102 int h = tabline_height(); |
2107 #ifdef FEAT_AUTOCMD | |
2108 int count = tabpage_index(NULL); | 2103 int count = tabpage_index(NULL); |
2109 #endif | |
2110 | 2104 |
2111 ++RedrawingDisabled; | 2105 ++RedrawingDisabled; |
2112 | 2106 |
2113 for (wp = firstwin; wp != NULL && !ONE_WINDOW; ) | 2107 for (wp = firstwin; wp != NULL && !ONE_WINDOW; ) |
2114 { | 2108 { |
2115 if (wp->w_buffer == buf && (!keep_curwin || wp != curwin) | 2109 if (wp->w_buffer == buf && (!keep_curwin || wp != curwin) |
2116 #ifdef FEAT_AUTOCMD | 2110 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) |
2117 && !(wp->w_closing || wp->w_buffer->b_locked > 0) | |
2118 #endif | |
2119 ) | |
2120 { | 2111 { |
2121 if (win_close(wp, FALSE) == FAIL) | 2112 if (win_close(wp, FALSE) == FAIL) |
2122 /* If closing the window fails give up, to avoid looping | 2113 /* If closing the window fails give up, to avoid looping |
2123 * forever. */ | 2114 * forever. */ |
2124 break; | 2115 break; |
2135 { | 2126 { |
2136 nexttp = tp->tp_next; | 2127 nexttp = tp->tp_next; |
2137 if (tp != curtab) | 2128 if (tp != curtab) |
2138 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | 2129 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) |
2139 if (wp->w_buffer == buf | 2130 if (wp->w_buffer == buf |
2140 #ifdef FEAT_AUTOCMD | 2131 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) |
2141 && !(wp->w_closing || wp->w_buffer->b_locked > 0) | |
2142 #endif | |
2143 ) | |
2144 { | 2132 { |
2145 win_close_othertab(wp, FALSE, tp); | 2133 win_close_othertab(wp, FALSE, tp); |
2146 | 2134 |
2147 /* Start all over, the tab page may be closed and | 2135 /* Start all over, the tab page may be closed and |
2148 * autocommands may change the window layout. */ | 2136 * autocommands may change the window layout. */ |
2151 } | 2139 } |
2152 } | 2140 } |
2153 | 2141 |
2154 --RedrawingDisabled; | 2142 --RedrawingDisabled; |
2155 | 2143 |
2156 #ifdef FEAT_AUTOCMD | |
2157 if (count != tabpage_index(NULL)) | 2144 if (count != tabpage_index(NULL)) |
2158 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); | 2145 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); |
2159 #endif | |
2160 | 2146 |
2161 redraw_tabline = TRUE; | 2147 redraw_tabline = TRUE; |
2162 if (h != tabline_height()) | 2148 if (h != tabline_height()) |
2163 shell_new_rows(); | 2149 shell_new_rows(); |
2164 } | 2150 } |
2179 * current tab page. | 2165 * current tab page. |
2180 */ | 2166 */ |
2181 int | 2167 int |
2182 one_window(void) | 2168 one_window(void) |
2183 { | 2169 { |
2184 #ifdef FEAT_AUTOCMD | |
2185 win_T *wp; | 2170 win_T *wp; |
2186 int seen_one = FALSE; | 2171 int seen_one = FALSE; |
2187 | 2172 |
2188 FOR_ALL_WINDOWS(wp) | 2173 FOR_ALL_WINDOWS(wp) |
2189 { | 2174 { |
2193 return FALSE; | 2178 return FALSE; |
2194 seen_one = TRUE; | 2179 seen_one = TRUE; |
2195 } | 2180 } |
2196 } | 2181 } |
2197 return TRUE; | 2182 return TRUE; |
2198 #else | |
2199 return ONE_WINDOW; | |
2200 #endif | |
2201 } | 2183 } |
2202 | 2184 |
2203 /* | 2185 /* |
2204 * Close the possibly last window in a tab page. | 2186 * Close the possibly last window in a tab page. |
2205 * Returns TRUE when the window was closed already. | 2187 * Returns TRUE when the window was closed already. |
2210 int free_buf, | 2192 int free_buf, |
2211 tabpage_T *prev_curtab) | 2193 tabpage_T *prev_curtab) |
2212 { | 2194 { |
2213 if (ONE_WINDOW) | 2195 if (ONE_WINDOW) |
2214 { | 2196 { |
2215 #ifdef FEAT_AUTOCMD | |
2216 buf_T *old_curbuf = curbuf; | 2197 buf_T *old_curbuf = curbuf; |
2217 #endif | |
2218 | 2198 |
2219 /* | 2199 /* |
2220 * Closing the last window in a tab page. First go to another tab | 2200 * Closing the last window in a tab page. First go to another tab |
2221 * page and then close the window and the tab page. This avoids that | 2201 * page and then close the window and the tab page. This avoids that |
2222 * curwin and curtab are invalid while we are freeing memory, they may | 2202 * curwin and curtab are invalid while we are freeing memory, they may |
2237 if (h != tabline_height()) | 2217 if (h != tabline_height()) |
2238 shell_new_rows(); | 2218 shell_new_rows(); |
2239 } | 2219 } |
2240 /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do | 2220 /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do |
2241 * that now. */ | 2221 * that now. */ |
2242 #ifdef FEAT_AUTOCMD | |
2243 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); | 2222 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); |
2244 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); | 2223 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); |
2245 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); | 2224 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); |
2246 if (old_curbuf != curbuf) | 2225 if (old_curbuf != curbuf) |
2247 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 2226 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
2248 #endif | |
2249 return TRUE; | 2227 return TRUE; |
2250 } | 2228 } |
2251 return FALSE; | 2229 return FALSE; |
2252 } | 2230 } |
2253 | 2231 |
2260 */ | 2238 */ |
2261 int | 2239 int |
2262 win_close(win_T *win, int free_buf) | 2240 win_close(win_T *win, int free_buf) |
2263 { | 2241 { |
2264 win_T *wp; | 2242 win_T *wp; |
2265 #ifdef FEAT_AUTOCMD | |
2266 int other_buffer = FALSE; | 2243 int other_buffer = FALSE; |
2267 #endif | |
2268 int close_curwin = FALSE; | 2244 int close_curwin = FALSE; |
2269 int dir; | 2245 int dir; |
2270 int help_window = FALSE; | 2246 int help_window = FALSE; |
2271 tabpage_T *prev_curtab = curtab; | 2247 tabpage_T *prev_curtab = curtab; |
2272 frame_T *win_frame = win->w_frame->fr_parent; | 2248 frame_T *win_frame = win->w_frame->fr_parent; |
2275 { | 2251 { |
2276 EMSG(_("E444: Cannot close last window")); | 2252 EMSG(_("E444: Cannot close last window")); |
2277 return FAIL; | 2253 return FAIL; |
2278 } | 2254 } |
2279 | 2255 |
2280 #ifdef FEAT_AUTOCMD | |
2281 if (win->w_closing || (win->w_buffer != NULL | 2256 if (win->w_closing || (win->w_buffer != NULL |
2282 && win->w_buffer->b_locked > 0)) | 2257 && win->w_buffer->b_locked > 0)) |
2283 return FAIL; /* window is already being closed */ | 2258 return FAIL; /* window is already being closed */ |
2284 if (win == aucmd_win) | 2259 if (win == aucmd_win) |
2285 { | 2260 { |
2289 if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) | 2264 if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) |
2290 { | 2265 { |
2291 EMSG(_("E814: Cannot close window, only autocmd window would remain")); | 2266 EMSG(_("E814: Cannot close window, only autocmd window would remain")); |
2292 return FAIL; | 2267 return FAIL; |
2293 } | 2268 } |
2294 #endif | |
2295 | 2269 |
2296 /* When closing the last window in a tab page first go to another tab page | 2270 /* When closing the last window in a tab page first go to another tab page |
2297 * and then close the window and the tab page to avoid that curwin and | 2271 * and then close the window and the tab page to avoid that curwin and |
2298 * curtab are invalid while we are freeing memory. */ | 2272 * curtab are invalid while we are freeing memory. */ |
2299 if (close_last_window_tabpage(win, free_buf, prev_curtab)) | 2273 if (close_last_window_tabpage(win, free_buf, prev_curtab)) |
2304 if (bt_help(win->w_buffer)) | 2278 if (bt_help(win->w_buffer)) |
2305 help_window = TRUE; | 2279 help_window = TRUE; |
2306 else | 2280 else |
2307 clear_snapshot(curtab, SNAP_HELP_IDX); | 2281 clear_snapshot(curtab, SNAP_HELP_IDX); |
2308 | 2282 |
2309 #ifdef FEAT_AUTOCMD | |
2310 if (win == curwin) | 2283 if (win == curwin) |
2311 { | 2284 { |
2312 /* | 2285 /* |
2313 * Guess which window is going to be the new current window. | 2286 * Guess which window is going to be the new current window. |
2314 * This may change because of the autocommands (sigh). | 2287 * This may change because of the autocommands (sigh). |
2335 if (!win_valid(win)) | 2308 if (!win_valid(win)) |
2336 return FAIL; | 2309 return FAIL; |
2337 win->w_closing = FALSE; | 2310 win->w_closing = FALSE; |
2338 if (last_window()) | 2311 if (last_window()) |
2339 return FAIL; | 2312 return FAIL; |
2340 # ifdef FEAT_EVAL | 2313 #ifdef FEAT_EVAL |
2341 /* autocmds may abort script processing */ | 2314 /* autocmds may abort script processing */ |
2342 if (aborting()) | 2315 if (aborting()) |
2343 return FAIL; | 2316 return FAIL; |
2344 # endif | 2317 #endif |
2345 } | 2318 } |
2346 #endif | |
2347 | 2319 |
2348 #ifdef FEAT_GUI | 2320 #ifdef FEAT_GUI |
2349 /* Avoid trouble with scrollbars that are going to be deleted in | 2321 /* Avoid trouble with scrollbars that are going to be deleted in |
2350 * win_free(). */ | 2322 * win_free(). */ |
2351 if (gui.in_use) | 2323 if (gui.in_use) |
2364 if (win->w_buffer != NULL) | 2336 if (win->w_buffer != NULL) |
2365 { | 2337 { |
2366 bufref_T bufref; | 2338 bufref_T bufref; |
2367 | 2339 |
2368 set_bufref(&bufref, curbuf); | 2340 set_bufref(&bufref, curbuf); |
2369 #ifdef FEAT_AUTOCMD | |
2370 win->w_closing = TRUE; | 2341 win->w_closing = TRUE; |
2371 #endif | |
2372 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, TRUE); | 2342 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, TRUE); |
2373 #ifdef FEAT_AUTOCMD | |
2374 if (win_valid_any_tab(win)) | 2343 if (win_valid_any_tab(win)) |
2375 win->w_closing = FALSE; | 2344 win->w_closing = FALSE; |
2376 #endif | |
2377 /* Make sure curbuf is valid. It can become invalid if 'bufhidden' is | 2345 /* Make sure curbuf is valid. It can become invalid if 'bufhidden' is |
2378 * "wipe". */ | 2346 * "wipe". */ |
2379 if (!bufref_valid(&bufref)) | 2347 if (!bufref_valid(&bufref)) |
2380 curbuf = firstbuf; | 2348 curbuf = firstbuf; |
2381 } | 2349 } |
2453 else | 2421 else |
2454 win_comp_pos(); | 2422 win_comp_pos(); |
2455 if (close_curwin) | 2423 if (close_curwin) |
2456 { | 2424 { |
2457 win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE); | 2425 win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE); |
2458 #ifdef FEAT_AUTOCMD | |
2459 if (other_buffer) | 2426 if (other_buffer) |
2460 /* careful: after this wp and win may be invalid! */ | 2427 /* careful: after this wp and win may be invalid! */ |
2461 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 2428 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
2462 #endif | |
2463 } | 2429 } |
2464 | 2430 |
2465 /* | 2431 /* |
2466 * If last window has a status line now and we don't want one, | 2432 * If last window has a status line now and we don't want one, |
2467 * remove the status line. | 2433 * remove the status line. |
2496 win_T *wp; | 2462 win_T *wp; |
2497 int dir; | 2463 int dir; |
2498 tabpage_T *ptp = NULL; | 2464 tabpage_T *ptp = NULL; |
2499 int free_tp = FALSE; | 2465 int free_tp = FALSE; |
2500 | 2466 |
2501 #ifdef FEAT_AUTOCMD | |
2502 /* Get here with win->w_buffer == NULL when win_close() detects the tab | 2467 /* Get here with win->w_buffer == NULL when win_close() detects the tab |
2503 * page changed. */ | 2468 * page changed. */ |
2504 if (win->w_closing || (win->w_buffer != NULL | 2469 if (win->w_closing || (win->w_buffer != NULL |
2505 && win->w_buffer->b_locked > 0)) | 2470 && win->w_buffer->b_locked > 0)) |
2506 return; /* window is already being closed */ | 2471 return; /* window is already being closed */ |
2507 #endif | |
2508 | 2472 |
2509 if (win->w_buffer != NULL) | 2473 if (win->w_buffer != NULL) |
2510 /* Close the link to the buffer. */ | 2474 /* Close the link to the buffer. */ |
2511 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, FALSE); | 2475 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, FALSE); |
2512 | 2476 |
2584 int dummy; | 2548 int dummy; |
2585 | 2549 |
2586 while (first_tabpage->tp_next != NULL) | 2550 while (first_tabpage->tp_next != NULL) |
2587 tabpage_close(TRUE); | 2551 tabpage_close(TRUE); |
2588 | 2552 |
2589 # ifdef FEAT_AUTOCMD | |
2590 if (aucmd_win != NULL) | 2553 if (aucmd_win != NULL) |
2591 { | 2554 { |
2592 (void)win_free_mem(aucmd_win, &dummy, NULL); | 2555 (void)win_free_mem(aucmd_win, &dummy, NULL); |
2593 aucmd_win = NULL; | 2556 aucmd_win = NULL; |
2594 } | 2557 } |
2595 # endif | |
2596 | 2558 |
2597 while (firstwin != NULL) | 2559 while (firstwin != NULL) |
2598 (void)win_free_mem(firstwin, &dummy, NULL); | 2560 (void)win_free_mem(firstwin, &dummy, NULL); |
2599 | 2561 |
2600 /* No window should be used after this. Set curwin to NULL to crash | 2562 /* No window should be used after this. Set curwin to NULL to crash |
3329 win_T *nextwp; | 3291 win_T *nextwp; |
3330 int r; | 3292 int r; |
3331 | 3293 |
3332 if (one_window()) | 3294 if (one_window()) |
3333 { | 3295 { |
3334 if (message | 3296 if (message && !autocmd_busy) |
3335 #ifdef FEAT_AUTOCMD | |
3336 && !autocmd_busy | |
3337 #endif | |
3338 ) | |
3339 MSG(_(m_onlyone)); | 3297 MSG(_(m_onlyone)); |
3340 return; | 3298 return; |
3341 } | 3299 } |
3342 | 3300 |
3343 /* Be very careful here: autocommands may change the window layout. */ | 3301 /* Be very careful here: autocommands may change the window layout. */ |
3347 if (wp != curwin) /* don't close current window */ | 3305 if (wp != curwin) /* don't close current window */ |
3348 { | 3306 { |
3349 | 3307 |
3350 /* Check if it's allowed to abandon this window */ | 3308 /* Check if it's allowed to abandon this window */ |
3351 r = can_abandon(wp->w_buffer, forceit); | 3309 r = can_abandon(wp->w_buffer, forceit); |
3352 #ifdef FEAT_AUTOCMD | |
3353 if (!win_valid(wp)) /* autocommands messed wp up */ | 3310 if (!win_valid(wp)) /* autocommands messed wp up */ |
3354 { | 3311 { |
3355 nextwp = firstwin; | 3312 nextwp = firstwin; |
3356 continue; | 3313 continue; |
3357 } | 3314 } |
3358 #endif | |
3359 if (!r) | 3315 if (!r) |
3360 { | 3316 { |
3361 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 3317 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
3362 if (message && (p_confirm || cmdmod.confirm) && p_write) | 3318 if (message && (p_confirm || cmdmod.confirm) && p_write) |
3363 { | 3319 { |
3364 dialog_changed(wp->w_buffer, FALSE); | 3320 dialog_changed(wp->w_buffer, FALSE); |
3365 # ifdef FEAT_AUTOCMD | |
3366 if (!win_valid(wp)) /* autocommands messed wp up */ | 3321 if (!win_valid(wp)) /* autocommands messed wp up */ |
3367 { | 3322 { |
3368 nextwp = firstwin; | 3323 nextwp = firstwin; |
3369 continue; | 3324 continue; |
3370 } | 3325 } |
3371 # endif | |
3372 } | 3326 } |
3373 if (bufIsChanged(wp->w_buffer)) | 3327 if (bufIsChanged(wp->w_buffer)) |
3374 #endif | 3328 #endif |
3375 continue; | 3329 continue; |
3376 } | 3330 } |
3441 curtab = first_tabpage; | 3395 curtab = first_tabpage; |
3442 | 3396 |
3443 return OK; | 3397 return OK; |
3444 } | 3398 } |
3445 | 3399 |
3446 #if defined(FEAT_AUTOCMD) || defined(PROTO) | |
3447 /* | 3400 /* |
3448 * Init "aucmd_win". This can only be done after the first | 3401 * Init "aucmd_win". This can only be done after the first |
3449 * window is fully initialized, thus it can't be in win_alloc_first(). | 3402 * window is fully initialized, thus it can't be in win_alloc_first(). |
3450 */ | 3403 */ |
3451 void | 3404 void |
3457 win_init_some(aucmd_win, curwin); | 3410 win_init_some(aucmd_win, curwin); |
3458 RESET_BINDING(aucmd_win); | 3411 RESET_BINDING(aucmd_win); |
3459 new_frame(aucmd_win); | 3412 new_frame(aucmd_win); |
3460 } | 3413 } |
3461 } | 3414 } |
3462 #endif | |
3463 | 3415 |
3464 /* | 3416 /* |
3465 * Allocate the first window or the first window in a new tab page. | 3417 * Allocate the first window or the first window in a new tab page. |
3466 * When "oldwin" is NULL create an empty buffer for it. | 3418 * When "oldwin" is NULL create an empty buffer for it. |
3467 * When "oldwin" is not NULL copy info from it to the new window. | 3419 * When "oldwin" is not NULL copy info from it to the new window. |
3661 * scrollbars. Have to update them anyway. */ | 3613 * scrollbars. Have to update them anyway. */ |
3662 gui_may_update_scrollbars(); | 3614 gui_may_update_scrollbars(); |
3663 #endif | 3615 #endif |
3664 | 3616 |
3665 redraw_all_later(CLEAR); | 3617 redraw_all_later(CLEAR); |
3666 #ifdef FEAT_AUTOCMD | |
3667 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); | 3618 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); |
3668 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); | 3619 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); |
3669 apply_autocmds(EVENT_TABNEW, NULL, NULL, FALSE, curbuf); | 3620 apply_autocmds(EVENT_TABNEW, NULL, NULL, FALSE, curbuf); |
3670 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); | 3621 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); |
3671 #endif | |
3672 return OK; | 3622 return OK; |
3673 } | 3623 } |
3674 | 3624 |
3675 /* Failed, get back the previous Tab page */ | 3625 /* Failed, get back the previous Tab page */ |
3676 enter_tabpage(curtab, curbuf, TRUE, TRUE); | 3626 enter_tabpage(curtab, curbuf, TRUE, TRUE); |
3708 | 3658 |
3709 /* Limit to 'tabpagemax' tabs. */ | 3659 /* Limit to 'tabpagemax' tabs. */ |
3710 if (count > p_tpm) | 3660 if (count > p_tpm) |
3711 count = p_tpm; | 3661 count = p_tpm; |
3712 | 3662 |
3713 #ifdef FEAT_AUTOCMD | |
3714 /* | 3663 /* |
3715 * Don't execute autocommands while creating the tab pages. Must do that | 3664 * Don't execute autocommands while creating the tab pages. Must do that |
3716 * when putting the buffers in the windows. | 3665 * when putting the buffers in the windows. |
3717 */ | 3666 */ |
3718 block_autocmds(); | 3667 block_autocmds(); |
3719 #endif | |
3720 | 3668 |
3721 for (todo = count - 1; todo > 0; --todo) | 3669 for (todo = count - 1; todo > 0; --todo) |
3722 if (win_new_tabpage(0) == FAIL) | 3670 if (win_new_tabpage(0) == FAIL) |
3723 break; | 3671 break; |
3724 | 3672 |
3725 #ifdef FEAT_AUTOCMD | |
3726 unblock_autocmds(); | 3673 unblock_autocmds(); |
3727 #endif | |
3728 | 3674 |
3729 /* return actual number of tab pages */ | 3675 /* return actual number of tab pages */ |
3730 return (count - todo); | 3676 return (count - todo); |
3731 } | 3677 } |
3732 | 3678 |
3839 int trigger_leave_autocmds UNUSED) | 3785 int trigger_leave_autocmds UNUSED) |
3840 { | 3786 { |
3841 tabpage_T *tp = curtab; | 3787 tabpage_T *tp = curtab; |
3842 | 3788 |
3843 reset_VIsual_and_resel(); /* stop Visual mode */ | 3789 reset_VIsual_and_resel(); /* stop Visual mode */ |
3844 #ifdef FEAT_AUTOCMD | |
3845 if (trigger_leave_autocmds) | 3790 if (trigger_leave_autocmds) |
3846 { | 3791 { |
3847 if (new_curbuf != curbuf) | 3792 if (new_curbuf != curbuf) |
3848 { | 3793 { |
3849 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); | 3794 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); |
3855 return FAIL; | 3800 return FAIL; |
3856 apply_autocmds(EVENT_TABLEAVE, NULL, NULL, FALSE, curbuf); | 3801 apply_autocmds(EVENT_TABLEAVE, NULL, NULL, FALSE, curbuf); |
3857 if (curtab != tp) | 3802 if (curtab != tp) |
3858 return FAIL; | 3803 return FAIL; |
3859 } | 3804 } |
3860 #endif | |
3861 #if defined(FEAT_GUI) | 3805 #if defined(FEAT_GUI) |
3862 /* Remove the scrollbars. They may be added back later. */ | 3806 /* Remove the scrollbars. They may be added back later. */ |
3863 if (gui.in_use) | 3807 if (gui.in_use) |
3864 gui_remove_scrollbars(); | 3808 gui_remove_scrollbars(); |
3865 #endif | 3809 #endif |
3927 /* When 'guioptions' includes 'L' or 'R' may have to remove or add | 3871 /* When 'guioptions' includes 'L' or 'R' may have to remove or add |
3928 * scrollbars. Have to update them anyway. */ | 3872 * scrollbars. Have to update them anyway. */ |
3929 gui_may_update_scrollbars(); | 3873 gui_may_update_scrollbars(); |
3930 #endif | 3874 #endif |
3931 | 3875 |
3932 #ifdef FEAT_AUTOCMD | |
3933 /* Apply autocommands after updating the display, when 'rows' and | 3876 /* Apply autocommands after updating the display, when 'rows' and |
3934 * 'columns' have been set correctly. */ | 3877 * 'columns' have been set correctly. */ |
3935 if (trigger_enter_autocmds) | 3878 if (trigger_enter_autocmds) |
3936 { | 3879 { |
3937 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); | 3880 apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); |
3938 if (old_curbuf != curbuf) | 3881 if (old_curbuf != curbuf) |
3939 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 3882 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
3940 } | 3883 } |
3941 #endif | |
3942 | 3884 |
3943 redraw_all_later(CLEAR); | 3885 redraw_all_later(CLEAR); |
3944 } | 3886 } |
3945 | 3887 |
3946 /* | 3888 /* |
4129 { | 4071 { |
4130 beep_flush(); | 4072 beep_flush(); |
4131 text_locked_msg(); | 4073 text_locked_msg(); |
4132 return; | 4074 return; |
4133 } | 4075 } |
4134 #ifdef FEAT_AUTOCMD | |
4135 if (curbuf_locked()) | 4076 if (curbuf_locked()) |
4136 return; | 4077 return; |
4137 #endif | |
4138 | 4078 |
4139 if (wp->w_buffer != curbuf) | 4079 if (wp->w_buffer != curbuf) |
4140 reset_VIsual_and_resel(); | 4080 reset_VIsual_and_resel(); |
4141 else if (VIsual_active) | 4081 else if (VIsual_active) |
4142 wp->w_cursor = curwin->w_cursor; | 4082 wp->w_cursor = curwin->w_cursor; |
4335 int curwin_invalid, | 4275 int curwin_invalid, |
4336 int trigger_new_autocmds UNUSED, | 4276 int trigger_new_autocmds UNUSED, |
4337 int trigger_enter_autocmds UNUSED, | 4277 int trigger_enter_autocmds UNUSED, |
4338 int trigger_leave_autocmds UNUSED) | 4278 int trigger_leave_autocmds UNUSED) |
4339 { | 4279 { |
4340 #ifdef FEAT_AUTOCMD | |
4341 int other_buffer = FALSE; | 4280 int other_buffer = FALSE; |
4342 #endif | |
4343 | 4281 |
4344 if (wp == curwin && !curwin_invalid) /* nothing to do */ | 4282 if (wp == curwin && !curwin_invalid) /* nothing to do */ |
4345 return; | 4283 return; |
4346 | 4284 |
4347 #ifdef FEAT_AUTOCMD | |
4348 if (!curwin_invalid && trigger_leave_autocmds) | 4285 if (!curwin_invalid && trigger_leave_autocmds) |
4349 { | 4286 { |
4350 /* | 4287 /* |
4351 * Be careful: If autocommands delete the window, return now. | 4288 * Be careful: If autocommands delete the window, return now. |
4352 */ | 4289 */ |
4358 return; | 4295 return; |
4359 } | 4296 } |
4360 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); | 4297 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); |
4361 if (!win_valid(wp)) | 4298 if (!win_valid(wp)) |
4362 return; | 4299 return; |
4363 # ifdef FEAT_EVAL | 4300 #ifdef FEAT_EVAL |
4364 /* autocmds may abort script processing */ | 4301 /* autocmds may abort script processing */ |
4365 if (aborting()) | 4302 if (aborting()) |
4366 return; | 4303 return; |
4367 # endif | 4304 #endif |
4368 } | 4305 } |
4369 #endif | |
4370 | 4306 |
4371 /* sync undo before leaving the current buffer */ | 4307 /* sync undo before leaving the current buffer */ |
4372 if (undo_sync && curbuf != wp->w_buffer) | 4308 if (undo_sync && curbuf != wp->w_buffer) |
4373 u_sync(FALSE); | 4309 u_sync(FALSE); |
4374 | 4310 |
4415 ignored = mch_chdir((char *)globaldir); | 4351 ignored = mch_chdir((char *)globaldir); |
4416 VIM_CLEAR(globaldir); | 4352 VIM_CLEAR(globaldir); |
4417 shorten_fnames(TRUE); | 4353 shorten_fnames(TRUE); |
4418 } | 4354 } |
4419 | 4355 |
4420 #ifdef FEAT_AUTOCMD | |
4421 if (trigger_new_autocmds) | 4356 if (trigger_new_autocmds) |
4422 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); | 4357 apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf); |
4423 if (trigger_enter_autocmds) | 4358 if (trigger_enter_autocmds) |
4424 { | 4359 { |
4425 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); | 4360 apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); |
4426 if (other_buffer) | 4361 if (other_buffer) |
4427 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 4362 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
4428 } | 4363 } |
4429 #endif | |
4430 | 4364 |
4431 #ifdef FEAT_TITLE | 4365 #ifdef FEAT_TITLE |
4432 maketitle(); | 4366 maketitle(); |
4433 #endif | 4367 #endif |
4434 curwin->w_redr_status = TRUE; | 4368 curwin->w_redr_status = TRUE; |
4542 return NULL; | 4476 return NULL; |
4543 } | 4477 } |
4544 init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE); | 4478 init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE); |
4545 #endif | 4479 #endif |
4546 | 4480 |
4547 #ifdef FEAT_AUTOCMD | |
4548 /* Don't execute autocommands while the window is not properly | 4481 /* Don't execute autocommands while the window is not properly |
4549 * initialized yet. gui_create_scrollbar() may trigger a FocusGained | 4482 * initialized yet. gui_create_scrollbar() may trigger a FocusGained |
4550 * event. */ | 4483 * event. */ |
4551 block_autocmds(); | 4484 block_autocmds(); |
4552 #endif | 4485 |
4553 /* | 4486 /* |
4554 * link the window in the window list | 4487 * link the window in the window list |
4555 */ | 4488 */ |
4556 if (!hidden) | 4489 if (!hidden) |
4557 win_append(after, new_wp); | 4490 win_append(after, new_wp); |
4583 } | 4516 } |
4584 #endif | 4517 #endif |
4585 #ifdef FEAT_FOLDING | 4518 #ifdef FEAT_FOLDING |
4586 foldInitWin(new_wp); | 4519 foldInitWin(new_wp); |
4587 #endif | 4520 #endif |
4588 #ifdef FEAT_AUTOCMD | |
4589 unblock_autocmds(); | 4521 unblock_autocmds(); |
4590 #endif | |
4591 #ifdef FEAT_SEARCH_EXTRA | 4522 #ifdef FEAT_SEARCH_EXTRA |
4592 new_wp->w_match_head = NULL; | 4523 new_wp->w_match_head = NULL; |
4593 new_wp->w_next_match_id = 4; | 4524 new_wp->w_next_match_id = 4; |
4594 #endif | 4525 #endif |
4595 return new_wp; | 4526 return new_wp; |
4612 #endif | 4543 #endif |
4613 | 4544 |
4614 /* reduce the reference count to the argument list. */ | 4545 /* reduce the reference count to the argument list. */ |
4615 alist_unlink(wp->w_alist); | 4546 alist_unlink(wp->w_alist); |
4616 | 4547 |
4617 #ifdef FEAT_AUTOCMD | |
4618 /* Don't execute autocommands while the window is halfway being deleted. | 4548 /* Don't execute autocommands while the window is halfway being deleted. |
4619 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ | 4549 * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ |
4620 block_autocmds(); | 4550 block_autocmds(); |
4621 #endif | |
4622 | 4551 |
4623 #ifdef FEAT_LUA | 4552 #ifdef FEAT_LUA |
4624 lua_window_free(wp); | 4553 lua_window_free(wp); |
4625 #endif | 4554 #endif |
4626 | 4555 |
4706 | 4635 |
4707 #ifdef FEAT_SYN_HL | 4636 #ifdef FEAT_SYN_HL |
4708 vim_free(wp->w_p_cc_cols); | 4637 vim_free(wp->w_p_cc_cols); |
4709 #endif | 4638 #endif |
4710 | 4639 |
4711 #ifdef FEAT_AUTOCMD | |
4712 if (wp != aucmd_win) | 4640 if (wp != aucmd_win) |
4713 #endif | |
4714 win_remove(wp, tp); | 4641 win_remove(wp, tp); |
4715 #ifdef FEAT_AUTOCMD | |
4716 if (autocmd_busy) | 4642 if (autocmd_busy) |
4717 { | 4643 { |
4718 wp->w_next = au_pending_free_win; | 4644 wp->w_next = au_pending_free_win; |
4719 au_pending_free_win = wp; | 4645 au_pending_free_win = wp; |
4720 } | 4646 } |
4721 else | 4647 else |
4722 #endif | |
4723 vim_free(wp); | 4648 vim_free(wp); |
4724 | 4649 |
4725 #ifdef FEAT_AUTOCMD | |
4726 unblock_autocmds(); | 4650 unblock_autocmds(); |
4727 #endif | |
4728 } | 4651 } |
4729 | 4652 |
4730 /* | 4653 /* |
4731 * Append window "wp" in the window list after window "after". | 4654 * Append window "wp" in the window list after window "after". |
4732 */ | 4655 */ |
6424 if (wp->w_buffer != NULL | 6347 if (wp->w_buffer != NULL |
6425 && (!((bt_help(wp->w_buffer) && !bt_help(curbuf)) | 6348 && (!((bt_help(wp->w_buffer) && !bt_help(curbuf)) |
6426 # ifdef FEAT_QUICKFIX | 6349 # ifdef FEAT_QUICKFIX |
6427 || wp->w_p_pvw | 6350 || wp->w_p_pvw |
6428 # endif | 6351 # endif |
6429 ) || wp == curwin) | 6352 ) || wp == curwin) && wp != aucmd_win) |
6430 # ifdef FEAT_AUTOCMD | |
6431 && wp != aucmd_win | |
6432 # endif | |
6433 ) | |
6434 ++count; | 6353 ++count; |
6435 return (count <= 1); | 6354 return (count <= 1); |
6436 } | 6355 } |
6437 | 6356 |
6438 /* | 6357 /* |
6611 tabpage_T **save_curtab, | 6530 tabpage_T **save_curtab, |
6612 win_T *win, | 6531 win_T *win, |
6613 tabpage_T *tp, | 6532 tabpage_T *tp, |
6614 int no_display) | 6533 int no_display) |
6615 { | 6534 { |
6616 # ifdef FEAT_AUTOCMD | |
6617 block_autocmds(); | 6535 block_autocmds(); |
6618 # endif | |
6619 *save_curwin = curwin; | 6536 *save_curwin = curwin; |
6620 if (tp != NULL) | 6537 if (tp != NULL) |
6621 { | 6538 { |
6622 *save_curtab = curtab; | 6539 *save_curtab = curtab; |
6623 if (no_display) | 6540 if (no_display) |
6665 if (win_valid(save_curwin)) | 6582 if (win_valid(save_curwin)) |
6666 { | 6583 { |
6667 curwin = save_curwin; | 6584 curwin = save_curwin; |
6668 curbuf = curwin->w_buffer; | 6585 curbuf = curwin->w_buffer; |
6669 } | 6586 } |
6670 # ifdef FEAT_AUTOCMD | |
6671 unblock_autocmds(); | 6587 unblock_autocmds(); |
6672 # endif | |
6673 } | 6588 } |
6674 | 6589 |
6675 /* | 6590 /* |
6676 * Make "buf" the current buffer. restore_buffer() MUST be called to undo. | 6591 * Make "buf" the current buffer. restore_buffer() MUST be called to undo. |
6677 * No autocommands will be executed. Use aucmd_prepbuf() if there are any. | 6592 * No autocommands will be executed. Use aucmd_prepbuf() if there are any. |
6678 */ | 6593 */ |
6679 void | 6594 void |
6680 switch_buffer(bufref_T *save_curbuf, buf_T *buf) | 6595 switch_buffer(bufref_T *save_curbuf, buf_T *buf) |
6681 { | 6596 { |
6682 # ifdef FEAT_AUTOCMD | |
6683 block_autocmds(); | 6597 block_autocmds(); |
6684 # endif | |
6685 set_bufref(save_curbuf, curbuf); | 6598 set_bufref(save_curbuf, curbuf); |
6686 --curbuf->b_nwindows; | 6599 --curbuf->b_nwindows; |
6687 curbuf = buf; | 6600 curbuf = buf; |
6688 curwin->w_buffer = buf; | 6601 curwin->w_buffer = buf; |
6689 ++curbuf->b_nwindows; | 6602 ++curbuf->b_nwindows; |
6693 * Restore the current buffer after using switch_buffer(). | 6606 * Restore the current buffer after using switch_buffer(). |
6694 */ | 6607 */ |
6695 void | 6608 void |
6696 restore_buffer(bufref_T *save_curbuf) | 6609 restore_buffer(bufref_T *save_curbuf) |
6697 { | 6610 { |
6698 # ifdef FEAT_AUTOCMD | |
6699 unblock_autocmds(); | 6611 unblock_autocmds(); |
6700 # endif | |
6701 /* Check for valid buffer, just in case. */ | 6612 /* Check for valid buffer, just in case. */ |
6702 if (bufref_valid(save_curbuf)) | 6613 if (bufref_valid(save_curbuf)) |
6703 { | 6614 { |
6704 --curbuf->b_nwindows; | 6615 --curbuf->b_nwindows; |
6705 curwin->w_buffer = save_curbuf->br_buf; | 6616 curwin->w_buffer = save_curbuf->br_buf; |