PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
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
  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. // an arbitrary letter for a register.
  15. myReg = 'p';
  16. emacsCtrlK()
  17. {
  18. int currentLine = textArea.getCaretPosition();
  19. try
  20. {
  21. int lastLine = Integer.parseInt("" + jEdit.getProperty("lastpos"));
  22. if(lastLine != currentLine)
  23. {
  24. Registers.clearRegister('$');
  25. }
  26. }
  27. catch ( NumberFormatException nfe )
  28. {
  29. Registers.clearRegister('$');
  30. }
  31. selections = textArea.getSelection();
  32. if(selections.length == 0)
  33. {
  34. textArea.goToEndOfWhiteSpace(true);
  35. }
  36. selections = textArea.getSelection();
  37. if (selections.length==0)
  38. {
  39. textArea.goToNextCharacter(true);
  40. }
  41. selections = textArea.getSelection();
  42. Registers.append(textArea, '$', "");
  43. // since there is no cut-append, I"ll just cut it into another register
  44. Registers.cut(textArea, 'e');
  45. // remember the caretPosition for next time around
  46. // Registers.setRegister('p', "" + textArea.getCaretPosition());
  47. jEdit.setProperty("lastpos", "" + textArea.getCaretPosition());
  48. }
  49. emacsCtrlK();
  50. /**
  51. <listitem>
  52. <para>
  53. If no text is selected, the current line is cut to the clipboard,
  54. otherwise the selected text is cut to the clipboard.
  55. Subsequent calls to Emacs_Ctrl-k will alternate between cut-append
  56. the following newline character, or the following line of text.
  57. </para>
  58. </listitem>
  59. */