Author Topic: Macro for EmEditor to sort lines according to length  (Read 817 times)

spiros

  • Administrator
  • Hero Member
  • *****
  • Posts: 293795
  • Gender: Male
  • point d’amour
    • spiros.doikas
    • greektranslator
    • doikas
    • 102094522373850556729
    • lavagraph
    • Greek translator CV
Macro for EmEditor to sort lines according to length
« on: 11 Feb, 2013, 08:24:29 »
Macro for EmEditor (my favourite text editor) to sort lines according to length

Save the macro of your choice below in a txt file in My Macros folder (found in My Documents). Rename the file to sort.jsee (or use the attached after you unzip it).

First select the text. Then run any of these macros:

Sort the selected text from long to short
Code: [Select]
document.selection.text = ((document.selection.text.split("\n")).sort(function(a,b){return b.length-a.length})).join('\n');
Sort the selected text from short to long
Code: [Select]
document.selection.text = ((document.selection.text.split("\n")).sort(function(a,b){return a.length-b.length})).join('\n');
This was tested on an 80 MB file with maximum line length of 80,000 characters and it took a couple of seconds to run.
« Last Edit: 11 Feb, 2013, 08:28:24 by spiros »