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

This module implements command search tools. It is possible to execute python
functions to highlight patterns of text and replace patterns.

Usage
=====

Set an AreaVi instance as target for command with <Control-E>
then execute the functions below with <Control-e>. In case of using
<Control-semicolon> there is no need to set a target for command since
that key-command automatically sets the AreaVi instance that has focus as target for commands.

Commands
========

Command: find(self, regex, index='1.0', stopindex='end', exact=None, regexp=True, nocase=None, 
             elide=None, nolinestop=None):
Description: Highlight patterns in the AreaVi instance that has focus.
regex     = The pattern to be searched.
index     = The starting index of the search.
stopindex = The stop index of the search.

Command: replace_all(self, regex, data, index='1.0', stopindex='end', exact=None, regexp=True, nocase=None, 
             elide=None, nolinestop=None):

Description: Replace all occurrences of a given pattern for data.
regex = The pattern to be searched.
data  = The replacement for the pattern.

Command: get(index, stopindex)
Description: Get the text between index and stopindex from an AreaVi instance
that was set as target for commands.
index     = The start index.
stopindex = The stopindex.
"""

from vyapp.plugins import ENV
from vyapp.areavi import AreaVi

ENV['find'] = lambda *args, **kwargs: AreaVi.ACTIVE.tag_add_found('sel', AreaVi.ACTIVE.find(*args, **kwargs))
ENV['sub'] = lambda *args, **kwargs: AreaVi.ACTIVE.replace_all(*args, **kwargs)
ENV['get'] = lambda *args: AreaVi.ACTIVE.get(*args)



<commit_msg>Fixing bugs with cmd_search plugin.<commit_after>"""
Overview
========

This module implements command search tools. It is possible to execute python
functions to highlight patterns of text and replace patterns.

Usage
=====

Set an AreaVi instance as target for command with <Control-E>
then execute the functions below with <Control-e>. In case of using
<Control-semicolon> there is no need to set a target for command since
that key-command automatically sets the AreaVi instance that has focus as target for commands.

Commands
========

Command: find(regex, index='1.0', stopindex='end', exact=None, regexp=True, nocase=None, 
             elide=None, nolinestop=None):
Description: Highlight patterns in the AreaVi instance that has focus.
regex     = The pattern to be searched.
index     = The starting index of the search.
stopindex = The stop index of the search.

Command: sub(regex, data, index='1.0', stopindex='end', exact=None, regexp=True, nocase=None, 
             elide=None, nolinestop=None):

Description: Replace all occurrences of a given pattern for data.
regex = The pattern to be searched.
data  = The replacement for the pattern.

Command: get(index, stopindex)
Description: Get the text between index and stopindex from an AreaVi instance
that was set as target for commands.
index     = The start index.
stopindex = The stopindex.
"""

from vyapp.plugins import ENV
from vyapp.areavi import AreaVi

ENV['find'] = lambda *args, **kwargs: AreaVi.ACTIVE.map_matches('sel', AreaVi.ACTIVE.find(*args, **kwargs))
ENV['sub'] = lambda *args, **kwargs: AreaVi.ACTIVE.replace_all(*args, **kwargs)
ENV['get'] = lambda *args: AreaVi.ACTIVE.get(*args)





{'fraction_non_alphanumeric': 0.1037989829494466, 'fraction_numerical': 0.0023930601256356566, 'mean_word_length': 4.582637729549249, 'pattern_counts': {'":': 0, '<': 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': '6511309', 'n_tokens_mistral': 949, 'n_tokens_neox': 934, 'n_words': 400}