/*
 * Glob_Close.bsh - a BeanShell macro for jEdit that closes
 * all open buffers matching a given glob pattern.
 *
 * Copyright (C) 2003-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
 *
 * $Id: Glob_Close.bsh 12063 2008-03-02 06:58:51Z k_satoda $
 */

import java.util.regex.Pattern;

void globClose(View view)
{
	String glob = Macros.input(view, "Glob Pattern:");
	if(glob == null || glob.length() == 0)
		return;

	Pattern re = null;
	try
	{
		re = Pattern.compile(MiscUtilities.globToRE(glob));
	}
	catch(Exception e)
	{
		Macros.error(view,"Error in glob pattern: " + e.toString());
		return;
	}

	Buffer[] buffers = jEdit.getBuffers();
	for(int i=0; i < buffers.length; i++)
	{
		if(re.matcher(buffers[i].getPath()).matches())
			jEdit.closeBuffer(view,buffers[i]);
	}
}

globClose(view);

/*

<listitem>
	<para><filename>Glob_Close.bsh</filename></para>
	<abstract><para>
		Closes all open buffers matching a given glob pattern.
	</para></abstract>
</listitem>

*/
