Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
iogf committed Mar 22, 2020
2 parents 622f567 + 0d49051 commit 682cf45
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 76 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from distutils.core import setup

setup(name="vy",
version="4.0.1",
version="4.1.0",
description="A vim-like in python made from scratch.",
packages=["vyapp",
"vyapp.plugins",
Expand Down
11 changes: 5 additions & 6 deletions vyapp/plugins/mc.py
Expand Up @@ -106,7 +106,7 @@ def c_appearance(cls, dir, file):
cls.confs['(MC-DIRECTORY)'] = dir
cls.confs['(MC-FILE)'] = file

printd('Mc - Setting dir/file appearance confs = ', cls.confs)
printd('(Mc) Setting dir/file appearance confs = ', cls.confs)

def list_clipboard(self):
self.area.delete('1.0', 'end')
Expand Down Expand Up @@ -174,7 +174,9 @@ def mv(self):
self.ls(self.ph)

def rename(self):
path = self.area.get_line()
path = self.area.get_line()

root.status.set_msg('(Mc) Rename file:')
ask = Ask()
destin = join(dirname(path), ask.data)
code = check_call('mv "%s" %s' % (path,
Expand All @@ -190,9 +192,9 @@ def rm(self):
self.ls(self.ph)

def create_dir(self):
root.status.set_msg('Type dir name:')
path = self.area.get_line()

root.status.set_msg('Type dir name:')
ask = Ask()
path = join(path, ask.data)
code = check_call('mkdir "%s"' % path, shell=1)
Expand All @@ -203,6 +205,3 @@ def create_dir(self):
install = Mc





102 changes: 33 additions & 69 deletions vyapp/plugins/word_search.py
Expand Up @@ -13,60 +13,55 @@
Mode: NORMAL
Event: <Key-M>
Description: Switch to ISEARCH mode.
Description: Ask for a pattern to search.
Event: <Alt-p>
Mode: INPUT
Description: Put the cursor on the next less possible match.
Event: <Key-V>
Mode: NORMAL
Description: Display previous matches.
Event: <Alt-o>
Mode: INPUT
Description: Put the cursor on the previous possible match.
"""

from vyapp.ask import Get
from vyapp.widgets import LinePicker
from vyapp.ask import Ask
from itertools import groupby
from re import escape
from vyapp.app import root

class WordSearch:
def __init__(self, area, setup={'background':'yellow', 'foreground':'black'}):
options = LinePicker()

def __init__(self, area):
self.area = area
area.tag_configure('(ISEARCH_MATCH)', **setup)
area.install('word-search', (
'NORMAL', '<Key-M>', lambda event: Get(events={
'<Return>' : self.start,
'<Alt-p>' : lambda wid: self.go_down(),
'<Alt-o>' : lambda wid: self.go_up(),
'<Destroy>': lambda wid: self.area.tag_remove(
'(ISEARCH_MATCH)', '1.0', 'end'),
'<Escape> ': lambda wid: True})))

self.seq = []
self.index = -1

def start(self, wid):

area.install('word-search',
('NORMAL', '<Key-M>', self.match),
('NORMAL', '<Key-V>', self.display_matches))

def display_matches(self, event):
self.options.display()
root.status.set_msg('Word Search matches!')

def match(self, event):
"""
"""

self.seq = []
self.index = -1
data = wid.get().split(' ')
find = lambda ind: self.area.find(
escape(ind), '1.0', step='+1l linestart')
ask = Ask()
data = ask.data.split(' ')
find = lambda ind: self.area.find(
escape(ind).lower(), '1.0', step='+1l linestart')

self.seq = self.match_possible_regions(find, data)
seq = self.match_regions(find, data)
matches = ((self.area.filename, line,
self.area.get_line('%s.0' % line))
for count, line in seq)

if not self.seq:
self.no_match()
if not seq:
root.status.set_msg('No pattern found!')
else:
self.go_down()

def no_match(self):
root.status.set_msg('No pattern found!')
self.options(matches)

def match_possible_regions(self, find, data):
def match_regions(self, find, data):
regions = []

for ind in data:
Expand All @@ -75,10 +70,10 @@ def match_possible_regions(self, find, data):

regions.sort()
seq = groupby(regions, lambda ind: ind[0])
matches = self.sort_possible_matches(seq, data)
matches = self.sort_matches(seq, data)
return matches

def sort_possible_matches(self, seq, data):
def sort_matches(self, seq, data):
matches = []

for line, group in seq:
Expand All @@ -90,36 +85,5 @@ def sort_possible_matches(self, seq, data):
matches.sort(reverse=True)
return matches

def go_up(self):
"""
"""


if self.index - 1 < 0: return
line = self.seq[self.index - 1][1]
pos0 = '%s.0' % line
pos1 = '%s.0 lineend' % line
self.area.tag_remove('(ISEARCH_MATCH)', '1.0', 'end')
self.area.tag_add('(ISEARCH_MATCH)', pos0, pos1)
self.area.seecur(pos0)
self.index = self.index - 1

def go_down(self):
"""
"""
if self.index + 1 >= len(self.seq): return
line = self.seq[self.index + 1][1]
pos0 = '%s.0' % line
pos1 = '%s.0 lineend' % line
self.area.tag_remove('(ISEARCH_MATCH)', '1.0', 'end')
self.area.tag_add('(ISEARCH_MATCH)', pos0, pos1)
self.area.seecur(pos0)

self.index = self.index + 1

install = WordSearch



0 comments on commit 682cf45

Please sign in to comment.