On Sun, Sep 6, 2009 at 12:11 PM, Bram Moolenaar <[email protected]> wrote:
>
> Bob Hiestand wrote:
>
> > On Thu, Sep 3, 2009 at 6:13 AM, Bram Moolenaar<[email protected]>
> wrote:
> >
> > >> Here's a probably better patch, and a test case to show the behavior I
> > >> expect from exists() with respect to autocommands:
> > >
> > > Thanks for the patch and testcase script. Would you be able to turn
> the
> > > script into a test for src/testdir? That will greatly help avoid
> > > regressions.
> >
> > Sure, something like the following?
>
> Looks good.
>
> To make it a bit easier to locate any exists() that doesn't do what was
> expected, can you make it:
>
> :call add(results, '##BufEnter: ' + exists('##BufEnter'))
>
>
Sure, a revised patch is attached.
Thank you,
bob
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
diff --git a/src/fileio.c b/src/fileio.c
index a9552b5..5da1a96 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -9498,15 +9498,10 @@ au_exists(arg)
ap = first_autopat[(int)event];
if (ap == NULL)
goto theend;
- if (pattern == NULL)
- {
- retval = TRUE;
- goto theend;
- }
/* if pattern is "<buffer>", special handling is needed which uses curbuf */
/* for pattern "<buffer=N>, fnamecmp() will work fine */
- if (STRICMP(pattern, "<buffer>") == 0)
+ if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0)
buflocal_buf = curbuf;
/* Check if there is an autocommand with the given pattern. */
@@ -9515,9 +9510,10 @@ au_exists(arg)
/* For buffer-local autocommands, fnamecmp() works fine. */
if (ap->pat != NULL && ap->cmds != NULL
&& (group == AUGROUP_ALL || ap->group == group)
- && (buflocal_buf == NULL
- ? fnamecmp(ap->pat, pattern) == 0
- : ap->buflocal_nr == buflocal_buf->b_fnum))
+ && (pattern == NULL
+ || (buflocal_buf == NULL
+ ? fnamecmp(ap->pat, pattern) == 0
+ : ap->buflocal_nr == buflocal_buf->b_fnum)))
{
retval = TRUE;
break;
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index 50386ec..8f9fd13 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -22,7 +22,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test48.out test49.out test51.out test52.out test53.out \
test54.out test55.out test56.out test57.out test58.out \
test59.out test60.out test61.out test62.out test63.out \
- test64.out test65.out test66.out
+ test64.out test65.out test66.out test67.out
SCRIPTS_GUI = test16.out
diff --git a/src/testdir/test67.in b/src/testdir/test67.in
new file mode 100644
index 0000000..a89c7ee
--- /dev/null
+++ b/src/testdir/test67.in
@@ -0,0 +1,35 @@
+Test that groups and patterns are tested correctly when calling exists() for autocommands.
+
+STARTTEST
+:so small.vim
+:let results=[]
+:augroup auexists
+:augroup END
+:call add(results, 'Invalid event (##Invalid): ' . exists('##Invalid'))
+:call add(results, 'Valid event (##BufEnter): ' . exists('##BufEnter'))
+:call add(results, 'Undefined event handler (#BufEnter): ' . exists('#BufEnter'))
+:au BufEnter * let g:entered=1
+:call add(results, 'Defined event handler (#BufEnter): ' . exists('#BufEnter'))
+:call add(results, 'Undefined grouped event handler (#auexists#BufEnter): ' . exists('#auexists#BufEnter'))
+:augroup auexists
+:au BufEnter * let g:entered=1
+:augroup END
+:call add(results, 'Defined grouped event handler (#auexists#BufEnter): ' . exists('#auexists#BufEnter'))
+:call add(results, 'Undefined patterened event handler (#BufEnter#*.test): ' . exists('#BufEnter#*.test'))
+:au BufEnter *.test let g:entered=1
+:call add(results, 'Undefined patterened event handler (#BufEnter#*.test): ' . exists('#BufEnter#*.test2'))
+:call add(results, 'Defined patterened event handler (#BufEnter#*.test): ' . exists('#BufEnter#*.test'))
+:edit testfile.test
+:call add(results, 'Undefined buffer event handler (#BufEnter#<buffer>): ' . exists('#BufEnter#<buffer>'))
+:au BufEnter <buffer> let g:entered=1
+:edit testfile2.test
+:call add(results, 'Undefined buffer event handler (#BufEnter#<buffer>): ' . exists('#BufEnter#<buffer>'))
+:edit testfile.test
+:call add(results, 'Defined buffer event handler (#BufEnter#<buffer>): ' . exists('#BufEnter#<buffer>'))
+:e test.out
+:call append(0, results)
+:$d
+:w
+:qa!
+ENDTEST
+
diff --git a/src/testdir/test67.ok b/src/testdir/test67.ok
new file mode 100644
index 0000000..4faa76e
--- /dev/null
+++ b/src/testdir/test67.ok
@@ -0,0 +1,12 @@
+Invalid event (##Invalid): 0
+Valid event (##BufEnter): 1
+Undefined event handler (#BufEnter): 0
+Defined event handler (#BufEnter): 1
+Undefined grouped event handler (#auexists#BufEnter): 0
+Defined grouped event handler (#auexists#BufEnter): 1
+Undefined patterened event handler (#BufEnter#*.test): 0
+Undefined patterened event handler (#BufEnter#*.test): 0
+Defined patterened event handler (#BufEnter#*.test): 1
+Undefined buffer event handler (#BufEnter#<buffer>): 0
+Undefined buffer event handler (#BufEnter#<buffer>): 0
+Defined buffer event handler (#BufEnter#<buffer>): 1