1/**
2 * Transpose character at caret with previous character, and move caret
3 * forward one. Emulates Emacs "transpose-chars" command (without prefix
4 * argument support).
5 */
6
7source (MiscUtilities.constructPath(dirname(scriptPath), "EmacsUtil.bsh"));
8
9void emacsTransposeChars()
10{
11    caret = textArea.getCaretPosition();
12    if ((caret == 0) || atEndOfBuffer())
13    {
14        beep();
15        return;
16    }
17
18    char chCur = charAtCaret();
19    char chPrev = charAt (caret - 1);
20    selection = new Selection.Range (caret - 1, caret + 1);
21    textArea.setSelection (selection);
22    textArea.setSelectedText (new String ("" + chCur + chPrev));
23    textArea.removeFromSelection (selection);
24}
25
26emacsTransposeChars();
27
28