<commit_before>from __future__ import absolute_import
from cfbeautifier import beautifier
from cfbeautifier.util import ParserError
import sublime, sublime_plugin

STATUS_KEY = 'cfengine-beautifier'

def settings():
    return sublime.load_settings('CFEngineBeautifier.sublime-settings')

def is_cfengine_file(file_name):
    return file_name.endswith(".cf")

class BeautifyCfengineEventListener(sublime_plugin.EventListener):
    def on_pre_save(self, view):
        if settings().get('beautify_on_save', True):
            view.run_command("beautify_cfengine")
    def on_modified(self, view):
        view.erase_regions("parser_errors")

class BeautifyCfengineCommand(sublime_plugin.TextCommand):
    def run(self, edit, moves_cursor = True):
        if is_cfengine_file(self.view.file_name()):
            buffer_region = sublime.Region(0, self.view.size())
            self.view.set_status(STATUS_KEY, "");
            try:
                view_state = self.viewport_state()
                self.view.replace(edit,
                                  buffer_region,
                                  beautifier.beautified_string(self.view.substr(buffer_region),
                                                              options = self.options()))
                self.set_viewport_state(view_state)
            except ParserError as error:<commit_msg>Fix loading under Sublime Text 3 #1<commit_after>import sys
import sublime, sublime_plugin

if sys.version_info[0] < 3:
    from cfbeautifier import beautifier
    from cfbeautifier.util import ParserError
else:
    from .cfbeautifier import beautifier
    from .cfbeautifier.util import ParserError

STATUS_KEY = 'cfengine-beautifier'

def settings():
    return sublime.load_settings('CFEngineBeautifier.sublime-settings')

def is_cfengine_file(file_name):
    return file_name.endswith(".cf")

class BeautifyCfengineEventListener(sublime_plugin.EventListener):
    def on_pre_save(self, view):
        if settings().get('beautify_on_save', True):
            view.run_command("beautify_cfengine")
    def on_modified(self, view):
        view.erase_regions("parser_errors")

class BeautifyCfengineCommand(sublime_plugin.TextCommand):
    def run(self, edit, moves_cursor = True):
        if is_cfengine_file(self.view.file_name()):
            buffer_region = sublime.Region(0, self.view.size())
            self.view.set_status(STATUS_KEY, "");
            try:
                view_state = self.viewport_state()
                self.view.replace(edit,
                                  buffer_region,
                                  beautifier.beautified_string(self.view.substr(buffer_region),
                                                              options = self.options()))
                self.set_viewport_state(view_state)
            except ParserError as error:
{'fraction_non_alphanumeric': 0.08799718409010912, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 2.5304347826086957, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3368470', 'n_tokens_mistral': 822, 'n_tokens_neox': 799, 'n_words': 143}