"Sort Lines & Remove Duplicates" by jumpfroggy
Rating:









10.0
(1 votes)
| Name: | Sort Lines & Remove Duplicates |
|---|---|
| Uploaded By: | jumpfroggy |
| Date Created: | May 2, 2009 2:43 a.m. |
| Date Modified: | May 2, 2009 2:43 a.m. |
| Description: | This is modified from the SortLines() script by Scott (wischeese). It sorts lines and removes any duplicates. Case sensitive. |
| Num Views: | 450 |
| Num Downloads: | 161 |
Contents
@script("Sort Lines (No Duplicates)", "Text")
def SortLinesNoDuplicates():
""" Sort Lines, Remove Duplicates (Modified by jumpfroggy from wischeese's "SortLines" script) """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
lsSelection = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
laLines = lsSelection.splitlines(0)
laLines.sort()
# Filter out duplicate lines
laLines2 = []
for line in laLines:
if line not in laLines2:
laLines2.append(line)
lsReplace = string.join(laLines2, '\r\n' )
editor.ReplaceSel(lsReplace)
editor.EndUndoAction()
Comments:
Yeah, that'd be nice. I'd name it EOLString (or actually EolString, depending on style), but that'd be a great convenience.
Posted by jumpfroggy on May 14, 2009 at 2:05 p.m.
Nice script! You could also respect the user's line endings choice by using editor.EOLMode:
CRLF = 0
CR = 1
LF = 2
Might be nice to have a editor.LineEndString or something similar to just return the appropriate string to use.
Posted by simon on May 2, 2009 at 3:47 a.m.