This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Reverse Line Order with Notepad++ Python Script

By: a guest on Oct 30th, 2012  |  syntax: Python  |  size: 0.88 KB  |  views: 96  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def reverseAllLines():
  2.         lines   = editor.getText().splitlines()
  3.         lines.reverse()
  4.         editor.setText(os.linesep.join(lines))
  5.  
  6. def reverseSelectedLines():
  7.         import os
  8.  
  9.         staline = editor.lineFromPosition(editor.getSelectionStart())
  10.         endline = editor.lineFromPosition(editor.getSelectionEnd())
  11.         start   = editor.positionFromLine(staline)
  12.         end             = editor.positionFromLine(endline)+editor.lineLength(endline)
  13.  
  14.         text    = editor.getTextRange(start, end)
  15.        
  16.         if text.endswith(os.linesep):
  17.                 eol = os.linesep
  18.         else:
  19.                 eol = ''
  20.  
  21.         lines   = text.splitlines()
  22.         lines.reverse()
  23.  
  24.         text    = os.linesep.join(lines)+eol
  25.  
  26.         editor.setSelection(start, end)
  27.         editor.replaceSel(text)
  28.         editor.setSelection(start, end) #keep selection after replace
  29.  
  30.  
  31. editor.beginUndoAction()
  32. if editor.getSelectionStart() == editor.getSelectionEnd():
  33.         reverseAllLines()
  34. else:
  35.         reverseSelectedLines()
  36. editor.endUndoAction()
clone this paste RAW Paste Data