/**
 * Emulate GNU Emacs's (fixup-whitespace) function (typically bound to
 * Ctrl-SPACE. Not a complete emulation. Emacs docs for this function:
 *
 *     Fixup white space between objects around caret.
 *     Leave one space or none, according to the context.
 */
source (MiscUtilities.constructPath(dirname(scriptPath), "EmacsUtil.bsh"));

void emacsAlignDeclarations()
{
    caret = textArea.getCaretPosition();
    caretLine = textArea.getCaretLine();
    lineStart = textArea.getLineStartOffset (caretLine);
    lineEnd = textArea.getLineEndOffset (caretLine);
    
    if (caretLine.trim().length() == 0)
        return;

    // Find the end of the block
    
    boolean emptyLine = false;
    caret2 = lineEnd + 1;
    while (! emptyLine)
    {
        line = lineAt (caret2);
        if (line.trim().length() == 0)
            break;
        caret2 = caret2 + line.length();
    }
}

emacsFixupWhitespace();

