<commit_before>"""
Overview
========

Used to find snippets accross folders.

Key-Commands
============


"""

from subprocess import Popen, STDOUT, PIPE
from vyapp.regutils import build_regex
from vyapp.widgets import LinePicker
from vyapp.areavi import AreaVi
from vyapp.app import root
from vyapp.ask import Get
from re import findall

class Fsnip:
    options = LinePicker()
    FOLDERS = []
    PATH   = 'ag'
    fptr   = ''
    def  __init__(self, area):
        self.area = area
        area.install('fsnip', 
        (-1, '<Key-b>', lambda event: self.options.display()),
        (-1, '<Key-B>', lambda event: Get(events = {
        '<Return>':self.find, 
        '<Control-g>':self.set_file_pattern, 
        '<Escape>':  lambda wid: True})))

    def set_file_pattern(self, wid):
        self.fptr = build_regex(wid.get())
        root.status.set_msg('Set file pattern:%s' % self.fptr)
        wid.delete(0, 'end')

    def find(self, wid):
        """
        """

        root.status.set_msg('Set fsnip pattern!')
        pattern = build_regex(wid.get())
        dirs    = ' '.join(self.FOLDERS)
        child   = Popen([self.PATH, '--nocolor', '--nogroup', '-G', self.fptr,
        '--vimgrep', '--noheading', pattern, dirs], stdout=PIPE, 
        stderr=STDOUT, encoding=self.area.charset)

        output =  child.communicate()[0]
        regex  = '(.+):([0-9]+):[0-9]+:(.+)' 
        ranges = findall(regex, output)
        if ranges:
            self.options(ranges)
        else:
            root.status.set_msg('No results:%s!' % pattern)
        return True

install = Fsnip

<commit_msg>Fixing misbehavior with fsnip.<commit_after>"""
Overview
========

Used to find snippets accross folders.

Key-Commands
============


"""

from subprocess import Popen, STDOUT, PIPE
from vyapp.regutils import build_regex
from vyapp.widgets import LinePicker
from vyapp.areavi import AreaVi
from vyapp.app import root
from vyapp.ask import Get
from re import findall

class Fsnip:
    options = LinePicker()
    FOLDERS = []
    PATH   = 'ag'
    fptr   = ''
    def  __init__(self, area):
        self.area = area
        area.install('fsnip', 
        ('NORMAL', '<Key-b>', lambda event: self.options.display()),
        ('NORMAL', '<Key-B>', lambda event: Get(events = {
        '<Return>':self.find, 
        '<Control-g>':self.set_file_pattern, 
        '<Escape>':  lambda wid: True})))

    def set_file_pattern(self, wid):
        self.fptr = build_regex(wid.get())
        root.status.set_msg('Set file pattern:%s' % self.fptr)
        wid.delete(0, 'end')

    def find(self, wid):
        """
        """

        root.status.set_msg('Set fsnip pattern!')
        pattern = build_regex(wid.get())
        dirs    = ' '.join(self.FOLDERS)
        child   = Popen([self.PATH, '--nocolor', '--nogroup', '-G', self.fptr,
        '--vimgrep', '--noheading', pattern, dirs], stdout=PIPE, 
        stderr=STDOUT, encoding=self.area.charset)

        output =  child.communicate()[0]
        regex  = '(.+):([0-9]+):[0-9]+:(.+)' 
        ranges = findall(regex, output)
        if ranges:
            self.options(ranges)
        else:
            root.status.set_msg('No results:%s!' % pattern)
        return True

install = Fsnip



{'fraction_non_alphanumeric': 0.16420209488601356, 'fraction_numerical': 0.004313000616142945, 'mean_word_length': 2.4396186440677967, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5412262', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1080, 'n_words': 245}