<commit_before>"""
Find Cursor
Licensed under MIT
Copyright (c) 2014 <NAME> <<EMAIL>>

Makes Sublime cursors highly visible for a short duration.

Also, iterate through cursors centering them, or pan through view showing cursors.

Example Keymap:
    //////////////////////////////////
    // Find Cursor: Iterative Find
    //////////////////////////////////
    {
        "keys": ["ctrl+."],
        "command": "find_cursor",
        "args": {"reverse": false, "pan": false}
    },
    {
        "keys": ["ctrl+shift+."],
        "command": "find_cursor",
        "args": {"reverse": true, "pan": false}
    }

    //////////////////////////////////
    // Find Cursor: Panning Find
    //////////////////////////////////
    {
        "keys": ["ctrl+."],
        "command": "find_cursor",
        "args": {"reverse": false, "pan": true}
    },
    {
        "keys": ["ctrl+shift+."],
        "command": "find_cursor",
        "args": {"reverse": true, "pan": true}
    }
"""
import sublime_plugin
import sublime
import time
from collections import namedtuple

PAN_MODE = -2
NULL_INDEX = -1
FORWARD = 1
BACKWARD = -1


class PanCursor(namedtuple('PanCursor', ['cursor', 'distance', 'index'], verbose=False)):
    pass


class FindCursorCommand(sublime_plugin.TextCommand):
    def save_item(self, defaults, src, dest):
        """
        Save the item if setting is available.
        """

        setting = self.settings.get(dest, None)
        if setting is not None:
            defaults[src] = setting

    def save(self):
        """
        Save the view's caret settings.
        """

        self.settings = self.view.settings()
        if self.settings.get("caret_defaults", None) is None:
            defaults = {}
            self.save_item(defaults, "width", "caret_extra_width")
            self.save_item(defaults, "top", "caret_extra_top")
            self.save_item(defaults, "bottom", "caret_extra_bottom")
            self.save_item(defaults, "style" , "caret_style")
            self.save_item(defaults, "inverse", "inverse_caret_state")
            self.settings.set("caret_defaults", defaults)

    def restore_item(self, defaults, src, dest):
        """
        Restore item if setting is available. Erase item if it is not.
        """

        setting = defaults.get(src, None)
        self.settings.set(dest, setting) if setting is not None else self.settings.erase(dest)

    def restore(self, t):
        """
        Restore the view's caret settings.
        """

        if self.settings.get("caret_last_change", "") == t:
            defaults = self.settings.get("caret_defaults", None)
            if defaults is not None:
                self.restore_item(defaults, "width", "caret_extra_width")
                self.restore_item(defaults, "top", "caret_extra_top")
                self.restore_item(defaults, "bottom", "caret_extra_bottom")
                self.restore_item(defaults, "style", "caret_style")<commit_msg>- Lint fix<commit_after>"""
Find Cursor
Licensed under MIT
Copyright (c) 2014 <NAME> <<EMAIL>>

Makes Sublime cursors highly visible for a short duration.

Also, iterate through cursors centering them, or pan through view showing cursors.

Example Keymap:
    //////////////////////////////////
    // Find Cursor: Iterative Find
    //////////////////////////////////
    {
        "keys": ["ctrl+."],
        "command": "find_cursor",
        "args": {"reverse": false, "pan": false}
    },
    {
        "keys": ["ctrl+shift+."],
        "command": "find_cursor",
        "args": {"reverse": true, "pan": false}
    }

    //////////////////////////////////
    // Find Cursor: Panning Find
    //////////////////////////////////
    {
        "keys": ["ctrl+."],
        "command": "find_cursor",
        "args": {"reverse": false, "pan": true}
    },
    {
        "keys": ["ctrl+shift+."],
        "command": "find_cursor",
        "args": {"reverse": true, "pan": true}
    }
"""
import sublime_plugin
import sublime
import time
from collections import namedtuple

PAN_MODE = -2
NULL_INDEX = -1
FORWARD = 1
BACKWARD = -1


class PanCursor(namedtuple('PanCursor', ['cursor', 'distance', 'index'], verbose=False)):
    pass


class FindCursorCommand(sublime_plugin.TextCommand):
    def save_item(self, defaults, src, dest):
        """
        Save the item if setting is available.
        """

        setting = self.settings.get(dest, None)
        if setting is not None:
            defaults[src] = setting

    def save(self):
        """
        Save the view's caret settings.
        """

        self.settings = self.view.settings()
        if self.settings.get("caret_defaults", None) is None:
            defaults = {}
            self.save_item(defaults, "width", "caret_extra_width")
            self.save_item(defaults, "top", "caret_extra_top")
            self.save_item(defaults, "bottom", "caret_extra_bottom")
            self.save_item(defaults, "style", "caret_style")
            self.save_item(defaults, "inverse", "inverse_caret_state")
            self.settings.set("caret_defaults", defaults)

    def restore_item(self, defaults, src, dest):
        """
        Restore item if setting is available. Erase item if it is not.
        """

        setting = defaults.get(src, None)
        self.settings.set(dest, setting) if setting is not None else self.settings.erase(dest)

    def restore(self, t):
        """
        Restore the view's caret settings.
        """

        if self.settings.get("caret_last_change", "") == t:
            defaults = self.settings.get("caret_defaults", None)
            if defaults is not None:
                self.restore_item(defaults, "width", "caret_extra_width")
                self.restore_item(defaults, "top", "caret_extra_top")
                self.restore_item(defaults, "bottom", "caret_extra_bottom")
                self.restore_item(defaults, "style", "caret_style")
{'fraction_non_alphanumeric': 0.17580372250423013, 'fraction_numerical': 0.0027072758037225042, 'mean_word_length': 2.070649350649351, 'pattern_counts': {'":': 40, '<': 9, '<?xml version=': 0, '>': 9, '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': '2075594', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1667, 'n_words': 439}