From 8b6769b34d645d47738c2aa4766505efb47358a2 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Fri, 14 Feb 2020 21:14:05 +0000 Subject: [PATCH 1/8] Improving performance, removing unnecessary code. --- vyapp/ask.py | 2 +- vyapp/base.py | 5 ++-- vyapp/completion.py | 2 +- vyapp/plugins/anchors.py | 2 +- vyapp/plugins/builtin_modes.py | 2 +- vyapp/plugins/cursor_status.py | 2 +- vyapp/plugins/fsearch.py | 2 +- vyapp/plugins/fsniffer.py | 2 +- vyapp/plugins/fstmt.py | 2 +- vyapp/plugins/gohints.py | 2 +- vyapp/plugins/home.py | 2 +- vyapp/plugins/ibash.py | 2 +- vyapp/plugins/match_sym_pair.py | 45 +++++++++++++++---------------- vyapp/plugins/mode_shortcut.py | 2 +- vyapp/plugins/mypy.py | 2 +- vyapp/plugins/project.py | 2 +- vyapp/plugins/quick_jumps.py | 2 +- vyapp/plugins/quick_search.py | 2 +- vyapp/plugins/rope.py | 2 +- vyapp/plugins/shift.py | 2 +- vyapp/plugins/snakerr.py | 2 +- vyapp/plugins/spacing.py | 2 +- vyapp/plugins/spawn/base_spawn.py | 2 +- vyapp/plugins/syntax/spider.py | 2 +- vyapp/plugins/tab_search.py | 2 +- vyapp/plugins/ternjs/completer.py | 2 +- vyapp/plugins/tidy.py | 2 +- vyapp/plugins/word_search.py | 2 +- vyapp/plugins/ysnippet.py | 2 +- 29 files changed, 52 insertions(+), 52 deletions(-) diff --git a/vyapp/ask.py b/vyapp/ask.py index bac06b1..76602e0 100644 --- a/vyapp/ask.py +++ b/vyapp/ask.py @@ -9,7 +9,7 @@ class AskCancel(Exception): pass -class InputBox(object): +class InputBox: def __init__(self, default_data=''): self.default_data = default_data diff --git a/vyapp/base.py b/vyapp/base.py index 666ab73..2401715 100644 --- a/vyapp/base.py +++ b/vyapp/base.py @@ -56,12 +56,13 @@ def create_widgets(self): self.status.grid(row=2, sticky='we') Grid.rowconfigure(self, 0, weight=1) Grid.columnconfigure(self, 0, weight=1) + self.event_generate('<>') -class Debug(object): +class Debug: def write(self, *args): pass - def flush(object): + def flush(self): """ It seems python calls this method before exiting if it doesnt exist then python3 ends up with an error diff --git a/vyapp/completion.py b/vyapp/completion.py index b681093..bb9b18b 100644 --- a/vyapp/completion.py +++ b/vyapp/completion.py @@ -3,7 +3,7 @@ from tkinter import LEFT, BOTH, Text, SCROLL from vyapp.mixins import Echo -class Option(object): +class Option: def __init__(self, name, type='', doc=''): self.name = name self.doc = doc diff --git a/vyapp/plugins/anchors.py b/vyapp/plugins/anchors.py index c15633c..e4593c6 100644 --- a/vyapp/plugins/anchors.py +++ b/vyapp/plugins/anchors.py @@ -7,7 +7,7 @@ """ -class Anchors(object): +class Anchors: def __init__(self, area): area.add_mode('ANCHORS') self.area = area diff --git a/vyapp/plugins/builtin_modes.py b/vyapp/plugins/builtin_modes.py index 3fc78b2..f6f27c0 100644 --- a/vyapp/plugins/builtin_modes.py +++ b/vyapp/plugins/builtin_modes.py @@ -39,7 +39,7 @@ Description: Get the AreaVi instance that is focused in ALPHA mode. """ -class BuiltinModes(object): +class BuiltinModes: def __init__(self, area): self.area = area diff --git a/vyapp/plugins/cursor_status.py b/vyapp/plugins/cursor_status.py index 7783972..19a42b4 100644 --- a/vyapp/plugins/cursor_status.py +++ b/vyapp/plugins/cursor_status.py @@ -1,6 +1,6 @@ from vyapp.app import root -class CursorStatus(object): +class CursorStatus: def __init__(self, area, timeout=1000): self.area = area self.timeout = timeout diff --git a/vyapp/plugins/fsearch.py b/vyapp/plugins/fsearch.py index 1354788..16dc6c6 100644 --- a/vyapp/plugins/fsearch.py +++ b/vyapp/plugins/fsearch.py @@ -30,7 +30,7 @@ from vyapp.app import root -class FSearch(object): +class FSearch: def __init__(self, area): self.area = area self.output = '' diff --git a/vyapp/plugins/fsniffer.py b/vyapp/plugins/fsniffer.py index c3e1aac..63423cd 100644 --- a/vyapp/plugins/fsniffer.py +++ b/vyapp/plugins/fsniffer.py @@ -36,7 +36,7 @@ from os.path import basename -class FSniffer(object): +class FSniffer: options = LinePicker() wide = True diff --git a/vyapp/plugins/fstmt.py b/vyapp/plugins/fstmt.py index 819f418..3242ffb 100644 --- a/vyapp/plugins/fstmt.py +++ b/vyapp/plugins/fstmt.py @@ -38,7 +38,7 @@ from vyapp.base import printd from vyapp.app import root -class Fstmt(object): +class Fstmt: options = LinePicker() path = 'ag' diff --git a/vyapp/plugins/gohints.py b/vyapp/plugins/gohints.py index 6bef5f9..166d550 100644 --- a/vyapp/plugins/gohints.py +++ b/vyapp/plugins/gohints.py @@ -51,7 +51,7 @@ def build(self, data): return [Option(ind['name'], 'Type:%s' % ind['type'], 'Class:%s' % ind['class']) for ind in data[1]] -class GolangCompletion(object): +class GolangCompletion: PATH = 'gocode' def __init__(self, area): diff --git a/vyapp/plugins/home.py b/vyapp/plugins/home.py index 5f26486..4330313 100644 --- a/vyapp/plugins/home.py +++ b/vyapp/plugins/home.py @@ -10,7 +10,7 @@ from vyapp.app import root from vyapp.ask import Ask -class Home(object): +class Home: def __init__(self, area): self.area = area area.install('home', diff --git a/vyapp/plugins/ibash.py b/vyapp/plugins/ibash.py index bc14cee..4508fc4 100644 --- a/vyapp/plugins/ibash.py +++ b/vyapp/plugins/ibash.py @@ -44,7 +44,7 @@ from vyapp.plugins import ENV import sys -class Process(object): +class Process: def __call__(self, area): area.install('ibash', ('NORMAL', '', lambda event: self.dump_region(event.widget)), diff --git a/vyapp/plugins/match_sym_pair.py b/vyapp/plugins/match_sym_pair.py index 7055add..7c1a65d 100644 --- a/vyapp/plugins/match_sym_pair.py +++ b/vyapp/plugins/match_sym_pair.py @@ -6,37 +6,36 @@ """ +from vyapp.areavi import AreaVi +from vyapp.app import root -class MatchSymPair(object): - def __init__(self, area, setup={'background':'pink', - 'foreground':'black'}, max=1500, timeout=500): - self.max = max - self.timeout = timeout - self.area = area +class MatchSymPair: + setup={'background':'pink', + 'foreground':'black'} + max=1500 + timeout=700 - area.tag_config('(paren)', **setup) - area.tag_config('(bracket)', **setup) - area.tag_config('(brace)', **setup) + def __call__(self, area): + area.tag_config('(paren)', **self.setup) + area.tag_config('(bracket)', **self.setup) + area.tag_config('(brace)', **self.setup) + def __init__(self): + # root.bind('<>', self.install_handles, once=True) + root.after_idle(self.install_handles) + + def install_handles(self): self.blink('(paren)', ('(', ')')) self.blink('(bracket)', ('[', ']')) self.blink('(brace)', ('{', '}')) def blink(self, name, args): - self.area.after(self.timeout, self.blink, name, args) - index = self.area.case_pair('insert', self.max, *args) + root.after(self.timeout, self.blink, name, args) + index = AreaVi.INPUT.case_pair('insert', self.max, *args) - self.area.tag_remove(name, '1.0', 'end') + AreaVi.INPUT.tag_remove(name, '1.0', 'end') if not index: return - self.area.tag_add(name, 'insert', 'insert +1c') - self.area.tag_add(name, index, '%s +1c' % index) - - - -install = MatchSymPair - - - - - + AreaVi.INPUT.tag_add(name, 'insert', 'insert +1c') + AreaVi.INPUT.tag_add(name, index, '%s +1c' % index) +install = MatchSymPair() diff --git a/vyapp/plugins/mode_shortcut.py b/vyapp/plugins/mode_shortcut.py index 3a120f1..0a9584e 100644 --- a/vyapp/plugins/mode_shortcut.py +++ b/vyapp/plugins/mode_shortcut.py @@ -22,7 +22,7 @@ from vyapp.app import root -class ModeShortcut(object): +class ModeShortcut: target_id = 'NORMAL' def __init__(self, area): diff --git a/vyapp/plugins/mypy.py b/vyapp/plugins/mypy.py index a0ca9cc..1acd707 100644 --- a/vyapp/plugins/mypy.py +++ b/vyapp/plugins/mypy.py @@ -44,7 +44,7 @@ from re import findall import sys -class StaticChecker(object): +class StaticChecker: options = LinePicker() path = 'mypy' diff --git a/vyapp/plugins/project.py b/vyapp/plugins/project.py index c165dcd..0e4cd21 100644 --- a/vyapp/plugins/project.py +++ b/vyapp/plugins/project.py @@ -27,7 +27,7 @@ def get_sentinel_file(path, *args): elif tmp == dirname(tmp): return '' -class Project(object): +class Project: sentinels = ('.git', '.svn', '.hg', '._') def __init__(self, area): diff --git a/vyapp/plugins/quick_jumps.py b/vyapp/plugins/quick_jumps.py index e0a42d8..e7dfc04 100644 --- a/vyapp/plugins/quick_jumps.py +++ b/vyapp/plugins/quick_jumps.py @@ -20,7 +20,7 @@ """ -class QuickJumps(object): +class QuickJumps: def __init__(self, area): self.area = area area.install('quick-jumps', ('NORMAL', '', lambda event: self.area.mark_set('(PREV_POSITION)', 'insert')), diff --git a/vyapp/plugins/quick_search.py b/vyapp/plugins/quick_search.py index 691dd6d..154ae51 100644 --- a/vyapp/plugins/quick_search.py +++ b/vyapp/plugins/quick_search.py @@ -18,7 +18,7 @@ from vyapp.base import printd from vyapp.app import root -class QuickSearch(object): +class QuickSearch: confs = { 'background':'yellow', 'foreground':'black' } diff --git a/vyapp/plugins/rope.py b/vyapp/plugins/rope.py index e3e7fc4..007740a 100644 --- a/vyapp/plugins/rope.py +++ b/vyapp/plugins/rope.py @@ -29,7 +29,7 @@ from rope.base import libutils from rope.refactor.move import create_move -class PythonRefactor(object): +class PythonRefactor: def __init__(self, area): self.area = area self.files = None diff --git a/vyapp/plugins/shift.py b/vyapp/plugins/shift.py index ea7220f..90db409 100644 --- a/vyapp/plugins/shift.py +++ b/vyapp/plugins/shift.py @@ -19,7 +19,7 @@ """ -class Shift(object): +class Shift: def __init__(self, area): area.install('shift', ('NORMAL', '', self.sel_right), diff --git a/vyapp/plugins/snakerr.py b/vyapp/plugins/snakerr.py index f9ab74c..2a4bf23 100644 --- a/vyapp/plugins/snakerr.py +++ b/vyapp/plugins/snakerr.py @@ -45,7 +45,7 @@ from re import findall import sys -class PythonChecker(object): +class PythonChecker: options = LinePicker() path = 'pyflakes' diff --git a/vyapp/plugins/spacing.py b/vyapp/plugins/spacing.py index 9a7269b..8a1a4e7 100644 --- a/vyapp/plugins/spacing.py +++ b/vyapp/plugins/spacing.py @@ -21,7 +21,7 @@ from vyapp.areavi import AreaVi from vyapp.app import root -class Tab(object): +class Tab: scheme = {} def __init__(self, area): diff --git a/vyapp/plugins/spawn/base_spawn.py b/vyapp/plugins/spawn/base_spawn.py index e9ac3d0..3e7412e 100644 --- a/vyapp/plugins/spawn/base_spawn.py +++ b/vyapp/plugins/spawn/base_spawn.py @@ -2,7 +2,7 @@ from vyapp.app import root import signal -class BaseSpawn(object): +class BaseSpawn: def __init__(self, cmd, input, output): self.cmd = cmd self.input = input diff --git a/vyapp/plugins/syntax/spider.py b/vyapp/plugins/syntax/spider.py index 0c3746b..fb7f6e0 100644 --- a/vyapp/plugins/syntax/spider.py +++ b/vyapp/plugins/syntax/spider.py @@ -7,7 +7,7 @@ from pygments.lexers import get_lexer_for_filename, guess_lexer from re import search -class Spider(object): +class Spider: def __init__(self, area, theme, max=10): self.area = area self.max = max diff --git a/vyapp/plugins/tab_search.py b/vyapp/plugins/tab_search.py index dbfc49e..da0431e 100644 --- a/vyapp/plugins/tab_search.py +++ b/vyapp/plugins/tab_search.py @@ -12,7 +12,7 @@ from vyapp.ask import Get from vyapp.app import root -class TabSearch(object): +class TabSearch: def __init__(self, area): self.area = area diff --git a/vyapp/plugins/ternjs/completer.py b/vyapp/plugins/ternjs/completer.py index 779ac86..f1e46a8 100644 --- a/vyapp/plugins/ternjs/completer.py +++ b/vyapp/plugins/ternjs/completer.py @@ -83,7 +83,7 @@ def build(self, data): data = json.loads(data) return [Option(**ind) for ind in data['completions']] -class JavascriptCompletion(object): +class JavascriptCompletion: PATH = 'tern' PORT = 1234 diff --git a/vyapp/plugins/tidy.py b/vyapp/plugins/tidy.py index 9e8037a..9570eeb 100644 --- a/vyapp/plugins/tidy.py +++ b/vyapp/plugins/tidy.py @@ -34,7 +34,7 @@ from re import findall import sys -class HtmlChecker(object): +class HtmlChecker: PATH = 'tidy' def __init__(self, area): diff --git a/vyapp/plugins/word_search.py b/vyapp/plugins/word_search.py index 23ebfc4..ba79ad7 100644 --- a/vyapp/plugins/word_search.py +++ b/vyapp/plugins/word_search.py @@ -29,7 +29,7 @@ from re import escape from vyapp.app import root -class WordSearch(object): +class WordSearch: def __init__(self, area, setup={'background':'yellow', 'foreground':'black'}): self.area = area area.tag_configure('(ISEARCH_MATCH)', **setup) diff --git a/vyapp/plugins/ysnippet.py b/vyapp/plugins/ysnippet.py index d3f617a..e0ea3f1 100644 --- a/vyapp/plugins/ysnippet.py +++ b/vyapp/plugins/ysnippet.py @@ -91,7 +91,7 @@ def delete(self, event): # Otherwise it gets messed up. del self.options[index] -class Ysnippet(object): +class Ysnippet: nocas = True db_name = join(expanduser('~'), '.ysnippet.db') conn = sqlite3.connect(db_name) From 7bcf7ea92d59d5097487410e7e9e7c4e1b6bf1f2 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Fri, 14 Feb 2020 21:45:20 +0000 Subject: [PATCH 2/8] Removing unecessary imports. --- vyapp/plugins/__init__.py | 3 +-- vyapp/plugins/cmd.py | 1 - vyapp/plugins/cmd_search.py | 1 - vyapp/plugins/deadcode.py | 2 -- vyapp/plugins/delve.py | 5 ----- vyapp/plugins/gdb.py | 6 ------ vyapp/plugins/inline_comment.py | 1 - vyapp/plugins/iocmd.py | 1 - vyapp/plugins/jsdebugger.py | 4 ---- vyapp/plugins/jsonfmt.py | 7 ------- vyapp/plugins/line_index.py | 3 ++- vyapp/plugins/mc.py | 2 +- vyapp/plugins/mypy.py | 4 +--- vyapp/plugins/project.py | 2 -- vyapp/plugins/spacing.py | 2 -- vyapp/plugins/spawn/base_spawn.py | 1 - vyapp/plugins/syntax/spider.py | 2 -- vyapp/plugins/tabs.py | 3 +-- vyapp/plugins/ternjs/completer.py | 1 - vyapp/plugins/ycmd/client.py | 3 +-- 20 files changed, 7 insertions(+), 47 deletions(-) diff --git a/vyapp/plugins/__init__.py b/vyapp/plugins/__init__.py index 43c070d..5400494 100644 --- a/vyapp/plugins/__init__.py +++ b/vyapp/plugins/__init__.py @@ -1,5 +1,4 @@ -from functools import wraps, update_wrapper -from vyapp.areavi import AreaVi +from functools import wraps # ENV is a dict holding plugins objects, like functions, classes etc. # Plugins should install their handles in ENV. diff --git a/vyapp/plugins/cmd.py b/vyapp/plugins/cmd.py index d4ece25..b465257 100644 --- a/vyapp/plugins/cmd.py +++ b/vyapp/plugins/cmd.py @@ -27,7 +27,6 @@ """ from vyapp.plugins import Command -from traceback import print_exc as debug from vyapp.tools import exec_pipe, e_stop from vyapp.ask import Ask from vyapp.plugins import ENV diff --git a/vyapp/plugins/cmd_search.py b/vyapp/plugins/cmd_search.py index 9ad3688..9784b86 100644 --- a/vyapp/plugins/cmd_search.py +++ b/vyapp/plugins/cmd_search.py @@ -8,7 +8,6 @@ """ from vyapp.plugins import Command -from vyapp.areavi import AreaVi @Command() def find(area, regex, handle, *args, **kwargs): diff --git a/vyapp/plugins/deadcode.py b/vyapp/plugins/deadcode.py index 52a5f1e..331bb69 100644 --- a/vyapp/plugins/deadcode.py +++ b/vyapp/plugins/deadcode.py @@ -42,8 +42,6 @@ from subprocess import Popen, STDOUT, PIPE from os.path import relpath from vyapp.widgets import LinePicker -from vyapp.areavi import AreaVi -from vyapp.plugins import ENV from vyapp.tools import get_project_root from vyapp.base import printd from vyapp.app import root diff --git a/vyapp/plugins/delve.py b/vyapp/plugins/delve.py index c71b4c1..3793bb9 100644 --- a/vyapp/plugins/delve.py +++ b/vyapp/plugins/delve.py @@ -62,19 +62,14 @@ """ -from subprocess import Popen, PIPE, STDOUT -from untwisted.expect import Expect, LOAD, CLOSE from untwisted.wrappers import xmap from untwisted.splits import Terminator from vyapp.regutils import RegexEvent from re import findall from vyapp.dap import DAP from vyapp.ask import Ask -from vyapp.areavi import AreaVi from vyapp.app import root import shlex -import sys -import os class Delve(DAP): def __call__(self, area): diff --git a/vyapp/plugins/gdb.py b/vyapp/plugins/gdb.py index 07e0b1c..f97696f 100644 --- a/vyapp/plugins/gdb.py +++ b/vyapp/plugins/gdb.py @@ -60,20 +60,14 @@ """ -from subprocess import Popen, PIPE, STDOUT from tkinter.filedialog import askopenfilename -from untwisted.expect import Expect, LOAD, CLOSE from untwisted.wrappers import xmap from untwisted.splits import Terminator from vyapp.regutils import RegexEvent -from re import findall from vyapp.dap import DAP from vyapp.ask import Ask -from vyapp.areavi import AreaVi from vyapp.app import root import shlex -import sys -import os class GDB(DAP): def __call__(self, area): diff --git a/vyapp/plugins/inline_comment.py b/vyapp/plugins/inline_comment.py index dbc614a..722e75b 100644 --- a/vyapp/plugins/inline_comment.py +++ b/vyapp/plugins/inline_comment.py @@ -19,7 +19,6 @@ """ -from re import escape import os.path DEFAULT = '#' diff --git a/vyapp/plugins/iocmd.py b/vyapp/plugins/iocmd.py index 38dd4be..9967565 100644 --- a/vyapp/plugins/iocmd.py +++ b/vyapp/plugins/iocmd.py @@ -17,7 +17,6 @@ """ from vyapp.plugins import Command -from vyapp.areavi import AreaVi from vyapp.app import root @Command('s') diff --git a/vyapp/plugins/jsdebugger.py b/vyapp/plugins/jsdebugger.py index 4453070..ddbd2bb 100644 --- a/vyapp/plugins/jsdebugger.py +++ b/vyapp/plugins/jsdebugger.py @@ -54,8 +54,6 @@ """ -from subprocess import Popen, PIPE, STDOUT -from untwisted.expect import Expect, LOAD, CLOSE from untwisted.wrappers import xmap from untwisted.splits import Terminator from vyapp.regutils import RegexEvent @@ -63,8 +61,6 @@ from vyapp.ask import Ask from vyapp.app import root import shlex -import sys -import os class JSDebugger(DAP): def __call__(self, area): diff --git a/vyapp/plugins/jsonfmt.py b/vyapp/plugins/jsonfmt.py index e9e04b0..77dab97 100644 --- a/vyapp/plugins/jsonfmt.py +++ b/vyapp/plugins/jsonfmt.py @@ -17,8 +17,6 @@ """ -from vyapp.plugins import ENV -from vyapp.areavi import AreaVi from subprocess import Popen, PIPE from vyapp.app import root @@ -45,9 +43,4 @@ def run_printer(self, event): self.area.chmode('NORMAL') - def fmt_data(self, start, end, data): - self.area.delete(start, end) - self.area.insert(start, output) - - install = FmtJSON \ No newline at end of file diff --git a/vyapp/plugins/line_index.py b/vyapp/plugins/line_index.py index b017c2e..178e037 100644 --- a/vyapp/plugins/line_index.py +++ b/vyapp/plugins/line_index.py @@ -15,7 +15,8 @@ Description: Shows an input text field to insert a Line.Col value to place the cursor at that position. """ -from vyapp.ask import * +from vyapp.ask import Ask +from tkinter import TclError def go_to_pos(area): ask = Ask() diff --git a/vyapp/plugins/mc.py b/vyapp/plugins/mc.py index 0f166ed..3aaf909 100644 --- a/vyapp/plugins/mc.py +++ b/vyapp/plugins/mc.py @@ -58,7 +58,7 @@ """ -from subprocess import check_output, check_call, Popen +from subprocess import check_output, check_call from os.path import expanduser, dirname, join from vyapp.base import printd from vyapp.tools import error diff --git a/vyapp/plugins/mypy.py b/vyapp/plugins/mypy.py index 1acd707..fd35c54 100644 --- a/vyapp/plugins/mypy.py +++ b/vyapp/plugins/mypy.py @@ -34,11 +34,9 @@ from vyapp.plugins import Command from subprocess import Popen, STDOUT, PIPE -from os.path import exists, dirname, join, relpath +from os.path import relpath from vyapp.widgets import LinePicker -from vyapp.areavi import AreaVi from vyapp.tools import get_project_root -from vyapp.plugins import ENV from vyapp.app import root from vyapp.base import printd from re import findall diff --git a/vyapp/plugins/project.py b/vyapp/plugins/project.py index 0e4cd21..e1d3bcc 100644 --- a/vyapp/plugins/project.py +++ b/vyapp/plugins/project.py @@ -10,9 +10,7 @@ """ from os.path import exists, dirname, join -from vyapp.app import root from vyapp.base import printd -from vyapp.ask import Ask def get_sentinel_file(path, *args): """ diff --git a/vyapp/plugins/spacing.py b/vyapp/plugins/spacing.py index 8a1a4e7..5f953f8 100644 --- a/vyapp/plugins/spacing.py +++ b/vyapp/plugins/spacing.py @@ -17,8 +17,6 @@ from vyapp.plugins import Command from os.path import splitext -from vyapp.plugins import ENV -from vyapp.areavi import AreaVi from vyapp.app import root class Tab: diff --git a/vyapp/plugins/spawn/base_spawn.py b/vyapp/plugins/spawn/base_spawn.py index 3e7412e..a0c6034 100644 --- a/vyapp/plugins/spawn/base_spawn.py +++ b/vyapp/plugins/spawn/base_spawn.py @@ -1,4 +1,3 @@ -from untwisted.event import LOAD, CLOSE from vyapp.app import root import signal diff --git a/vyapp/plugins/syntax/spider.py b/vyapp/plugins/syntax/spider.py index fb7f6e0..abbf8b0 100644 --- a/vyapp/plugins/syntax/spider.py +++ b/vyapp/plugins/syntax/spider.py @@ -2,10 +2,8 @@ :) """ -from vyapp.plugins.syntax.tools import * from vyapp.plugins.syntax.keys import PRECEDENCE_TABLE, DEFAULT from pygments.lexers import get_lexer_for_filename, guess_lexer -from re import search class Spider: def __init__(self, area, theme, max=10): diff --git a/vyapp/plugins/tabs.py b/vyapp/plugins/tabs.py index 0bd41ee..5a90841 100644 --- a/vyapp/plugins/tabs.py +++ b/vyapp/plugins/tabs.py @@ -34,8 +34,7 @@ from vyapp.app import root from tkinter.messagebox import * -from tkinter.filedialog import askopenfilename, asksaveasfilename -from vyapp.areavi import AreaVi +from tkinter.filedialog import askopenfilename def load_tab(): """ diff --git a/vyapp/plugins/ternjs/completer.py b/vyapp/plugins/ternjs/completer.py index f1e46a8..d508368 100644 --- a/vyapp/plugins/ternjs/completer.py +++ b/vyapp/plugins/ternjs/completer.py @@ -21,7 +21,6 @@ from vyapp.plugins import Command from subprocess import Popen, PIPE from shutil import copyfile -from os import getcwd import json import requests import sys diff --git a/vyapp/plugins/ycmd/client.py b/vyapp/plugins/ycmd/client.py index e4a635b..76d130e 100644 --- a/vyapp/plugins/ycmd/client.py +++ b/vyapp/plugins/ycmd/client.py @@ -33,12 +33,11 @@ from base64 import b64encode, b64decode from vyapp.widgets import LinePicker from tempfile import NamedTemporaryFile -from subprocess import Popen, PIPE +from subprocess import Popen from shutil import copyfile from vyapp.plugins import Command, ENV from vyapp.app import root from vyapp.base import printd -from vyapp.areavi import AreaVi import atexit import requests import random From 1d99a90ef780aa3bd8ae05b6a10240fe01f07523 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Fri, 14 Feb 2020 21:46:20 +0000 Subject: [PATCH 3/8] Removing unecessary import. --- vyapp/plugins/spawn/unix_platform.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vyapp/plugins/spawn/unix_platform.py b/vyapp/plugins/spawn/unix_platform.py index 8f7001c..2a1e9f8 100644 --- a/vyapp/plugins/spawn/unix_platform.py +++ b/vyapp/plugins/spawn/unix_platform.py @@ -56,7 +56,6 @@ from os import environ, setsid, killpg from vyapp.plugins.spawn.base_spawn import BaseSpawn from vyapp.app import root -from os import environ class Spawn(BaseSpawn): def __init__(self, cmd): From 810e21ec0864a49e28039ef8edcbc6ecb07fc7fc Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Fri, 14 Feb 2020 21:50:18 +0000 Subject: [PATCH 4/8] Fixing imports due to changings. --- vyapp/plugins/syntax/spider.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vyapp/plugins/syntax/spider.py b/vyapp/plugins/syntax/spider.py index abbf8b0..3eae14c 100644 --- a/vyapp/plugins/syntax/spider.py +++ b/vyapp/plugins/syntax/spider.py @@ -1,10 +1,11 @@ """ :) """ - +from vyapp.plugins.syntax.tools import get_tokens_unprocessed_matrix, matrix_step from vyapp.plugins.syntax.keys import PRECEDENCE_TABLE, DEFAULT from pygments.lexers import get_lexer_for_filename, guess_lexer + class Spider: def __init__(self, area, theme, max=10): self.area = area From 28f037df04b6320babb407ea5603fa6facb32ed2 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Fri, 14 Feb 2020 21:55:19 +0000 Subject: [PATCH 5/8] Fixing imports. --- vyapp/areavi.py | 2 +- vyapp/ask.py | 3 ++- vyapp/plugins/io.py | 2 +- vyapp/plugins/syntax/spider.py | 2 +- vyapp/plugins/tabs.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/vyapp/areavi.py b/vyapp/areavi.py index 5f183ca..3271656 100644 --- a/vyapp/areavi.py +++ b/vyapp/areavi.py @@ -3,7 +3,7 @@ """ from vyapp.mixins import DataEvent, IdleEvent -from tkinter import * +from tkinter import Text, IntVar import os class AreaVi(Text, DataEvent, IdleEvent): diff --git a/vyapp/ask.py b/vyapp/ask.py index 76602e0..9c2073d 100644 --- a/vyapp/ask.py +++ b/vyapp/ask.py @@ -2,7 +2,8 @@ This module implements basic input data scheme. """ -from tkinter import * +# from tkinter import * +from tkinter import Frame, Entry, BOTH from vyapp.app import root from vyapp.mixins import DataEvent, IdleEvent diff --git a/vyapp/plugins/io.py b/vyapp/plugins/io.py index 9f7d460..0072423 100644 --- a/vyapp/plugins/io.py +++ b/vyapp/plugins/io.py @@ -36,7 +36,7 @@ """ -from tkinter.messagebox import * +# from tkinter.messagebox import * from tkinter.filedialog import askopenfilename, asksaveasfilename from vyapp.app import root from vyapp.ask import Ask diff --git a/vyapp/plugins/syntax/spider.py b/vyapp/plugins/syntax/spider.py index 3eae14c..0277dfe 100644 --- a/vyapp/plugins/syntax/spider.py +++ b/vyapp/plugins/syntax/spider.py @@ -1,7 +1,7 @@ """ :) """ -from vyapp.plugins.syntax.tools import get_tokens_unprocessed_matrix, matrix_step +from vyapp.plugins.syntax.tools import get_tokens_unprocessed_matrix from vyapp.plugins.syntax.keys import PRECEDENCE_TABLE, DEFAULT from pygments.lexers import get_lexer_for_filename, guess_lexer diff --git a/vyapp/plugins/tabs.py b/vyapp/plugins/tabs.py index 5a90841..e991fe8 100644 --- a/vyapp/plugins/tabs.py +++ b/vyapp/plugins/tabs.py @@ -33,7 +33,7 @@ """ from vyapp.app import root -from tkinter.messagebox import * +# from tkinter.messagebox import * from tkinter.filedialog import askopenfilename def load_tab(): From ac606d5d2238114e9dd5a33fb006817bdfffbee2 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Sun, 16 Feb 2020 23:10:51 +0000 Subject: [PATCH 6/8] Improving code. --- vyapp/app.py | 1 + vyapp/base.py | 1 - vyapp/plugins/match_sym_pair.py | 11 +++++++---- vyapp/plugins/tabs.py | 11 ----------- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/vyapp/app.py b/vyapp/app.py index 5c21bc8..64f26fc 100644 --- a/vyapp/app.py +++ b/vyapp/app.py @@ -50,4 +50,5 @@ # attempting to load a non existing file. if not args.verbose: sys.stderr = Debug() +root.event_generate('<>') diff --git a/vyapp/base.py b/vyapp/base.py index 2401715..b038019 100644 --- a/vyapp/base.py +++ b/vyapp/base.py @@ -56,7 +56,6 @@ def create_widgets(self): self.status.grid(row=2, sticky='we') Grid.rowconfigure(self, 0, weight=1) Grid.columnconfigure(self, 0, weight=1) - self.event_generate('<>') class Debug: def write(self, *args): diff --git a/vyapp/plugins/match_sym_pair.py b/vyapp/plugins/match_sym_pair.py index 7c1a65d..a8bbc78 100644 --- a/vyapp/plugins/match_sym_pair.py +++ b/vyapp/plugins/match_sym_pair.py @@ -13,7 +13,7 @@ class MatchSymPair: setup={'background':'pink', 'foreground':'black'} max=1500 - timeout=700 + timeout=1000 def __call__(self, area): area.tag_config('(paren)', **self.setup) @@ -22,18 +22,21 @@ def __call__(self, area): def __init__(self): # root.bind('<>', self.install_handles, once=True) - root.after_idle(self.install_handles) + root.bind('<>', self.install_handles) - def install_handles(self): + def install_handles(self, event): self.blink('(paren)', ('(', ')')) self.blink('(bracket)', ('[', ']')) self.blink('(brace)', ('{', '}')) def blink(self, name, args): root.after(self.timeout, self.blink, name, args) + if not AreaVi.INPUT: return + index = AreaVi.INPUT.case_pair('insert', self.max, *args) + AreaVi.INPUT.tag_remove(name, + 'insert -%sc' % self.max, 'insert +%sc' % self.max) - AreaVi.INPUT.tag_remove(name, '1.0', 'end') if not index: return AreaVi.INPUT.tag_add(name, 'insert', 'insert +1c') AreaVi.INPUT.tag_add(name, index, '%s +1c' % index) diff --git a/vyapp/plugins/tabs.py b/vyapp/plugins/tabs.py index e991fe8..123bca8 100644 --- a/vyapp/plugins/tabs.py +++ b/vyapp/plugins/tabs.py @@ -104,14 +104,3 @@ def install(area): (-1, '', lambda event: remove_tab()), (-1, '', lambda event: select_left()), (-1, '', lambda event: select_right())) - - - - - - - - - - - From e89e0b2bbf594bb034002f33033bbc0a1b1839fc Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Sat, 22 Feb 2020 23:52:48 +0000 Subject: [PATCH 7/8] Improving blink pair plugin. --- setup.py | 2 +- vyapp/plugins/blink_pair.py | 45 +++++++++++++++++++++++++++++++++ vyapp/plugins/match_sym_pair.py | 44 -------------------------------- vyapp/vyrc | 6 +++-- 4 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 vyapp/plugins/blink_pair.py delete mode 100644 vyapp/plugins/match_sym_pair.py diff --git a/setup.py b/setup.py index ac102c6..9c28814 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name="vy", - version="4.0.0", + version="4.0.1", description="A vim-like in python made from scratch.", packages=["vyapp", "vyapp.plugins", diff --git a/vyapp/plugins/blink_pair.py b/vyapp/plugins/blink_pair.py new file mode 100644 index 0000000..a666e15 --- /dev/null +++ b/vyapp/plugins/blink_pair.py @@ -0,0 +1,45 @@ +""" +Overview +======== + +This plugin implements a mechanism to highligh pairs of ( ) [ ] { }. + + +""" +from vyapp.areavi import AreaVi +from vyapp.app import root + +class BlinkPair: + setup={'background':'pink', + 'foreground':'black'} + 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) + + self.id = self.area.hook('blink-pair', '-1', + '', lambda e: self.blink()) + + self.area.hook('blink-pair', '-1', '', + 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) + +install = BlinkPair diff --git a/vyapp/plugins/match_sym_pair.py b/vyapp/plugins/match_sym_pair.py deleted file mode 100644 index a8bbc78..0000000 --- a/vyapp/plugins/match_sym_pair.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Overview -======== - -This plugin implements a mechanism to highligh pairs of ( ) [ ] { }. - - -""" -from vyapp.areavi import AreaVi -from vyapp.app import root - -class MatchSymPair: - setup={'background':'pink', - 'foreground':'black'} - max=1500 - timeout=1000 - - def __call__(self, area): - area.tag_config('(paren)', **self.setup) - area.tag_config('(bracket)', **self.setup) - area.tag_config('(brace)', **self.setup) - - def __init__(self): - # root.bind('<>', self.install_handles, once=True) - root.bind('<>', self.install_handles) - - def install_handles(self, event): - self.blink('(paren)', ('(', ')')) - self.blink('(bracket)', ('[', ']')) - self.blink('(brace)', ('{', '}')) - - def blink(self, name, args): - root.after(self.timeout, self.blink, name, args) - if not AreaVi.INPUT: return - - index = AreaVi.INPUT.case_pair('insert', self.max, *args) - AreaVi.INPUT.tag_remove(name, - 'insert -%sc' % self.max, 'insert +%sc' % self.max) - - if not index: return - AreaVi.INPUT.tag_add(name, 'insert', 'insert +1c') - AreaVi.INPUT.tag_add(name, index, '%s +1c' % index) - -install = MatchSymPair() diff --git a/vyapp/vyrc b/vyapp/vyrc index e91454d..ed73660 100644 --- a/vyapp/vyrc +++ b/vyapp/vyrc @@ -200,8 +200,10 @@ autoload(data_del) # Used to highlight pairs of character like () {} []. # It is useful when playing with lisp things. -from vyapp.plugins import match_sym_pair -autoload(match_sym_pair) +from vyapp.plugins import 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 From cdcbe57e7c7572ea04c6dec84a6eac5bc842e9ca Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Sat, 29 Feb 2020 19:50:30 +0000 Subject: [PATCH 8/8] Improving blink plugin. --- vyapp/plugins/blink_pair.py | 37 +++++++++++++++++-------------------- vyapp/vyrc | 4 +--- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/vyapp/plugins/blink_pair.py b/vyapp/plugins/blink_pair.py index a666e15..d4f3628 100644 --- a/vyapp/plugins/blink_pair.py +++ b/vyapp/plugins/blink_pair.py @@ -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', - '', lambda e: self.blink()) + '', lambda e: self.scale()) self.area.hook('blink-pair', '-1', '', 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 diff --git a/vyapp/vyrc b/vyapp/vyrc index ed73660..098c826 100644 --- a/vyapp/vyrc +++ b/vyapp/vyrc @@ -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