aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/fileio.c25
-rw-r--r--src/nvim/globals.h1
-rw-r--r--src/nvim/testdir/test_autocmd.vim70
3 files changed, 90 insertions, 6 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 53b945d983..b2840c9402 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -6061,17 +6061,30 @@ void do_autocmd(char_u *arg_in, int forceit)
for (size_t i = 0; i < 2; i++) {
if (*cmd != NUL) {
// Check for "++once" flag.
- if (!once && STRNCMP(cmd, "++once", 6) == 0 && ascii_iswhite(cmd[6])) {
+ if (STRNCMP(cmd, "++once", 6) == 0 && ascii_iswhite(cmd[6])) {
+ if (once) {
+ EMSG2(_(e_duparg2), "++once");
+ }
once = true;
cmd = skipwhite(cmd + 6);
}
+
// Check for "++nested" flag.
- if (!nested
- && ((STRNCMP(cmd, "++nested", 8) == 0 && ascii_iswhite(cmd[8]))
- // Deprecated form (without "++").
- || (STRNCMP(cmd, "nested", 6) == 0 && ascii_iswhite(cmd[6])))) {
+ if ((STRNCMP(cmd, "++nested", 8) == 0 && ascii_iswhite(cmd[8]))) {
+ if (nested) {
+ EMSG2(_(e_duparg2), "++nested");
+ }
+ nested = true;
+ cmd = skipwhite(cmd + 8);
+ }
+
+ // Check for the old (deprecated) "nested" flag.
+ if (STRNCMP(cmd, "nested", 6) == 0 && ascii_iswhite(cmd[6])) {
+ if (nested) {
+ EMSG2(_(e_duparg2), "nested");
+ }
nested = true;
- cmd = skipwhite(cmd + ('+' == cmd[0] ? 8 : 6));
+ cmd = skipwhite(cmd + 6);
}
}
}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index a4d31c0c08..b529357dea 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -931,6 +931,7 @@ EXTERN char_u e_interr[] INIT(= N_("Interrupted"));
EXTERN char_u e_invaddr[] INIT(= N_("E14: Invalid address"));
EXTERN char_u e_invarg[] INIT(= N_("E474: Invalid argument"));
EXTERN char_u e_invarg2[] INIT(= N_("E475: Invalid argument: %s"));
+EXTERN char_u e_duparg2[] INIT(= N_("E983: Duplicate argument: %s"));
EXTERN char_u e_invexpr2[] INIT(= N_("E15: Invalid expression: %s"));
EXTERN char_u e_invrange[] INIT(= N_("E16: Invalid range"));
EXTERN char_u e_invcmd[] INIT(= N_("E476: Invalid command"));
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index 7a6c9478ca..6d4c54bbf9 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -1308,3 +1308,73 @@ func Test_Changed_FirstTime()
call delete('Xchanged.txt')
bwipe!
endfunc
+
+func Test_autocmd_nested()
+ let g:did_nested = 0
+ augroup Testing
+ au WinNew * edit somefile
+ au BufNew * let g:did_nested = 1
+ augroup END
+ split
+ call assert_equal(0, g:did_nested)
+ close
+ bwipe! somefile
+
+ " old nested argument still works
+ augroup Testing
+ au!
+ au WinNew * nested edit somefile
+ au BufNew * let g:did_nested = 1
+ augroup END
+ split
+ call assert_equal(1, g:did_nested)
+ close
+ bwipe! somefile
+
+ " New ++nested argument works
+ augroup Testing
+ au!
+ au WinNew * ++nested edit somefile
+ au BufNew * let g:did_nested = 1
+ augroup END
+ split
+ call assert_equal(1, g:did_nested)
+ close
+ bwipe! somefile
+
+ augroup Testing
+ au!
+ augroup END
+
+ call assert_fails('au WinNew * ++nested ++nested echo bad', 'E983:')
+ call assert_fails('au WinNew * nested nested echo bad', 'E983:')
+endfunc
+
+func Test_autocmd_once()
+ " Without ++once WinNew triggers twice
+ let g:did_split = 0
+ augroup Testing
+ au WinNew * let g:did_split += 1
+ augroup END
+ split
+ split
+ call assert_equal(2, g:did_split)
+ call assert_true(exists('#WinNew'))
+ close
+ close
+
+ " With ++once WinNew triggers once
+ let g:did_split = 0
+ augroup Testing
+ au!
+ au WinNew * ++once let g:did_split += 1
+ augroup END
+ split
+ split
+ call assert_equal(1, g:did_split)
+ call assert_false(exists('#WinNew'))
+ close
+ close
+
+ call assert_fails('au WinNew * ++once ++once echo bad', 'E983:')
+endfunc