<commit_before>import sublime_plugin
from threading import Timer

DEFAULT_NAME = 'Find Results'
ALT_NAME = 'Find Results '


class OpenSearchInNewTab(sublime_plugin.EventListener):

    # set a bit changed name
    # so the tab won't be bothered
    # during new search
    def on_activated(self, view):
        if self.is_search_view(view):
            self.apply_alt_name(view)

    # these hooks will help other plugins
    # to understand that we are in search results file
    def on_text_command(self, view, command_name, args):
        if self.is_search_view(view):
            self.apply_default_name(view)

    def post_text_command(self, view, command_name, args):
        if self.is_search_view(view):
            self.apply_alt_name(view)

    def apply_alt_name(self, view):
        view.set_name(ALT_NAME)

    def apply_default_name(self, view):
        view.set_name(DEFAULT_NAME)
        t = Timer(.1, self.apply_alt_name, (view,))
        t.start()

    def is_search_view(self, view):
        name = view.name()
        return name == ALT_NAME or name == DEFAULT_NAME<commit_msg>PoC of named buffer function<commit_after>import re
from threading import Timer

import sublime_plugin
import sublime

DEFAULT_NAME = 'Find Results'
ALT_NAME_BASE = 'Find Results '


class OpenSearchInNewTab(sublime_plugin.EventListener):

    # set a bit changed name
    # so the tab won't be bothered
    # during new search
    def on_activated(self, view):
        if self.is_search_view(view):
            self.apply_alt_name(view)

    # these hooks will help other plugins
    # to understand that we are in search results file
    def on_text_command(self, view, command_name, args):
        if self.is_search_view(view):
            self.apply_default_name(view)

    def post_text_command(self, view, command_name, args):
        if self.is_search_view(view):
            self.apply_alt_name(view)

    def get_alt_name(self, view):
        first_line_coords = view.full_line(sublime.Region(0, 0))
        first_line = view.substr(sublime.Region(*first_line_coords))
        match = re.search('Searching \d+ files for "(.*)"$', first_line)

        if match:
            query = match.group(1)
            return ALT_NAME_BASE + '"' + query + '"'

        return ALT_NAME_BASE

    def apply_alt_name(self, view):
        t = Timer(.1, self.apply_alt_name_async, (view,))
        t.start()

    def apply_alt_name_async(self, view):
        view.set_name(self.get_alt_name(view))

    def apply_default_name(self, view):
        view.set_name(DEFAULT_NAME)
        self.apply_alt_name(view)

    def is_search_view(self, view):
        name = view.name()

        print('name ' + name)
        print('alt_name ' + self.get_alt_name(view))

        return (
            name == DEFAULT_NAME or
            name == ALT_NAME_BASE or
            name == self.get_alt_name(view)
            )
{'fraction_non_alphanumeric': 0.09323204419889503, 'fraction_numerical': 0.0017265193370165745, 'mean_word_length': 2.7574578469520103, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '75072', 'n_tokens_mistral': 940, 'n_tokens_neox': 898, 'n_words': 219}