<commit_before>import sublime
import sublime_plugin
import subprocess
import re
import collections

SETTINGS_FILE = 'SublimeLineMessages.sublime-settings'

LINE_MESSAGES = {}

class Message(object):
    def __init__(self, filename, tool, line, message):
        self.filename = filename
        self.tool = tool
        self.line = line
        self.message = message

    def __str__(self):
        return '[{:^10}]{:>4}:{}'.format(self.tool, self.line, self.message)


class MessageContainer(object):
    """
    A container class that is responsible for the addition, subtraction and
    viewing (in the GUI) of messages.
    """

    def __init__(self, view):
        self.view = view
        self.line_messages = collections.defaultdict(list)
        self.region_key = '{}_line_message'.format(self.view.id())

    def add_message(self, message, noline=False):
        if not noline:
            self.line_messages[message.line].append(message)
        else:
            self.line_messages[0] = message

    def add_regions(self):
        regions = [
            self.view.line(self.view.text_point(line-1, 0)) for line in
                self.line_messages ]
        self.view.add_regions(self.region_key, regions, 'error', '', sublime.DRAW_NO_FILL)

    def clear_regions(self):
        self.view.erase_regions(self.region_key)
        self.line_messages = collections.defaultdict(list)

    def line_message(self, line):
        if line in self.line_messages:
            return ' '.join(self.line_messages[line])
        return ''

    def __str__(self):
        text = ''
        for line in self.line_messages:
            for message in self.line_messages[line]:
                text += str(message) + '\n'
        return text

def parser_from_regex(tool, regex):
    """
    Forms a line parser from a regex, returns a parsing function.
    """
    _regex = re.compile(regex)
    def parser(text):
        messages = []
        for line in text.split('\n'):
            result = _regex.match(line)
            if result is not None:
                filename, line, message = result.groups()
                messages.append(
                    Message(filename,
                            tool,
                            int(line) if line else 1,<commit_msg>Added sorting (based on line numbers) to the messages.<commit_after>import sublime
import sublime_plugin
import subprocess
import re
import collections

SETTINGS_FILE = 'SublimeLineMessages.sublime-settings'

LINE_MESSAGES = {}

class Message(object):
    def __init__(self, filename, tool, line, message):
        self.filename = filename
        self.tool = tool
        self.line = line
        self.message = message

    def __str__(self):
        return '[{:^10}]{:>4}:{}'.format(self.tool, self.line, self.message)


class MessageContainer(object):
    """
    A container class that is responsible for the addition, subtraction and
    viewing (in the GUI) of messages.
    """

    def __init__(self, view):
        self.view = view
        self.line_messages = collections.defaultdict(list)
        self.region_key = '{}_line_message'.format(self.view.id())

    def add_message(self, message, noline=False):
        if not noline:
            self.line_messages[message.line].append(message)
        else:
            self.line_messages[0] = message

    def add_regions(self):
        regions = [
            self.view.line(self.view.text_point(line-1, 0)) for line in
                self.line_messages ]
        self.view.add_regions(self.region_key, regions, 'error', '', sublime.DRAW_NO_FILL)

    def clear_regions(self):
        self.view.erase_regions(self.region_key)
        self.line_messages = collections.defaultdict(list)

    def line_message(self, line):
        if line in self.line_messages:
            return ' '.join(self.line_messages[line])
        return ''

    def __str__(self):
        text = ''
        for line in sorted(self.line_messages):
            for message in self.line_messages[line]:
                text += str(message) + '\n'
        return text

def parser_from_regex(tool, regex):
    """
    Forms a line parser from a regex, returns a parsing function.
    """
    _regex = re.compile(regex)
    def parser(text):
        messages = []
        for line in text.split('\n'):
            result = _regex.match(line)
            if result is not None:
                filename, line, message = result.groups()
                messages.append(
                    Message(filename,
                            tool,
                            int(line) if line else 1,
{'fraction_non_alphanumeric': 0.10506852294974983, 'fraction_numerical': 0.0030454644333260824, 'mean_word_length': 2.201949860724234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '482731', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1288, 'n_words': 327}