Welcome, guest | Sign In | My Account | Store | Cart

This will sort the lines in the current document into alphabetical order. It doesn't apply any special rule (so 5 will come after 42).

On running, it asks if you want a unique sort (Cancel for no, Ok for yes), in which case it'll remove duplicate lines.

JavaScript, 20 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// Macro recorded on: Wed May 26 2010 15:54:13 GMT+0100 (GMT)
komodo.assertMacroVersion(2);
if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }

var scimoz = ko.views.manager.currentView.scimoz;
var whole_buffer = scimoz.text;
var buffer_lines = whole_buffer.split( '\n' );
buffer_lines.sort();
if ( confirm( 'Unique?' ) ) {
    // Go through the array in reverse order from last to 2nd, and if the nth line is the same
    // as the (n-1)th line, then remove the nth line.
    for( bidx = buffer_lines.length - 1 ; bidx > 0 ; bidx-- ) {
        if ( buffer_lines[ bidx ] == buffer_lines[ bidx - 1 ] ) {
            buffer_lines.splice( bidx, 1 );
        }
    }
}
var new_buffer = buffer_lines.join( '\n' );
scimoz.selectAll();
scimoz.replaceSel( new_buffer );
Created by Glenn Jenkins on Thu, 27 May 2010 (MIT)
JavaScript recipes (69)
Glenn Jenkins's recipes (2)

Required Modules

  • (none specified)

Other Information and Tasks