Patch 7.4.2103
Problem: Can't have "augroup END" right after ":au!".
Solution: Check for the bar character before the command argument.
Files: src/fileio.c, src/testdir/test_autocmd.vim,
runtime/doc/autocmd.txt
*** ../vim-7.4.2102/src/fileio.c 2016-07-24 21:58:39.704057634 +0200
--- src/fileio.c 2016-07-26 20:36:53.020012452 +0200
***************
*** 8100,8107 ****
int i;
int len;
! /* the event name ends with end of line, a blank or a comma */
! for (p = start; *p && !vim_iswhite(*p) && *p != ','; ++p)
;
for (i = 0; event_names[i].name != NULL; ++i)
{
--- 8100,8107 ----
int i;
int len;
! /* the event name ends with end of line, '|', a blank or a comma */
! for (p = start; *p && !vim_iswhite(*p) && *p != ',' && *p != '|'; ++p)
;
for (i = 0; event_names[i].name != NULL; ++i)
{
***************
*** 8153,8159 ****
}
else
{
! for (pat = arg; *pat && !vim_iswhite(*pat); pat = p)
{
if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS)
{
--- 8153,8159 ----
}
else
{
! for (pat = arg; *pat && *pat != '|' && !vim_iswhite(*pat); pat = p)
{
if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS)
{
***************
*** 8286,8293 ****
* Mostly a {group} argument can optionally appear before <event>.
*/
void
! do_autocmd(char_u *arg, int forceit)
{
char_u *pat;
char_u *envpat = NULL;
char_u *cmd;
--- 8286,8294 ----
* Mostly a {group} argument can optionally appear before <event>.
*/
void
! do_autocmd(char_u *arg_in, int forceit)
{
+ char_u *arg = arg_in;
char_u *pat;
char_u *envpat = NULL;
char_u *cmd;
***************
*** 8296,8307 ****
int nested = FALSE;
int group;
! /*
! * Check for a legal group name. If not, use AUGROUP_ALL.
! */
! group = au_get_grouparg(&arg);
! if (arg == NULL) /* out of memory */
! return;
/*
* Scan over the events.
--- 8297,8316 ----
int nested = FALSE;
int group;
! if (*arg == '|')
! {
! arg = (char_u *)"";
! group = AUGROUP_ALL; /* no argument, use all groups */
! }
! else
! {
! /*
! * Check for a legal group name. If not, use AUGROUP_ALL.
! */
! group = au_get_grouparg(&arg);
! if (arg == NULL) /* out of memory */
! return;
! }
/*
* Scan over the events.
***************
*** 8311,8363 ****
if (pat == NULL)
return;
- /*
- * Scan over the pattern. Put a NUL at the end.
- */
pat = skipwhite(pat);
! cmd = pat;
! while (*cmd && (!vim_iswhite(*cmd) || cmd[-1] == '\\'))
! cmd++;
! if (*cmd)
! *cmd++ = NUL;
!
! /* Expand environment variables in the pattern. Set 'shellslash', we want
! * forward slashes here. */
! if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL)
{
#ifdef BACKSLASH_IN_FILENAME
! int p_ssl_save = p_ssl;
! p_ssl = TRUE;
#endif
! envpat = expand_env_save(pat);
#ifdef BACKSLASH_IN_FILENAME
! p_ssl = p_ssl_save;
#endif
! if (envpat != NULL)
! pat = envpat;
! }
! /*
! * Check for "nested" flag.
! */
! cmd = skipwhite(cmd);
! if (*cmd != NUL && STRNCMP(cmd, "nested", 6) == 0 && vim_iswhite(cmd[6]))
! {
! nested = TRUE;
! cmd = skipwhite(cmd + 6);
! }
! /*
! * Find the start of the commands.
! * Expand <sfile> in it.
! */
! if (*cmd != NUL)
! {
! cmd = expand_sfile(cmd);
! if (cmd == NULL) /* some error */
! return;
! need_free = TRUE;
}
/*
--- 8320,8380 ----
if (pat == NULL)
return;
pat = skipwhite(pat);
! if (*pat == '|')
{
+ pat = (char_u *)"";
+ cmd = (char_u *)"";
+ }
+ else
+ {
+ /*
+ * Scan over the pattern. Put a NUL at the end.
+ */
+ cmd = pat;
+ while (*cmd && (!vim_iswhite(*cmd) || cmd[-1] == '\\'))
+ cmd++;
+ if (*cmd)
+ *cmd++ = NUL;
+
+ /* Expand environment variables in the pattern. Set 'shellslash', we
want
+ * forward slashes here. */
+ if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL)
+ {
#ifdef BACKSLASH_IN_FILENAME
! int p_ssl_save = p_ssl;
! p_ssl = TRUE;
#endif
! envpat = expand_env_save(pat);
#ifdef BACKSLASH_IN_FILENAME
! p_ssl = p_ssl_save;
#endif
! if (envpat != NULL)
! pat = envpat;
! }
! /*
! * Check for "nested" flag.
! */
! cmd = skipwhite(cmd);
! if (*cmd != NUL && STRNCMP(cmd, "nested", 6) == 0 &&
vim_iswhite(cmd[6]))
! {
! nested = TRUE;
! cmd = skipwhite(cmd + 6);
! }
! /*
! * Find the start of the commands.
! * Expand <sfile> in it.
! */
! if (*cmd != NUL)
! {
! cmd = expand_sfile(cmd);
! if (cmd == NULL) /* some error */
! return;
! need_free = TRUE;
! }
}
/*
***************
*** 8374,8380 ****
*/
last_event = (event_T)-1; /* for listing the event name */
last_group = AUGROUP_ERROR; /* for listing the group name */
! if (*arg == '*' || *arg == NUL)
{
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1))
--- 8391,8397 ----
*/
last_event = (event_T)-1; /* for listing the event name */
last_group = AUGROUP_ERROR; /* for listing the group name */
! if (*arg == '*' || *arg == NUL || *arg == '|')
{
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1))
***************
*** 8384,8390 ****
}
else
{
! while (*arg && !vim_iswhite(*arg))
if (do_autocmd_event(event_name2nr(arg, &arg), pat,
nested, cmd, forceit, group) == FAIL)
break;
--- 8401,8407 ----
}
else
{
! while (*arg && *arg != '|' && !vim_iswhite(*arg))
if (do_autocmd_event(event_name2nr(arg, &arg), pat,
nested, cmd, forceit, group) == FAIL)
break;
***************
*** 8409,8415 ****
char_u *arg = *argp;
int group = AUGROUP_ALL;
! p = skiptowhite(arg);
if (p > arg)
{
group_name = vim_strnsave(arg, (int)(p - arg));
--- 8426,8433 ----
char_u *arg = *argp;
int group = AUGROUP_ALL;
! for (p = arg; *p && !vim_iswhite(*p) && *p != '|'; ++p)
! ;
if (p > arg)
{
group_name = vim_strnsave(arg, (int)(p - arg));
*** ../vim-7.4.2102/src/testdir/test_autocmd.vim 2016-07-19
23:12:18.716611687 +0200
--- src/testdir/test_autocmd.vim 2016-07-26 20:26:58.577461120 +0200
***************
*** 19,24 ****
--- 19,25 ----
call timer_start(100, 'ExitInsertMode')
call feedkeys('a', 'x!')
call assert_equal(1, g:triggered)
+ au! CursorHoldI
endfunc
func Test_cursorhold_insert_ctrl_x()
***************
*** 29,34 ****
--- 30,36 ----
" CursorHoldI does not trigger after CTRL-X
call feedkeys("a\<C-X>", 'x!')
call assert_equal(0, g:triggered)
+ au! CursorHoldI
endfunc
endif
***************
*** 58,63 ****
--- 60,66 ----
bwipeout
call assert_equal(["bufunload", "bufdelete", "bufwipeout"], s:li)
+ au! test_bufunload_group
augroup! test_bufunload_group
endfunc
***************
*** 120,122 ****
--- 123,153 ----
augroup END
unlet g:record
endfunc
+
+ func s:AddAnAutocmd()
+ augroup vimBarTest
+ au BufReadCmd * echo 'hello'
+ augroup END
+ call assert_equal(3, len(split(execute('au vimBarTest'), "\n")))
+ endfunc
+
+ func Test_early_bar()
+ " test that a bar is recognized before the {event}
+ call s:AddAnAutocmd()
+ augroup vimBarTest | au! | augroup END
+ call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
+
+ call s:AddAnAutocmd()
+ augroup vimBarTest| au!| augroup END
+ call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
+
+ " test that a bar is recognized after the {event}
+ call s:AddAnAutocmd()
+ augroup vimBarTest| au!BufReadCmd| augroup END
+ call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
+
+ " test that a bar is recognized after the {group}
+ call s:AddAnAutocmd()
+ au! vimBarTest|echo 'hello'
+ call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
+ endfunc
*** ../vim-7.4.2102/runtime/doc/autocmd.txt 2016-07-19 23:12:18.716611687
+0200
--- runtime/doc/autocmd.txt 2016-07-26 20:24:26.482855960 +0200
***************
*** 52,60 ****
==============================================================================
2. Defining autocommands *autocmd-define*
- Note: The ":autocmd" command cannot be followed by another command, since any
- '|' is considered part of the command.
-
*:au* *:autocmd*
:au[tocmd] [group] {event} {pat} [nested] {cmd}
Add {cmd} to the list of commands that Vim will
--- 52,57 ----
***************
*** 67,72 ****
--- 64,75 ----
The special pattern <buffer> or <buffer=N> defines a buffer-local autocommand.
See |autocmd-buflocal|.
+ Note: The ":autocmd" command can only be followed by another command when the
+ '|' appears before {cmd}. This works: >
+ :augroup mine | au! BufRead | augroup END
+ But this sees "augroup" as part of the defined command: >
+ :augroup mine | au BufRead * set tw=70 | augroup END
+
Note that special characters (e.g., "%", "<cword>") in the ":autocmd"
arguments are not expanded when the autocommand is defined. These will be
expanded when the Event is recognized, and the {cmd} is executed. The only
*** ../vim-7.4.2102/src/version.c 2016-07-24 22:25:11.217375024 +0200
--- src/version.c 2016-07-25 21:53:52.123603600 +0200
***************
*** 760,761 ****
--- 760,763 ----
{ /* Add new patch number below this line */
+ /**/
+ 2103,
/**/
--
An indication you must be a manager:
You can explain to somebody the difference between "re-engineering",
"down-sizing", "right-sizing", and "firing people's asses".
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.