/**
 * Single_Space_Buffer.bsh - A Beanshell macro for jEdit that 
 * converts a buffer from being double-spaced (where every second
 * line is blank) to single-spaced, by removing each second line -
 * but only if they're all blank.
 *
 * Copyright (C) 2004 Ollie Rutherfurd <oliver@rutherfurd.net>
 *
 * $Id: Single_Space_Buffer.bsh 9126 2007-03-10 19:14:30Z Vampire0 $
 */

void singleSpaceBuffer(View view)
{
	Buffer buffer = view.getBuffer();
	int line = 1;	// start on second line
	Vector lines = new java.util.Stack();

	while(line < buffer.getLineCount())
	{
		if(buffer.getLineText(line).equals(""))
			lines.addElement(new Integer(line));
		else
		{
			StringBuffer msg = new StringBuffer();
			msg.append(buffer.getPath() + " doesn't appear to be double-spaced:\n");
			msg.append("Line " + (line + 1) + " isn't blank.");
			Macros.error(view, msg.toString());
			return;
		}
		line += 2;
	}
	while(!lines.empty())
	{
		Integer lineno = (Integer)lines.pop();
		int offset = buffer.getLineStartOffset(lineno.intValue());
		buffer.remove(offset-1,1);
	}
}

singleSpaceBuffer(view);

/*

<listitem>
	<para><filename>Single_Space_Buffer.bsh</filename></para>
	<abstract><para>
		Removes every second line, if they are all blank.
	</para></abstract>
</listitem>

*/
