Last active
December 7, 2017 14:06
-
-
Save funivan/5f110c7eb8d30ceed990 to your computer and use it in GitHub Desktop.
Sublime plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
class CalculateLinesCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
lines={} | |
region = sublime.Region(0, self.view.size()) | |
for lineRegion in self.view.lines(region): | |
key = self.view.substr(lineRegion) | |
key = key.strip(' \t\n\r') | |
if len(key) == 0 : | |
continue | |
i=0 | |
if key in lines: | |
i=lines[key] | |
i=i+1 | |
lines[key]=i | |
sorted_names = sorted(lines, key=lines.__getitem__, reverse=True) | |
index=0 | |
self.view.erase(edit, region); | |
for k in sorted_names: | |
a="{} => {}\n".format(lines[k], k) | |
self.view.insert(edit, index, a) | |
index=index + len(a); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment