NF+BF: add close-figs option to plot_directive

Add `close-figs` choice to `context` option of plot_directive.  This
keeps the current context, but closes any previous figures.

This is necessary because the plot directive first runs the specified
code, then collects figures with:

    fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()

If you are using the "context" option, prior figures maybe generated
from a previous plot directive command, are still open, and therefore
collected with the new figure(s).  The old figures will usually be
earlier in the list, and so, for something like this ReST block, you
will always get the first generated figure (``range(10)``) repeated in
the second plot directive panel:

    #######
    A title
    #######

    .. plot::
        :context:

        import matplotlib.pyplot as plt
        plt.plot(range(10))

        Then some text.

    .. plot::
        :context:

        plt.figure()
        plt.plot(range(5), 'r')

This PR add a context option of form `:context: close-figs` that closes
any previous figure windows before running the directive code.

It also adds a small test sphinx project to test the directive commands.

See email discussion thread starting here:

https://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg10816.html
BUG: add fix for Python 2.6 compatibility

re.flags argument to re.sub appears to a 2.7 innovation.