/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * Emacs-Ctrl-k.bsh - a BeanShell macro for jEdit
- * which cuts either the selected text, or the current line
- * if no text is selected, to the clipboard.
- *
- * Repeated calls to Emacs-Ctrl-K from the same position
- * should append cut lines to the cut buffer.
- *
- * By Alan Ezust <ezust at users dot sourceforge dot net>
- * with help from Ollie Rutherford
- * Version 0.1 21 December 2003
- *
- */
- // an arbitrary letter for a register.
- myReg = 'p';
- emacsCtrlK()
- {
- int currentLine = textArea.getCaretPosition();
- try
- {
- int lastLine = Integer.parseInt("" + jEdit.getProperty("lastpos"));
- if(lastLine != currentLine)
- {
- Registers.clearRegister('$');
- }
- }
- catch ( NumberFormatException nfe )
- {
- Registers.clearRegister('$');
- }
- selections = textArea.getSelection();
- if(selections.length == 0)
- {
- textArea.goToEndOfWhiteSpace(true);
- }
- selections = textArea.getSelection();
- if (selections.length==0)
- {
- textArea.goToNextCharacter(true);
- }
- selections = textArea.getSelection();
- Registers.append(textArea, '$', "");
- // since there is no cut-append, I"ll just cut it into another register
- Registers.cut(textArea, 'e');
- // remember the caretPosition for next time around
- // Registers.setRegister('p', "" + textArea.getCaretPosition());
- jEdit.setProperty("lastpos", "" + textArea.getCaretPosition());
- }
- emacsCtrlK();
- /**
- <listitem>
- <para>
- If no text is selected, the current line is cut to the clipboard,
- otherwise the selected text is cut to the clipboard.
- Subsequent calls to Emacs_Ctrl-k will alternate between cut-append
- the following newline character, or the following line of text.
- </para>
- </listitem>
- */