Mirror of the Vim source from https://github.com/vim/vim
Revision | cdd82acd75b449784a574058387449096667e56f (tree) |
---|---|
Time | 2007-09-29 21:16:41 |
Author | vimboss |
Commiter | vimboss |
updated for version 7.1-125
@@ -5515,11 +5515,11 @@ | ||
5515 | 5515 | |
5516 | 5516 | #ifdef FEAT_AUTOCMD |
5517 | 5517 | if (!aucmd) /* Don't trigger BufDelete autocommands here. */ |
5518 | - ++autocmd_block; | |
5518 | + block_autocmds(); | |
5519 | 5519 | #endif |
5520 | 5520 | close_buffer(NULL, buf, DOBUF_WIPE); |
5521 | 5521 | #ifdef FEAT_AUTOCMD |
5522 | 5522 | if (!aucmd) |
5523 | - --autocmd_block; | |
5523 | + unblock_autocmds(); | |
5524 | 5524 | #endif |
5525 | 5525 | } |
@@ -840,11 +840,11 @@ | ||
840 | 840 | tmp_orig, tmp_new); |
841 | 841 | append_redir(cmd, p_srr, tmp_diff); |
842 | 842 | #ifdef FEAT_AUTOCMD |
843 | - ++autocmd_block; /* Avoid ShellCmdPost stuff */ | |
843 | + block_autocmds(); /* Avoid ShellCmdPost stuff */ | |
844 | 844 | #endif |
845 | 845 | (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); |
846 | 846 | #ifdef FEAT_AUTOCMD |
847 | - --autocmd_block; | |
847 | + unblock_autocmds(); | |
848 | 848 | #endif |
849 | 849 | vim_free(cmd); |
850 | 850 | } |
@@ -949,11 +949,11 @@ | ||
949 | 949 | # endif |
950 | 950 | eap->arg); |
951 | 951 | #ifdef FEAT_AUTOCMD |
952 | - ++autocmd_block; /* Avoid ShellCmdPost stuff */ | |
952 | + block_autocmds(); /* Avoid ShellCmdPost stuff */ | |
953 | 953 | #endif |
954 | 954 | (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
955 | 955 | #ifdef FEAT_AUTOCMD |
956 | - --autocmd_block; | |
956 | + unblock_autocmds(); | |
957 | 957 | #endif |
958 | 958 | } |
959 | 959 |
@@ -5925,7 +5925,7 @@ | ||
5925 | 5925 | |
5926 | 5926 | # ifdef FEAT_AUTOCMD |
5927 | 5927 | /* Don't execute autocommands while creating the window. */ |
5928 | - ++autocmd_block; | |
5928 | + block_autocmds(); | |
5929 | 5929 | # endif |
5930 | 5930 | /* don't use a new tab page */ |
5931 | 5931 | cmdmod.tab = 0; |
@@ -5934,6 +5934,9 @@ | ||
5934 | 5934 | if (win_split((int)p_cwh, WSP_BOT) == FAIL) |
5935 | 5935 | { |
5936 | 5936 | beep_flush(); |
5937 | +# ifdef FEAT_AUTOCMD | |
5938 | + unblock_autocmds(); | |
5939 | +# endif | |
5937 | 5940 | return K_IGNORE; |
5938 | 5941 | } |
5939 | 5942 | cmdwin_type = ccline.cmdfirstc; |
@@ -5956,7 +5959,7 @@ | ||
5956 | 5959 | |
5957 | 5960 | # ifdef FEAT_AUTOCMD |
5958 | 5961 | /* Do execute autocommands for setting the filetype (load syntax). */ |
5959 | - --autocmd_block; | |
5962 | + unblock_autocmds(); | |
5960 | 5963 | # endif |
5961 | 5964 | |
5962 | 5965 | /* Showing the prompt may have set need_wait_return, reset it. */ |
@@ -6110,7 +6113,7 @@ | ||
6110 | 6113 | |
6111 | 6114 | # ifdef FEAT_AUTOCMD |
6112 | 6115 | /* Don't execute autocommands while deleting the window. */ |
6113 | - ++autocmd_block; | |
6116 | + block_autocmds(); | |
6114 | 6117 | # endif |
6115 | 6118 | wp = curwin; |
6116 | 6119 | bp = curbuf; |
@@ -6122,7 +6125,7 @@ | ||
6122 | 6125 | win_size_restore(&winsizes); |
6123 | 6126 | |
6124 | 6127 | # ifdef FEAT_AUTOCMD |
6125 | - --autocmd_block; | |
6128 | + unblock_autocmds(); | |
6126 | 6129 | # endif |
6127 | 6130 | } |
6128 | 6131 |
@@ -7165,6 +7165,7 @@ | ||
7165 | 7165 | |
7166 | 7166 | static event_T last_event; |
7167 | 7167 | static int last_group; |
7168 | +static int autocmd_blocked = 0; /* block all autocmds */ | |
7168 | 7169 | |
7169 | 7170 | /* |
7170 | 7171 | * Show the autocommands for one AutoPat. |
@@ -8454,7 +8455,7 @@ | ||
8454 | 8455 | * Quickly return if there are no autocommands for this event or |
8455 | 8456 | * autocommands are blocked. |
8456 | 8457 | */ |
8457 | - if (first_autopat[(int)event] == NULL || autocmd_block > 0) | |
8458 | + if (first_autopat[(int)event] == NULL || autocmd_blocked > 0) | |
8458 | 8459 | goto BYPASS_AU; |
8459 | 8460 | |
8460 | 8461 | /* |
@@ -8768,6 +8769,40 @@ | ||
8768 | 8769 | return retval; |
8769 | 8770 | } |
8770 | 8771 | |
8772 | +# ifdef FEAT_EVAL | |
8773 | +static char_u *old_termresponse = NULL; | |
8774 | +# endif | |
8775 | + | |
8776 | +/* | |
8777 | + * Block triggering autocommands until unblock_autocmd() is called. | |
8778 | + * Can be used recursively, so long as it's symmetric. | |
8779 | + */ | |
8780 | + void | |
8781 | +block_autocmds() | |
8782 | +{ | |
8783 | +# ifdef FEAT_EVAL | |
8784 | + /* Remember the value of v:termresponse. */ | |
8785 | + if (autocmd_blocked == 0) | |
8786 | + old_termresponse = get_vim_var_str(VV_TERMRESPONSE); | |
8787 | +# endif | |
8788 | + ++autocmd_blocked; | |
8789 | +} | |
8790 | + | |
8791 | + void | |
8792 | +unblock_autocmds() | |
8793 | +{ | |
8794 | + --autocmd_blocked; | |
8795 | + | |
8796 | +# ifdef FEAT_EVAL | |
8797 | + /* When v:termresponse was set while autocommands were blocked, trigger | |
8798 | + * the autocommands now. Esp. useful when executing a shell command | |
8799 | + * during startup (vimdiff). */ | |
8800 | + if (autocmd_blocked == 0 | |
8801 | + && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse) | |
8802 | + apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf); | |
8803 | +# endif | |
8804 | +} | |
8805 | + | |
8771 | 8806 | /* |
8772 | 8807 | * Find next autocommand pattern that matches. |
8773 | 8808 | */ |
@@ -366,7 +366,6 @@ | ||
366 | 366 | EXTERN int autocmd_busy INIT(= FALSE); /* Is apply_autocmds() busy? */ |
367 | 367 | EXTERN int autocmd_no_enter INIT(= FALSE); /* *Enter autocmds disabled */ |
368 | 368 | EXTERN int autocmd_no_leave INIT(= FALSE); /* *Leave autocmds disabled */ |
369 | -EXTERN int autocmd_block INIT(= 0); /* block all autocmds */ | |
370 | 369 | EXTERN int modified_was_set; /* did ":set modified" */ |
371 | 370 | EXTERN int did_filetype INIT(= FALSE); /* FileType event found */ |
372 | 371 | EXTERN int keep_filetype INIT(= FALSE); /* value for did_filetype when |
@@ -972,7 +972,7 @@ | ||
972 | 972 | return; |
973 | 973 | entered = TRUE; |
974 | 974 | |
975 | - ++autocmd_block; /* don't want to trigger autocommands here */ | |
975 | + block_autocmds(); /* don't want to trigger autocommands here */ | |
976 | 976 | |
977 | 977 | #ifdef FEAT_WINDOWS |
978 | 978 | /* close all tabs and windows */ |
@@ -40,6 +40,8 @@ | ||
40 | 40 | int trigger_cursorhold __ARGS((void)); |
41 | 41 | int has_cursormoved __ARGS((void)); |
42 | 42 | int has_cursormovedI __ARGS((void)); |
43 | +void block_autocmds __ARGS((void)); | |
44 | +void unblock_autocmds __ARGS((void)); | |
43 | 45 | int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf)); |
44 | 46 | char_u *get_augroup_name __ARGS((expand_T *xp, int idx)); |
45 | 47 | char_u *set_context_in_autocmd __ARGS((expand_T *xp, char_u *arg, int doautocmd)); |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 125, | |
671 | +/**/ | |
670 | 672 | 124, |
671 | 673 | /**/ |
672 | 674 | 123, |
@@ -1291,7 +1291,7 @@ | ||
1291 | 1291 | * Don't execute autocommands while creating the windows. Must do that |
1292 | 1292 | * when putting the buffers in the windows. |
1293 | 1293 | */ |
1294 | - ++autocmd_block; | |
1294 | + block_autocmds(); | |
1295 | 1295 | #endif |
1296 | 1296 | |
1297 | 1297 | /* todo is number of windows left to create */ |
@@ -1313,7 +1313,7 @@ | ||
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | #ifdef FEAT_AUTOCMD |
1316 | - --autocmd_block; | |
1316 | + unblock_autocmds(); | |
1317 | 1317 | #endif |
1318 | 1318 | |
1319 | 1319 | /* return actual number of windows */ |
@@ -3415,7 +3415,7 @@ | ||
3415 | 3415 | * Don't execute autocommands while creating the tab pages. Must do that |
3416 | 3416 | * when putting the buffers in the windows. |
3417 | 3417 | */ |
3418 | - ++autocmd_block; | |
3418 | + block_autocmds(); | |
3419 | 3419 | #endif |
3420 | 3420 | |
3421 | 3421 | for (todo = count - 1; todo > 0; --todo) |
@@ -3423,7 +3423,7 @@ | ||
3423 | 3423 | break; |
3424 | 3424 | |
3425 | 3425 | #ifdef FEAT_AUTOCMD |
3426 | - --autocmd_block; | |
3426 | + unblock_autocmds(); | |
3427 | 3427 | #endif |
3428 | 3428 | |
3429 | 3429 | /* return actual number of tab pages */ |
@@ -4162,7 +4162,7 @@ | ||
4162 | 4162 | /* Don't execute autocommands while the window is not properly |
4163 | 4163 | * initialized yet. gui_create_scrollbar() may trigger a FocusGained |
4164 | 4164 | * event. */ |
4165 | - ++autocmd_block; | |
4165 | + block_autocmds(); | |
4166 | 4166 | #endif |
4167 | 4167 | /* |
4168 | 4168 | * link the window in the window list |
@@ -4207,7 +4207,7 @@ | ||
4207 | 4207 | foldInitWin(newwin); |
4208 | 4208 | #endif |
4209 | 4209 | #ifdef FEAT_AUTOCMD |
4210 | - --autocmd_block; | |
4210 | + unblock_autocmds(); | |
4211 | 4211 | #endif |
4212 | 4212 | #ifdef FEAT_SEARCH_EXTRA |
4213 | 4213 | newwin->w_match_head = NULL; |
@@ -4232,7 +4232,7 @@ | ||
4232 | 4232 | #ifdef FEAT_AUTOCMD |
4233 | 4233 | /* Don't execute autocommands while the window is halfway being deleted. |
4234 | 4234 | * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ |
4235 | - ++autocmd_block; | |
4235 | + block_autocmds(); | |
4236 | 4236 | #endif |
4237 | 4237 | |
4238 | 4238 | #ifdef FEAT_MZSCHEME |
@@ -4295,7 +4295,7 @@ | ||
4295 | 4295 | vim_free(wp); |
4296 | 4296 | |
4297 | 4297 | #ifdef FEAT_AUTOCMD |
4298 | - --autocmd_block; | |
4298 | + unblock_autocmds(); | |
4299 | 4299 | #endif |
4300 | 4300 | } |
4301 | 4301 |