From 73b8424fad108d1ae5981f7fad32f12df35fef2e Mon Sep 17 00:00:00 2001 From: Jurica Bradarić Date: Sun, 4 Sep 2016 23:43:41 +0200 Subject: vim-patch:7.4.1913 (#5260) Problem: When ":doautocmd" is used modelines are used even when no autocommands were executed. (Daniel Hahler) Solution: Skip processing modelines. (closes vim/vim#854) https://github.com/vim/vim/commit/1610d052413e0ed664498853a47acc2d677a22d1 --- src/nvim/fileio.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index e0b6ae1215..89e5fdb776 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3773,8 +3773,9 @@ static int set_rw_fname(char_u *fname, char_u *sfname) /* Do filetype detection now if 'filetype' is empty. */ if (*curbuf->b_p_ft == NUL) { - if (au_has_group((char_u *)"filetypedetect")) - (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE); + if (au_has_group((char_u *)"filetypedetect")) { + (void)do_doautocmd((char_u *)"filetypedetect BufRead", false, NULL); + } do_modelines(0); } @@ -6058,13 +6059,18 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, int do_doautocmd ( char_u *arg, - int do_msg /* give message for no matching autocmds? */ + int do_msg, // give message for no matching autocmds? + bool *did_something ) { char_u *fname; int nothing_done = TRUE; int group; + if (did_something != NULL) { + *did_something = false; + } + /* * Check for a legal group name. If not, use AUGROUP_ALL. */ @@ -6093,8 +6099,12 @@ do_doautocmd ( fname, NULL, TRUE, group, curbuf, NULL)) nothing_done = FALSE; - if (nothing_done && do_msg) + if (nothing_done && do_msg) { MSG(_("No matching autocommands")); + } + if (did_something != NULL) { + *did_something = !nothing_done; + } return aborting() ? FAIL : OK; } @@ -6123,13 +6133,14 @@ void ex_doautoall(exarg_T *eap) /* find a window for this buffer and save some values */ aucmd_prepbuf(&aco, buf); - /* execute the autocommands for this buffer */ - retval = do_doautocmd(arg, FALSE); + bool did_aucmd; + // execute the autocommands for this buffer + retval = do_doautocmd(arg, false, &did_aucmd); - if (call_do_modelines) { - /* Execute the modeline settings, but don't set window-local - * options if we are using the current window for another - * buffer. */ + if (call_do_modelines && did_aucmd) { + // Execute the modeline settings, but don't set window-local + // options if we are using the current window for another + // buffer. do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0); } -- cgit