From 356c16a009076ae880c1615fc05651b08d1785b4 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sat, 23 Mar 2024 19:10:38 +0300 Subject: [PATCH] [~] Refactor --- dotfiles/.py3.vimrc | 52 +++++++++++++++++++++++++++++++++++++++++++++ dotfiles/.vimrc | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/dotfiles/.py3.vimrc b/dotfiles/.py3.vimrc index 3a58712..2fcee23 100644 --- a/dotfiles/.py3.vimrc +++ b/dotfiles/.py3.vimrc @@ -21,4 +21,56 @@ def f2(): finally: for k, v in context.items(): vim.options[k] = v + +def f5_1(pattern, flags, info): + import subprocess + import io + import re + import tempfile + + #print([pattern, flags, info]) + t1 = subprocess.check_output([ + 'git', 'grep', '-n', '-P', pattern, + ], stderr=subprocess.PIPE) + def watch(data): + with tempfile.NamedTemporaryFile(suffix='.txt') as f: + with io.open(f.name, 'wb') as f2: + f2.write(data) + vim.command('!less %s' % f.name) + + #watch(t1) + + t2 = [] + for o in t1.splitlines(): + try: + #watch(o.encode('utf-8')) + t3 = o.decode('utf-8') + t4 = re.compile(r'^([^\:\=]+)[\:\=](\d+)[\:\=](.*)$').match(t3) + if not t4 is None: + t2.append( + dict( + name=t4[3].strip(), + filename=t4[1], + cmd=t4[2], + ) + ) + except: + pass + #print(t2) + + #return [{'name': 'blah', 'filename': 'docker-compose.yml', 'cmd': '23'}] + return t2 EOF + +function F5(pattern, flags, info) + let res = py3eval( + \'f5_1( + \vim.bindeval("a:pattern").decode("utf-8"), + \vim.bindeval("a:flags"), + \vim.bindeval("a:info") + \)' + \) + return res +endfunc + +set tagfunc=F5 diff --git a/dotfiles/.vimrc b/dotfiles/.vimrc index 8d1cfb9..5ca4662 100644 --- a/dotfiles/.vimrc +++ b/dotfiles/.vimrc @@ -3,7 +3,6 @@ filetype off set viminfo+=/1000000,:1000000 - if has('python3') source = $HOME . '.py3.vimrmc' endif @@ -46,6 +45,7 @@ map i1 :set sw=4 sts=4 ts=4 et ai ci:retab map i2 :set sw=2 sts=2 ts=2 et ai ci:retab map i3 :set t_Co=0 so=999 map i4 :set t_Co=256 so=0 +map i5 :set sw=2 sts=2 ts=2 noet ai ci set foldmethod=indent set nofoldenable map e :e #