Skip to content

Commit

Permalink
Remove line ending handling; it only concerns storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Amalthea Magnuson committed Feb 3, 2016
1 parent 17c32f1 commit 86ebf99
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions SortNumerically.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sublime_plugin
import re

LINE_ENDING_CHARACTER = '\n'


class SortNumericallyCommand(sublime_plugin.TextCommand):
def run(self, edit):
Expand All @@ -18,19 +20,10 @@ def run(self, edit):
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
sorted_lines = sorted(lines, key=alphanum_key)

# Determine the current line ending setting, so we can rejoin the
# sorted lines using the correct line ending character.
line_ending_character = '\n' # Default.
line_endings = self.view.line_endings()
if line_endings == 'CR':
line_ending_character = '\r'
elif line_endings == 'Windows':
line_ending_character = '\r\n'

output = line_ending_character.join(sorted_lines)
output = LINE_ENDING_CHARACTER.join(sorted_lines)

# If the end of the region had a line ending character, we re-add it here
if self.view.substr(region).endswith(line_ending_character):
output += line_ending_character
if self.view.substr(region).endswith(LINE_ENDING_CHARACTER):
output += LINE_ENDING_CHARACTER

self.view.replace(edit, region, output)

0 comments on commit 86ebf99

Please sign in to comment.