<commit_before># -*- coding: utf-8 -*-
import re
import operator
from functools import partial

import sublime
import sublime_plugin

from core.probe import extract
from core.templates import make_template

__all__ = [
    'HayakuCommand',
    'HayakuChangeNumberCommand',
]

# максимальный размер css properties
MAX_SIZE_CSS = len('-webkit-transition-timing-function')

ABBR_REGEX = re.compile(r'[\s|;|{]([\.:%#a-z-,\d]+!?)$', re.IGNORECASE)

class HayakuCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = self.view.sel()
        if len(regions) > 1:
            # разобраться с многооконными выборками
            # пока что работаем только с одним регионом
            for r in regions:
                self.view.insert(edit, r, '\t')
            return
        region = regions[0]
        if not region.empty():
            # сделать работы с выделенным словом
            self.view.insert(edit, region, '\t')
            return
        cur_pos = region.begin()

        start_pos = cur_pos - MAX_SIZE_CSS
        if start_pos < 0:
            start_pos = 0
        probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos))
        match = ABBR_REGEX.search(probably_abbr)
        if match is None:
            self.view.insert(edit, cur_pos, '\t')
            return

        abbr = match.group(1)
        # print repr(abbr), 'abbr'
        extracted = extract(abbr)
        # print extracted, '1'
        if not extracted[0]:
            return
        # print extracted, '2'
        template = make_template(self.view.settings().get("hayaku_CSS_whitespace_after_colon"), *extracted)
        new_cur_pos = cur_pos-len(abbr)
        assert cur_pos-len(abbr) >= 0
        self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos))
        self.view.run_command("insert_snippet", {"contents": template})

WHITE_SPACE_FINDER = re.compile(r'^(\s*)[-\w].*')
class HayakuAddLineCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = self.view.sel()
        if len(regions) > 1:
            align_regions = (self.view.line(r) for r in regions)
            strings = (self.view.substr(r) for r in align_regions)
            finders = (WHITE_SPACE_FINDER.search(s) for s in strings)<commit_msg>passing args<commit_after># -*- coding: utf-8 -*-
import re
import operator
from functools import partial

import sublime
import sublime_plugin

from core.probe import extract
from core.templates import make_template

__all__ = [
    'HayakuCommand',
    'HayakuChangeNumberCommand',
]

# максимальный размер css properties
MAX_SIZE_CSS = len('-webkit-transition-timing-function')

ABBR_REGEX = re.compile(r'[\s|;|{]([\.:%#a-z-,\d]+!?)$', re.IGNORECASE)

class HayakuCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = self.view.sel()
        if len(regions) > 1:
            # разобраться с многооконными выборками
            # пока что работаем только с одним регионом
            for r in regions:
                self.view.insert(edit, r, '\t')
            return
        region = regions[0]
        if not region.empty():
            # сделать работы с выделенным словом
            self.view.insert(edit, region, '\t')
            return
        cur_pos = region.begin()

        start_pos = cur_pos - MAX_SIZE_CSS
        if start_pos < 0:
            start_pos = 0
        probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos))
        match = ABBR_REGEX.search(probably_abbr)
        if match is None:
            self.view.insert(edit, cur_pos, '\t')
            return

        abbr = match.group(1)
        # print repr(abbr), 'abbr'
        extracted = extract(abbr)
        # print extracted, '1'
        if not extracted[0]:
            return
        property_, value, is_num, important = extracted
        args = {
            'whitespace': self.view.settings().get("hayaku_CSS_whitespace_after_colon"),
            'property_': property_,
            'value': value,
            'is_num': is_num,
            'important': important,
            }

        # print extracted, '2'
        template = make_template(**args)
        new_cur_pos = cur_pos-len(abbr)
        assert cur_pos-len(abbr) >= 0
        self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos))
        self.view.run_command("insert_snippet", {"contents": template})

WHITE_SPACE_FINDER = re.compile(r'^(\s*)[-\w].*')
class HayakuAddLineCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = self.view.sel()
        if len(regions) > 1:
            align_regions = (self.view.line(r) for r in regions)
            strings = (self.view.substr(r) for r in align_regions)
            finders = (WHITE_SPACE_FINDER.search(s) for s in strings)
{'fraction_non_alphanumeric': 0.11723847611029257, 'fraction_numerical': 0.004630604083350874, 'mean_word_length': 2.365439093484419, 'pattern_counts': {'":': 2, '<': 5, '<?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': '848624', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1542, 'n_words': 339}