<commit_before>import sublime, sublime_plugin
import re, itertools

last_index = 0
hints = []
search_regex = r''

next_search = False

mode = 0

def get_active_views(window, current_buffer_only):
    """Returns all currently visible views"""

    views = []
    if current_buffer_only:
        views.append(window.active_view())
    else:
        for group in range(window.num_groups()):
            views.append(window.active_view_in_group(group))
    return views

def set_views_setting(views, setting, values):
    """Sets the values for the setting in all given views"""

    for i in range(len(views)):
        views[i].settings().set(setting, values[i])

def set_views_settings(views, settings, values):
    """Sets the values for all settings in all given views"""

    for i in range(len(settings)):
        set_views_setting(views, settings[i], values[i])

def get_views_setting(views, setting):
    """Returns the setting value for all given views"""

    settings = []
    for view in views:
        settings.append(view.settings().get(setting))
    return settings

def get_views_settings(views, settings):
    """Gets the settings for every given view"""

    values = []
    for setting in settings:
        values.append(get_views_setting(views, setting))
    return values

def set_views_syntax(views, syntax):
    """Sets the syntax highlighting for all given views"""

    for i in range(len(views)):
        views[i].set_syntax_file(syntax[i])

def set_views_sel(views, selections):
    """Sets the selections for all given views"""

    for i in range(len(views)):
        for sel in selections[i]:
            views[i].sel().add(sel)

def get_views_sel(views):
    """Returns the current selection for each from the given views"""

    selections = []
    for view in views:
        selections.append(view.sel())
    return selections

def clear_views_sel(views):
    """Clears the selection in all given views"""

    for view in views:
        view.sel().clear()

class AceJumpCommand(sublime_plugin.WindowCommand):
    """Base command class for AceJump plugin"""

    def run(self, current_buffer_only = False):
        self.char = ""
        self.target = ""
        self.views = []
        self.changed_views = []
        self.breakpoints = []

        self.all_views = get_active_views(self.window, current_buffer_only)
        self.syntax = get_views_setting(self.all_views, "syntax")
        self.sel = get_views_sel(self.all_views)

        settings = sublime.load_settings("AceJump.sublime-settings")
        self.highlight = settings.get("labels_scope", "invalid")
        self.labels = settings.get(
            "labels",
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        )

        self.view_settings = settings.get("view_settings", [])
        self.view_values = get_views_settings(
            self.all_views,
            self.view_settings
        )

        self.show_prompt(self.prompt(), self.init_value())

    def show_prompt(self, title, value):
        """Shows a prompt with the given title and value in the window"""

        self.window.show_input_panel(
            title, value,
            self.next_batch, self.on_input, self.submit
        )

    def next_batch(self, command):
        """Displays the next batch of labels after pressing return"""

        self.remove_labels()
        self.show_prompt(self.prompt(), self.char)

    def on_input(self, command):
        """Fires the necessary actions for the current input"""

        if len(command) == 1:
            self.char = command
            self.add_labels(self.regex().format(re.escape(self.char)))
            return

        if len(command) == 2:
            self.target = command[1]

        self.window.run_command("hide_panel", {"cancel": True})

    def submit(self):
        """Handles the behavior after closing the prompt"""

        global next_search, mode
        next_search = False

        self.remove_labels()
        set_views_sel(self.all_views, self.sel)
        set_views_syntax(self.all_views, self.syntax)
        self.jump(self.labels.find(self.target))

        mode = 0

    def add_labels(self, regex):
        """Adds labels to characters matching the regex"""

        global last_index, hints

        last_index = 0
        hints = []

        self.views = self.views_to_label()
        self.changed_views = []
        self.breakpoints = []
        changed_files = []

        for view in self.views[:]:
            if view.file_name() in changed_files:
                break

            view.run_command("add_ace_jump_labels", {
                "regex": regex,
                "labels": self.labels,
                "highlight": self.highlight
            })
            self.breakpoints.append(last_index)
            self.changed_views.append(view)
            changed_files.append(view.file_name())

            if next_search:
                break

            self.views.remove(view)

        clear_views_sel(self.all_views)

        set_views_syntax(self.all_views, list(itertools.repeat(
            "Packages/AceJump/AceJump.tmLanguage",
            len(self.all_views)
        )))

        set_views_settings(
            self.all_views,
            self.view_settings,
            self.view_values
        )

    def remove_labels(self):
        """Removes all previously added labels"""

        last_breakpoint = 0
        for breakpoint in self.breakpoints:
            if breakpoint != last_breakpoint:
                view = self.changed_views[self.view_for_index(breakpoint - 1)]
                view.run_command("remove_ace_jump_labels")
                last_breakpoint = breakpoint

    def jump(self, index):
        """Performs the jump action"""

        if self.target == "" or index < 0 or index >= last_index:
            return
<commit_msg>Don't clear view selection before showing labels to save cursor position<commit_after>import sublime, sublime_plugin
import re, itertools

last_index = 0
hints = []
search_regex = r''

next_search = False

mode = 0

def get_active_views(window, current_buffer_only):
    """Returns all currently visible views"""

    views = []
    if current_buffer_only:
        views.append(window.active_view())
    else:
        for group in range(window.num_groups()):
            views.append(window.active_view_in_group(group))
    return views

def set_views_setting(views, setting, values):
    """Sets the values for the setting in all given views"""

    for i in range(len(views)):
        views[i].settings().set(setting, values[i])

def set_views_settings(views, settings, values):
    """Sets the values for all settings in all given views"""

    for i in range(len(settings)):
        set_views_setting(views, settings[i], values[i])

def get_views_setting(views, setting):
    """Returns the setting value for all given views"""

    settings = []
    for view in views:
        settings.append(view.settings().get(setting))
    return settings

def get_views_settings(views, settings):
    """Gets the settings for every given view"""

    values = []
    for setting in settings:
        values.append(get_views_setting(views, setting))
    return values

def set_views_syntax(views, syntax):
    """Sets the syntax highlighting for all given views"""

    for i in range(len(views)):
        views[i].set_syntax_file(syntax[i])

def set_views_sel(views, selections):
    """Sets the selections for all given views"""

    for i in range(len(views)):
        for sel in selections[i]:
            views[i].sel().add(sel)

def get_views_sel(views):
    """Returns the current selection for each from the given views"""

    selections = []
    for view in views:
        selections.append(view.sel())
    return selections

class AceJumpCommand(sublime_plugin.WindowCommand):
    """Base command class for AceJump plugin"""

    def run(self, current_buffer_only = False):
        self.char = ""
        self.target = ""
        self.views = []
        self.changed_views = []
        self.breakpoints = []

        self.all_views = get_active_views(self.window, current_buffer_only)
        self.syntax = get_views_setting(self.all_views, "syntax")
        self.sel = get_views_sel(self.all_views)

        settings = sublime.load_settings("AceJump.sublime-settings")
        self.highlight = settings.get("labels_scope", "invalid")
        self.labels = settings.get(
            "labels",
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        )

        self.view_settings = settings.get("view_settings", [])
        self.view_values = get_views_settings(
            self.all_views,
            self.view_settings
        )

        self.show_prompt(self.prompt(), self.init_value())

    def show_prompt(self, title, value):
        """Shows a prompt with the given title and value in the window"""

        self.window.show_input_panel(
            title, value,
            self.next_batch, self.on_input, self.submit
        )

    def next_batch(self, command):
        """Displays the next batch of labels after pressing return"""

        self.remove_labels()
        self.show_prompt(self.prompt(), self.char)

    def on_input(self, command):
        """Fires the necessary actions for the current input"""

        if len(command) == 1:
            self.char = command
            self.add_labels(self.regex().format(re.escape(self.char)))
            return

        if len(command) == 2:
            self.target = command[1]

        self.window.run_command("hide_panel", {"cancel": True})

    def submit(self):
        """Handles the behavior after closing the prompt"""

        global next_search, mode
        next_search = False

        self.remove_labels()
        set_views_sel(self.all_views, self.sel)
        set_views_syntax(self.all_views, self.syntax)
        self.jump(self.labels.find(self.target))

        mode = 0

    def add_labels(self, regex):
        """Adds labels to characters matching the regex"""

        global last_index, hints

        last_index = 0
        hints = []

        self.views = self.views_to_label()
        self.changed_views = []
        self.breakpoints = []
        changed_files = []

        for view in self.views[:]:
            if view.file_name() in changed_files:
                break

            view.run_command("add_ace_jump_labels", {
                "regex": regex,
                "labels": self.labels,
                "highlight": self.highlight
            })
            self.breakpoints.append(last_index)
            self.changed_views.append(view)
            changed_files.append(view.file_name())

            if next_search:
                break

            self.views.remove(view)

        set_views_syntax(self.all_views, list(itertools.repeat(
            "Packages/AceJump/AceJump.tmLanguage",
            len(self.all_views)
        )))

        set_views_settings(
            self.all_views,
            self.view_settings,
            self.view_values
        )

    def remove_labels(self):
        """Removes all previously added labels"""

        last_breakpoint = 0
        for breakpoint in self.breakpoints:
            if breakpoint != last_breakpoint:
                view = self.changed_views[self.view_for_index(breakpoint - 1)]
                view.run_command("remove_ace_jump_labels")
                last_breakpoint = breakpoint

    def jump(self, index):
        """Performs the jump action"""

        if self.target == "" or index < 0 or index >= last_index:
            return

{'fraction_non_alphanumeric': 0.10499913509773395, 'fraction_numerical': 0.0017298045320878741, 'mean_word_length': 2.382972498537156, 'pattern_counts': {'":': 8, '<': 5, '<?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': '4456511', 'n_tokens_mistral': 3428, 'n_tokens_neox': 3249, 'n_words': 797}