Skip to content

Commit

Permalink
Improving blink plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
iogf committed Feb 29, 2020
1 parent e89e0b2 commit cdcbe57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
37 changes: 17 additions & 20 deletions vyapp/plugins/blink_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,28 @@ class BlinkPair:
max=1500
timeout=1000

def __init__(self, area, lhs, lhr):
self.lhr = lhr
self.lhs = lhs
self.area = area

self.tname = '(blink%s)' % id(self)
self.area.tag_config(self.tname, **self.setup)
def __init__(self, area, *pairs):
self.pairs = pairs
self.area = area

self.area.tag_config('(BLINK)', **self.setup)
self.id = self.area.hook('blink-pair', '-1',
'<FocusIn>', lambda e: self.blink())
'<FocusIn>', lambda e: self.scale())

self.area.hook('blink-pair', '-1', '<FocusOut>',
lambda e: self.area.after_cancel(self.id))

def blink(self):
self.id = self.area.after(self.timeout, self.blink)

index = self.area.case_pair('insert',
self.max, self.lhs, self.lhr)

if self.area.tag_ranges(self.tname):
self.area.tag_remove(self.tname,
'insert -%sc' % self.max, 'insert +%sc' % self.max)

if index: self.area.tag_add(self.tname,
index, '%s +1c' % index)
def scale(self):
self.id = self.area.after(self.timeout, self.scale)
index0 = 'insert -%sc' % self.max
index1 = 'insert +%sc' % self.max

if self.area.tag_ranges('(BLINK)'):
self.area.tag_remove('(BLINK)', index0, index1)
for lhs, lhr in self.pairs:
index = self.area.case_pair(
'insert', self.max, lhs, lhr)
if index: self.area.tag_add(
'(BLINK)', index, '%s +1c' % index)

install = BlinkPair
4 changes: 1 addition & 3 deletions vyapp/vyrc
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ autoload(data_del)
# Used to highlight pairs of character like () {} [].
# It is useful when playing with lisp things.
from vyapp.plugins import blink_pair
autoload(blink_pair, '(', ')')
autoload(blink_pair, '[', ']')
autoload(blink_pair, '{', '}')
autoload(blink_pair, ('(', ')'), ('[', ']'), ('{', '}'))

# Used to complete words when Control-q is issued on insert mode.
from vyapp.plugins import word_completion
Expand Down

0 comments on commit cdcbe57

Please sign in to comment.