PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/macros/Editing/Emacs-Ctrl-K.bsh

#
Unknown | 67 lines | 59 code | 8 blank | 0 comment | 0 complexity | 9f486b946017069b7e15948c8a82c60b MD5 | raw file
 1/*
 2* Emacs-Ctrl-k.bsh - a BeanShell macro for jEdit
 3* which cuts either the selected text, or the current line 
 4* if no text is selected, to the clipboard.
 5*
 6* Repeated calls to Emacs-Ctrl-K from the same position
 7* should append cut lines to the cut buffer.
 8*
 9* By Alan Ezust <ezust at users dot sourceforge dot net>
10* with help from Ollie Rutherford
11* Version 0.1  21 December 2003
12*
13*/
14
15// an arbitrary letter for a register.
16myReg = 'p';    
17
18emacsCtrlK() 
19{
20    int currentLine = textArea.getCaretPosition();
21    try
22    {
23        int lastLine = Integer.parseInt("" + jEdit.getProperty("lastpos"));
24        if(lastLine != currentLine)
25        {
26            Registers.clearRegister('$');
27        }
28    }
29    catch ( NumberFormatException nfe )
30    {
31        Registers.clearRegister('$');
32    }
33
34    selections = textArea.getSelection();
35    if(selections.length == 0)
36    {
37        textArea.goToEndOfWhiteSpace(true);
38    }
39    selections = textArea.getSelection();
40    if (selections.length==0) 
41    {
42        textArea.goToNextCharacter(true);
43    }
44    selections = textArea.getSelection();
45    Registers.append(textArea, '$', "");
46
47    // since there is no cut-append, I"ll just cut it into another register
48    Registers.cut(textArea, 'e');
49
50    // remember the caretPosition for next time around
51    // Registers.setRegister('p', "" + textArea.getCaretPosition());
52    jEdit.setProperty("lastpos", "" + textArea.getCaretPosition());
53}
54
55emacsCtrlK();
56
57/**
58<listitem>
59	<para>
60        If no text is selected, the current line is cut to the clipboard,
61        otherwise the selected text is cut to the clipboard.
62
63        Subsequent calls to Emacs_Ctrl-k will alternate between cut-append
64        the following newline character, or the following line of text.
65	</para>
66</listitem>
67*/