2013-03-11 10:40:09 +01:00
|
|
|
# vim:fileencoding=utf-8:noet
|
2013-02-24 11:03:14 +01:00
|
|
|
_log = []
|
2013-05-19 10:14:06 +02:00
|
|
|
vars = {}
|
2013-06-22 17:14:07 +02:00
|
|
|
vvars = {'version': 703}
|
2014-08-03 07:07:31 +02:00
|
|
|
_tabpage = 0
|
2013-02-24 11:03:14 +01:00
|
|
|
_mode = 'n'
|
|
|
|
_buf_purge_events = set()
|
2013-05-19 10:14:06 +02:00
|
|
|
options = {
|
2013-03-10 10:08:01 +01:00
|
|
|
'paste': 0,
|
|
|
|
'ambiwidth': 'single',
|
2014-08-03 07:07:31 +02:00
|
|
|
'columns': 80,
|
2014-08-27 21:42:04 +02:00
|
|
|
'encoding': 'utf-8',
|
2013-03-10 10:08:01 +01:00
|
|
|
}
|
2013-02-24 11:03:14 +01:00
|
|
|
_last_bufnr = 0
|
|
|
|
_highlights = {}
|
2014-06-25 17:55:20 +02:00
|
|
|
from collections import defaultdict as _defaultdict
|
|
|
|
_environ = _defaultdict(lambda: '')
|
|
|
|
del _defaultdict
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
_thread_id = None
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
def _set_thread_id():
|
|
|
|
global _thread_id
|
|
|
|
from threading import current_thread
|
|
|
|
_thread_id = current_thread().ident
|
|
|
|
|
|
|
|
|
|
|
|
# Assuming import is done from the main thread
|
|
|
|
_set_thread_id()
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
def _print_log():
|
|
|
|
for item in _log:
|
|
|
|
print (item)
|
|
|
|
_log[:] = ()
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
def _vim(func):
|
2013-02-24 11:03:14 +01:00
|
|
|
from functools import wraps
|
2013-04-03 23:44:28 +02:00
|
|
|
from threading import current_thread
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
@wraps(func)
|
2013-03-03 17:40:35 +01:00
|
|
|
def f(*args, **kwargs):
|
2013-04-03 23:44:28 +02:00
|
|
|
global _thread_id
|
|
|
|
if _thread_id != current_thread().ident:
|
|
|
|
raise RuntimeError('Accessing vim from separate threads is not allowed')
|
2013-02-24 11:03:14 +01:00
|
|
|
_log.append((func.__name__, args))
|
2013-03-03 17:40:35 +01:00
|
|
|
return func(*args, **kwargs)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2014-07-10 20:54:27 +02:00
|
|
|
def _unicode(func):
|
|
|
|
from functools import wraps
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
return func
|
|
|
|
|
|
|
|
@wraps(func)
|
|
|
|
def f(*args, **kwargs):
|
|
|
|
from powerline.lib.unicode import u
|
|
|
|
ret = func(*args, **kwargs)
|
|
|
|
if isinstance(ret, bytes):
|
|
|
|
ret = u(ret)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
class _Buffers(object):
|
|
|
|
@_vim
|
|
|
|
def __init__(self):
|
|
|
|
self.d = {}
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
@_vim
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.d)
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
|
|
|
def __getitem__(self, item):
|
|
|
|
return self.d[item]
|
|
|
|
|
|
|
|
@_vim
|
|
|
|
def __setitem__(self, item, value):
|
|
|
|
self.d[item] = value
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
@_vim
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self.d.values())
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
|
|
|
def __contains__(self, item):
|
|
|
|
return item in self.d
|
|
|
|
|
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def _keys(self):
|
2013-04-03 23:44:28 +02:00
|
|
|
return self.d.keys()
|
|
|
|
|
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def _pop(self, *args, **kwargs):
|
2013-04-03 23:44:28 +02:00
|
|
|
return self.d.pop(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
buffers = _Buffers()
|
|
|
|
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
class _ObjList(object):
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def __init__(self, objtype):
|
2013-04-03 23:44:28 +02:00
|
|
|
self.l = []
|
2014-08-03 07:07:31 +02:00
|
|
|
self.objtype = objtype
|
2013-04-03 23:44:28 +02:00
|
|
|
|
|
|
|
@_vim
|
|
|
|
def __getitem__(self, item):
|
2014-08-03 07:07:31 +02:00
|
|
|
return self.l[item - int(item > 0)]
|
2013-04-03 23:44:28 +02:00
|
|
|
|
|
|
|
@_vim
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.l)
|
|
|
|
|
|
|
|
@_vim
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self.l)
|
|
|
|
|
|
|
|
@_vim
|
2014-08-03 10:43:41 +02:00
|
|
|
def _pop(self, idx):
|
|
|
|
obj = self.l.pop(idx - 1)
|
|
|
|
for moved_obj in self.l[idx - 1:]:
|
|
|
|
moved_obj.number -= 1
|
|
|
|
return obj
|
2013-04-03 23:44:28 +02:00
|
|
|
|
|
|
|
@_vim
|
2014-07-10 20:22:24 +02:00
|
|
|
def _append(self, *args, **kwargs):
|
2013-04-03 23:44:28 +02:00
|
|
|
return self.l.append(*args, **kwargs)
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
@_vim
|
|
|
|
def _new(self, *args, **kwargs):
|
|
|
|
number = len(self) + 1
|
|
|
|
new_obj = self.objtype(number, *args, **kwargs)
|
|
|
|
self._append(new_obj)
|
|
|
|
return new_obj
|
2013-04-03 23:44:28 +02:00
|
|
|
|
|
|
|
|
2013-03-24 02:45:52 +01:00
|
|
|
def _construct_result(r):
|
|
|
|
import sys
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
return r
|
|
|
|
else:
|
2014-07-10 21:08:59 +02:00
|
|
|
if isinstance(r, str):
|
2013-03-24 02:45:52 +01:00
|
|
|
return r.encode('utf-8')
|
2014-07-10 21:08:59 +02:00
|
|
|
elif isinstance(r, list):
|
|
|
|
return [_construct_result(i) for i in r]
|
|
|
|
elif isinstance(r, dict):
|
2014-08-15 18:58:19 +02:00
|
|
|
return dict((
|
|
|
|
(_construct_result(k), _construct_result(v))
|
|
|
|
for k, v in r.items()
|
|
|
|
))
|
2013-03-24 02:45:52 +01:00
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
def _str_func(func):
|
|
|
|
from functools import wraps
|
2013-03-24 16:59:56 +01:00
|
|
|
|
2013-03-24 02:45:52 +01:00
|
|
|
@wraps(func)
|
|
|
|
def f(*args, **kwargs):
|
|
|
|
return _construct_result(func(*args, **kwargs))
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2013-03-03 17:40:35 +01:00
|
|
|
def _log_print():
|
|
|
|
import sys
|
|
|
|
for entry in _log:
|
|
|
|
sys.stdout.write(repr(entry) + '\n')
|
|
|
|
|
|
|
|
|
2014-08-02 16:22:45 +02:00
|
|
|
_current_group = None
|
|
|
|
_on_wipeout = []
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def command(cmd):
|
2014-08-02 16:22:45 +02:00
|
|
|
global _current_group
|
|
|
|
cmd = cmd.lstrip()
|
2013-02-24 11:03:14 +01:00
|
|
|
if cmd.startswith('let g:'):
|
|
|
|
import re
|
|
|
|
varname, value = re.compile(r'^let g:(\w+)\s*=\s*(.*)').match(cmd).groups()
|
2013-05-19 10:14:06 +02:00
|
|
|
vars[varname] = value
|
2013-02-24 11:03:14 +01:00
|
|
|
elif cmd.startswith('hi '):
|
|
|
|
sp = cmd.split()
|
|
|
|
_highlights[sp[1]] = sp[2:]
|
2013-08-20 16:48:49 +02:00
|
|
|
elif cmd.startswith('function! Powerline_plugin_ctrlp'):
|
|
|
|
# Ignore CtrlP updating functions
|
|
|
|
pass
|
2014-08-02 16:22:45 +02:00
|
|
|
elif cmd.startswith('augroup'):
|
|
|
|
augroup = cmd.partition(' ')[2]
|
|
|
|
if augroup.upper() == 'END':
|
|
|
|
_current_group = None
|
|
|
|
else:
|
|
|
|
_current_group = augroup
|
|
|
|
elif cmd.startswith('autocmd'):
|
|
|
|
rest = cmd.partition(' ')[2]
|
|
|
|
auevent, rest = rest.partition(' ')[::2]
|
|
|
|
pattern, aucmd = rest.partition(' ')[::2]
|
|
|
|
if auevent != 'BufWipeout' or pattern != '*':
|
|
|
|
raise NotImplementedError
|
|
|
|
import sys
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
if not aucmd.startswith(':python '):
|
|
|
|
raise NotImplementedError
|
|
|
|
else:
|
|
|
|
if not aucmd.startswith(':python3 '):
|
|
|
|
raise NotImplementedError
|
|
|
|
_on_wipeout.append(aucmd.partition(' ')[2])
|
2014-08-10 14:17:22 +02:00
|
|
|
elif cmd.startswith('set '):
|
|
|
|
if cmd.startswith('set statusline='):
|
|
|
|
options['statusline'] = cmd[len('set statusline='):]
|
|
|
|
elif cmd.startswith('set tabline='):
|
|
|
|
options['tabline'] = cmd[len('set tabline='):]
|
|
|
|
else:
|
|
|
|
raise NotImplementedError(cmd)
|
2013-02-24 11:03:14 +01:00
|
|
|
else:
|
2014-08-10 14:17:22 +02:00
|
|
|
raise NotImplementedError(cmd)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2014-07-10 20:54:27 +02:00
|
|
|
@_unicode
|
2013-02-24 11:03:14 +01:00
|
|
|
def eval(expr):
|
|
|
|
if expr.startswith('g:'):
|
2013-05-19 10:14:06 +02:00
|
|
|
return vars[expr[2:]]
|
2014-08-24 11:41:54 +02:00
|
|
|
elif expr.startswith('v:'):
|
|
|
|
return vvars[expr[2:]]
|
2013-02-24 11:03:14 +01:00
|
|
|
elif expr.startswith('&'):
|
2013-05-19 10:14:06 +02:00
|
|
|
return options[expr[1:]]
|
2014-06-25 17:55:20 +02:00
|
|
|
elif expr.startswith('$'):
|
|
|
|
return _environ[expr[1:]]
|
2013-02-24 11:03:14 +01:00
|
|
|
elif expr.startswith('PowerlineRegisterCachePurgerEvent'):
|
|
|
|
_buf_purge_events.add(expr[expr.find('"') + 1:expr.rfind('"') - 1])
|
2014-01-11 08:51:58 +01:00
|
|
|
return '0'
|
2013-08-20 16:48:49 +02:00
|
|
|
elif expr.startswith('exists('):
|
|
|
|
return '0'
|
2014-07-10 20:12:08 +02:00
|
|
|
elif expr.startswith('getwinvar('):
|
|
|
|
import re
|
|
|
|
match = re.match(r'^getwinvar\((\d+), "(\w+)"\)$', expr)
|
|
|
|
if not match:
|
2014-08-03 10:00:05 +02:00
|
|
|
raise NotImplementedError(expr)
|
2014-07-10 20:12:08 +02:00
|
|
|
winnr = int(match.group(1))
|
|
|
|
varname = match.group(2)
|
|
|
|
return _emul_getwinvar(winnr, varname)
|
|
|
|
elif expr.startswith('has_key('):
|
|
|
|
import re
|
|
|
|
match = re.match(r'^has_key\(getwinvar\((\d+), ""\), "(\w+)"\)$', expr)
|
2014-08-03 10:00:05 +02:00
|
|
|
if match:
|
|
|
|
winnr = int(match.group(1))
|
|
|
|
varname = match.group(2)
|
|
|
|
return 0 + (varname in current.tabpage.windows[winnr].vars)
|
|
|
|
else:
|
|
|
|
match = re.match(r'^has_key\(gettabwinvar\((\d+), (\d+), ""\), "(\w+)"\)$', expr)
|
|
|
|
if not match:
|
|
|
|
raise NotImplementedError(expr)
|
|
|
|
tabnr = int(match.group(1))
|
|
|
|
winnr = int(match.group(2))
|
|
|
|
varname = match.group(3)
|
|
|
|
return 0 + (varname in tabpages[tabnr].windows[winnr].vars)
|
2014-01-11 08:51:58 +01:00
|
|
|
elif expr == 'getbufvar("%", "NERDTreeRoot").path.str()':
|
|
|
|
import os
|
2014-08-03 07:07:31 +02:00
|
|
|
assert os.path.basename(current.buffer.name).startswith('NERD_tree_')
|
2014-01-11 08:51:58 +01:00
|
|
|
return '/usr/include'
|
2014-08-03 07:07:31 +02:00
|
|
|
elif expr == 'tabpagenr()':
|
|
|
|
return current.tabpage.number
|
|
|
|
elif expr == 'tabpagenr("$")':
|
|
|
|
return len(tabpages)
|
|
|
|
elif expr.startswith('tabpagewinnr('):
|
|
|
|
tabnr = int(expr[len('tabpagewinnr('):-1])
|
|
|
|
return tabpages[tabnr].window.number
|
|
|
|
elif expr.startswith('tabpagebuflist('):
|
|
|
|
import re
|
|
|
|
match = re.match(r'tabpagebuflist\((\d+)\)\[(\d+)\]', expr)
|
|
|
|
tabnr = int(match.group(1))
|
|
|
|
winnr = int(match.group(2)) + 1
|
|
|
|
return tabpages[tabnr].windows[winnr].buffer.number
|
|
|
|
elif expr.startswith('gettabwinvar('):
|
|
|
|
import re
|
|
|
|
match = re.match(r'gettabwinvar\((\d+), (\d+), "(\w+)"\)', expr)
|
|
|
|
tabnr = int(match.group(1))
|
|
|
|
winnr = int(match.group(2))
|
|
|
|
varname = match.group(3)
|
|
|
|
return tabpages[tabnr].windows[winnr].vars[varname]
|
|
|
|
raise NotImplementedError(expr)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def bindeval(expr):
|
|
|
|
if expr == 'g:':
|
2013-05-19 10:14:06 +02:00
|
|
|
return vars
|
2013-05-23 16:22:49 +02:00
|
|
|
elif expr == '{}':
|
|
|
|
return {}
|
|
|
|
elif expr == '[]':
|
|
|
|
return []
|
2013-02-24 11:03:14 +01:00
|
|
|
import re
|
|
|
|
match = re.compile(r'^function\("([^"\\]+)"\)$').match(expr)
|
|
|
|
if match:
|
|
|
|
return globals()['_emul_' + match.group(1)]
|
|
|
|
else:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-24 02:45:52 +01:00
|
|
|
@_str_func
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_mode(*args):
|
|
|
|
if args and args[0]:
|
|
|
|
return _mode
|
|
|
|
else:
|
|
|
|
return _mode[0]
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-24 02:45:52 +01:00
|
|
|
@_str_func
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_getbufvar(bufnr, varname):
|
2014-01-11 08:51:58 +01:00
|
|
|
import re
|
2013-02-24 11:03:14 +01:00
|
|
|
if varname[0] == '&':
|
2013-04-13 17:28:19 +02:00
|
|
|
if bufnr == '%':
|
2014-08-03 07:07:31 +02:00
|
|
|
bufnr = current.buffer.number
|
2013-04-03 23:44:28 +02:00
|
|
|
if bufnr not in buffers:
|
2013-02-24 11:03:14 +01:00
|
|
|
return ''
|
|
|
|
try:
|
2013-05-19 10:14:06 +02:00
|
|
|
return buffers[bufnr].options[varname[1:]]
|
2013-02-24 11:03:14 +01:00
|
|
|
except KeyError:
|
|
|
|
try:
|
2013-05-19 10:14:06 +02:00
|
|
|
return options[varname[1:]]
|
2013-02-24 11:03:14 +01:00
|
|
|
except KeyError:
|
|
|
|
return ''
|
2014-01-11 08:51:58 +01:00
|
|
|
elif re.match('^[a-zA-Z_]+$', varname):
|
|
|
|
if bufnr == '%':
|
2014-08-03 07:07:31 +02:00
|
|
|
bufnr = current.buffer.number
|
2014-01-11 08:51:58 +01:00
|
|
|
if bufnr not in buffers:
|
|
|
|
return ''
|
|
|
|
return buffers[bufnr].vars[varname]
|
2013-02-24 11:03:14 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-24 02:45:52 +01:00
|
|
|
@_str_func
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_getwinvar(winnr, varname):
|
2014-08-03 07:07:31 +02:00
|
|
|
return current.tabpage.windows[winnr].vars.get(varname, '')
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_setwinvar(winnr, varname, value):
|
2014-08-03 07:07:31 +02:00
|
|
|
current.tabpage.windows[winnr].vars[varname] = value
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_virtcol(expr):
|
2014-08-05 20:49:53 +02:00
|
|
|
if expr == '.':
|
2014-08-03 07:07:31 +02:00
|
|
|
return current.window.cursor[1] + 1
|
2014-08-05 20:49:53 +02:00
|
|
|
if isinstance(expr, list) and len(expr) == 3:
|
|
|
|
return expr[-2] + expr[-1]
|
2013-02-24 11:03:14 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2014-08-05 20:49:53 +02:00
|
|
|
_v_pos = None
|
|
|
|
|
|
|
|
|
2013-08-06 10:34:14 +02:00
|
|
|
@_vim
|
|
|
|
def _emul_getpos(expr):
|
2014-08-05 20:49:53 +02:00
|
|
|
if expr == '.':
|
2014-08-03 07:07:31 +02:00
|
|
|
return [0, current.window.cursor[0] + 1, current.window.cursor[1] + 1, 0]
|
2014-08-05 20:49:53 +02:00
|
|
|
if expr == 'v':
|
|
|
|
return _v_pos or [0, current.window.cursor[0] + 1, current.window.cursor[1] + 1, 0]
|
2013-08-06 10:34:14 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-24 02:45:52 +01:00
|
|
|
@_str_func
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_fnamemodify(path, modstring):
|
|
|
|
import os
|
|
|
|
_modifiers = {
|
2013-12-01 16:25:19 +01:00
|
|
|
'~': lambda path: path.replace(os.environ['HOME'].encode('utf-8'), b'~') if path.startswith(os.environ['HOME'].encode('utf-8')) else path,
|
|
|
|
'.': lambda path: (lambda tpath: path if tpath[:3] == b'..' + os.sep.encode() else tpath)(os.path.relpath(path)),
|
2013-02-24 11:03:14 +01:00
|
|
|
't': lambda path: os.path.basename(path),
|
|
|
|
'h': lambda path: os.path.dirname(path),
|
|
|
|
}
|
|
|
|
|
|
|
|
for mods in modstring.split(':')[1:]:
|
|
|
|
path = _modifiers[mods](path)
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-24 02:45:52 +01:00
|
|
|
@_str_func
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_expand(expr):
|
2014-08-02 16:22:45 +02:00
|
|
|
global _abuf
|
2013-02-24 11:03:14 +01:00
|
|
|
if expr == '<abuf>':
|
2014-08-03 07:07:31 +02:00
|
|
|
return _abuf or current.buffer.number
|
2013-02-24 11:03:14 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_bufnr(expr):
|
|
|
|
if expr == '$':
|
|
|
|
return _last_bufnr
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _emul_exists(varname):
|
|
|
|
if varname.startswith('g:'):
|
2013-05-19 10:14:06 +02:00
|
|
|
return varname[2:] in vars
|
2013-02-24 11:03:14 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-03-14 19:38:40 +01:00
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-13 16:49:53 +01:00
|
|
|
def _emul_line2byte(line):
|
2014-08-03 07:07:31 +02:00
|
|
|
buflines = current.buffer._buf_lines
|
2013-03-13 16:49:53 +01:00
|
|
|
if line == len(buflines) + 1:
|
|
|
|
return sum((len(s) for s in buflines)) + 1
|
|
|
|
raise NotImplementedError
|
2013-02-24 11:03:14 +01:00
|
|
|
|
2013-05-19 10:14:06 +02:00
|
|
|
|
2014-01-21 15:48:05 +01:00
|
|
|
@_vim
|
|
|
|
def _emul_line(expr):
|
2014-08-03 07:07:31 +02:00
|
|
|
cursorline = current.window.cursor[0] + 1
|
|
|
|
numlines = len(current.buffer._buf_lines)
|
2014-01-21 15:48:05 +01:00
|
|
|
if expr == 'w0':
|
2014-02-26 05:49:25 +01:00
|
|
|
return max(cursorline - 5, 1)
|
2014-01-21 15:48:05 +01:00
|
|
|
if expr == 'w$':
|
2014-02-26 05:49:25 +01:00
|
|
|
return min(cursorline + 5, numlines)
|
2014-01-21 15:48:05 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2013-12-01 16:25:19 +01:00
|
|
|
@_vim
|
|
|
|
@_str_func
|
|
|
|
def _emul_strtrans(s):
|
|
|
|
# FIXME Do more replaces
|
|
|
|
return s.replace(b'\xFF', b'<ff>')
|
|
|
|
|
|
|
|
|
|
|
|
@_vim
|
|
|
|
@_str_func
|
|
|
|
def _emul_bufname(bufnr):
|
|
|
|
try:
|
|
|
|
return buffers[bufnr]._name or b''
|
|
|
|
except KeyError:
|
|
|
|
return b''
|
|
|
|
|
|
|
|
|
2013-02-24 11:03:14 +01:00
|
|
|
_window_id = 0
|
|
|
|
|
|
|
|
|
|
|
|
class _Window(object):
|
2014-08-03 07:07:31 +02:00
|
|
|
def __init__(self, number, buffer=None, cursor=(1, 0), width=80):
|
2013-02-24 11:03:14 +01:00
|
|
|
global _window_id
|
|
|
|
self.cursor = cursor
|
|
|
|
self.width = width
|
2014-08-03 07:07:31 +02:00
|
|
|
self.number = number
|
2013-02-24 11:03:14 +01:00
|
|
|
if buffer:
|
|
|
|
if type(buffer) is _Buffer:
|
|
|
|
self.buffer = buffer
|
|
|
|
else:
|
|
|
|
self.buffer = _Buffer(**buffer)
|
|
|
|
else:
|
|
|
|
self.buffer = _Buffer()
|
|
|
|
_window_id += 1
|
2014-08-03 07:07:31 +02:00
|
|
|
self._window_id = _window_id
|
2013-05-19 10:14:06 +02:00
|
|
|
self.options = {}
|
2014-08-03 07:07:31 +02:00
|
|
|
self.vars = {
|
|
|
|
'powerline_window_id': self._window_id,
|
|
|
|
}
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
2014-07-10 20:26:14 +02:00
|
|
|
return '<window ' + str(self.number - 1) + '>'
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
class _Tabpage(object):
|
|
|
|
def __init__(self, number):
|
|
|
|
self.windows = _ObjList(_Window)
|
|
|
|
self.number = number
|
|
|
|
|
|
|
|
def _new_window(self, **kwargs):
|
|
|
|
self.window = self.windows._new(**kwargs)
|
|
|
|
return self.window
|
|
|
|
|
2014-08-03 10:43:41 +02:00
|
|
|
def _close_window(self, winnr, open_window=True):
|
2014-08-03 07:07:31 +02:00
|
|
|
curwinnr = self.window.number
|
2014-08-03 10:43:41 +02:00
|
|
|
win = self.windows._pop(winnr)
|
2014-08-03 07:07:31 +02:00
|
|
|
if self.windows and winnr == curwinnr:
|
|
|
|
self.window = self.windows[-1]
|
2014-08-03 10:43:41 +02:00
|
|
|
elif open_window:
|
2014-08-03 07:07:31 +02:00
|
|
|
current.tabpage._new_window()
|
|
|
|
return win
|
|
|
|
|
2014-08-03 10:43:41 +02:00
|
|
|
def _close(self):
|
2014-08-10 14:17:22 +02:00
|
|
|
global _tabpage
|
2014-08-03 10:43:41 +02:00
|
|
|
while self.windows:
|
|
|
|
self._close_window(1, False)
|
|
|
|
tabpages._pop(self.number)
|
|
|
|
_tabpage = len(tabpages)
|
|
|
|
|
2014-08-03 07:07:31 +02:00
|
|
|
|
|
|
|
tabpages = _ObjList(_Tabpage)
|
|
|
|
|
|
|
|
|
2014-08-02 16:22:45 +02:00
|
|
|
_abuf = None
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class _Buffer(object):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
global _last_bufnr
|
|
|
|
_last_bufnr += 1
|
|
|
|
bufnr = _last_bufnr
|
|
|
|
self.number = bufnr
|
2013-12-01 16:25:19 +01:00
|
|
|
# FIXME Use unicode() for python-3
|
|
|
|
self.name = name
|
2014-08-02 16:22:45 +02:00
|
|
|
self.vars = {'changedtick': 1}
|
2013-05-19 10:14:06 +02:00
|
|
|
self.options = {
|
2013-04-13 17:21:11 +02:00
|
|
|
'modified': 0,
|
|
|
|
'readonly': 0,
|
|
|
|
'fileformat': 'unix',
|
|
|
|
'filetype': '',
|
|
|
|
'buftype': '',
|
|
|
|
'fileencoding': 'utf-8',
|
2013-04-13 17:28:19 +02:00
|
|
|
'textwidth': 80,
|
2013-04-13 17:21:11 +02:00
|
|
|
}
|
2014-08-03 07:07:31 +02:00
|
|
|
self._buf_lines = ['']
|
|
|
|
self._undostate = [self._buf_lines[:]]
|
|
|
|
self._undo_written = len(self._undostate)
|
2013-02-24 11:03:14 +01:00
|
|
|
buffers[bufnr] = self
|
|
|
|
|
2013-12-01 16:25:19 +01:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
import sys
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
return self._name
|
|
|
|
else:
|
|
|
|
return str(self._name, 'utf-8') if self._name else None
|
|
|
|
|
|
|
|
@name.setter
|
|
|
|
def name(self, name):
|
|
|
|
if name is None:
|
|
|
|
self._name = None
|
|
|
|
else:
|
|
|
|
import os
|
|
|
|
if type(name) is not bytes:
|
|
|
|
name = name.encode('utf-8')
|
2014-08-10 14:17:22 +02:00
|
|
|
if b':/' in name:
|
2014-08-03 21:58:34 +02:00
|
|
|
self._name = name
|
|
|
|
else:
|
|
|
|
self._name = os.path.abspath(name)
|
2013-12-01 16:25:19 +01:00
|
|
|
|
2013-02-24 11:03:14 +01:00
|
|
|
def __getitem__(self, line):
|
2014-08-03 07:07:31 +02:00
|
|
|
return self._buf_lines[line]
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __setitem__(self, line, value):
|
2013-05-19 10:14:06 +02:00
|
|
|
self.options['modified'] = 1
|
2014-08-02 16:22:45 +02:00
|
|
|
self.vars['changedtick'] += 1
|
2014-08-03 07:07:31 +02:00
|
|
|
self._buf_lines[line] = value
|
2013-02-24 11:03:14 +01:00
|
|
|
from copy import copy
|
2014-08-03 07:07:31 +02:00
|
|
|
self._undostate.append(copy(self._buf_lines))
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __setslice__(self, *args):
|
2013-05-19 10:14:06 +02:00
|
|
|
self.options['modified'] = 1
|
2014-08-02 16:22:45 +02:00
|
|
|
self.vars['changedtick'] += 1
|
2014-08-03 07:07:31 +02:00
|
|
|
self._buf_lines.__setslice__(*args)
|
2013-02-24 11:03:14 +01:00
|
|
|
from copy import copy
|
2014-08-03 07:07:31 +02:00
|
|
|
self._undostate.append(copy(self._buf_lines))
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __getslice__(self, *args):
|
2014-08-03 07:07:31 +02:00
|
|
|
return self._buf_lines.__getslice__(*args)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __len__(self):
|
2014-08-03 07:07:31 +02:00
|
|
|
return len(self._buf_lines)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<buffer ' + str(self.name) + '>'
|
|
|
|
|
|
|
|
def __del__(self):
|
2014-08-02 16:22:45 +02:00
|
|
|
global _abuf
|
2013-02-24 11:03:14 +01:00
|
|
|
bufnr = self.number
|
2014-08-02 16:22:45 +02:00
|
|
|
try:
|
|
|
|
import __main__
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
except RuntimeError:
|
|
|
|
# Module may have already been garbage-collected
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if _on_wipeout:
|
|
|
|
_abuf = bufnr
|
|
|
|
try:
|
|
|
|
for event in _on_wipeout:
|
|
|
|
exec(event, __main__.__dict__)
|
|
|
|
finally:
|
|
|
|
_abuf = None
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-03-13 16:49:53 +01:00
|
|
|
class _Current(object):
|
|
|
|
@property
|
|
|
|
def buffer(self):
|
2014-08-03 07:07:31 +02:00
|
|
|
return self.window.buffer
|
2013-03-13 16:49:53 +01:00
|
|
|
|
2013-05-17 06:51:33 +02:00
|
|
|
@property
|
|
|
|
def window(self):
|
2014-08-03 07:07:31 +02:00
|
|
|
return self.tabpage.window
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tabpage(self):
|
|
|
|
return tabpages[_tabpage - 1]
|
2013-05-17 06:51:33 +02:00
|
|
|
|
2013-03-13 16:49:53 +01:00
|
|
|
|
|
|
|
current = _Current()
|
|
|
|
|
|
|
|
|
2013-03-02 16:05:08 +01:00
|
|
|
_dict = None
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-02 16:05:08 +01:00
|
|
|
def _init():
|
|
|
|
global _dict
|
2013-02-24 11:03:14 +01:00
|
|
|
|
2013-03-02 16:05:08 +01:00
|
|
|
if _dict:
|
|
|
|
return _dict
|
2013-02-24 11:03:14 +01:00
|
|
|
|
2013-03-02 16:05:08 +01:00
|
|
|
_dict = {}
|
2013-02-24 11:03:14 +01:00
|
|
|
for varname, value in globals().items():
|
|
|
|
if varname[0] != '_':
|
2013-03-02 16:05:08 +01:00
|
|
|
_dict[varname] = value
|
2014-08-03 07:07:31 +02:00
|
|
|
_tabnew()
|
2013-03-02 16:05:08 +01:00
|
|
|
return _dict
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _get_segment_info():
|
|
|
|
mode_translations = {
|
2013-04-13 17:21:11 +02:00
|
|
|
chr(ord('V') - 0x40): '^V',
|
|
|
|
chr(ord('S') - 0x40): '^S',
|
|
|
|
}
|
2013-02-24 11:03:14 +01:00
|
|
|
mode = _mode
|
|
|
|
mode = mode_translations.get(mode, mode)
|
2014-08-03 07:07:31 +02:00
|
|
|
window = current.window
|
|
|
|
buffer = current.buffer
|
2014-08-03 10:05:03 +02:00
|
|
|
tabpage = current.tabpage
|
2013-02-24 11:03:14 +01:00
|
|
|
return {
|
2014-08-03 07:07:31 +02:00
|
|
|
'window': window,
|
|
|
|
'winnr': window.number,
|
|
|
|
'buffer': buffer,
|
|
|
|
'bufnr': buffer.number,
|
2014-08-03 10:05:03 +02:00
|
|
|
'tabpage': tabpage,
|
|
|
|
'tabnr': tabpage.number,
|
2014-08-03 07:07:31 +02:00
|
|
|
'window_id': window._window_id,
|
2013-02-24 11:03:14 +01:00
|
|
|
'mode': mode,
|
2014-09-14 11:45:19 +02:00
|
|
|
'encoding': options['encoding'],
|
2013-02-24 11:03:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _launch_event(event):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _start_mode(mode):
|
|
|
|
global _mode
|
|
|
|
if mode == 'i':
|
|
|
|
_launch_event('InsertEnter')
|
|
|
|
elif _mode == 'i':
|
|
|
|
_launch_event('InsertLeave')
|
|
|
|
_mode = mode
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _undo():
|
2014-08-03 07:07:31 +02:00
|
|
|
if len(current.buffer._undostate) == 1:
|
2013-02-24 11:03:14 +01:00
|
|
|
return
|
2014-08-03 07:07:31 +02:00
|
|
|
buffer = current.buffer
|
|
|
|
buffer._undostate.pop(-1)
|
|
|
|
buffer._buf_lines = buffer._undostate[-1]
|
|
|
|
if buffer._undo_written == len(buffer._undostate):
|
|
|
|
buffer.options['modified'] = 0
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _edit(name=None):
|
2014-08-03 07:07:31 +02:00
|
|
|
if current.buffer.name is None:
|
|
|
|
buffer = current.buffer
|
|
|
|
buffer.name = name
|
2013-02-24 11:03:14 +01:00
|
|
|
else:
|
2014-08-03 07:07:31 +02:00
|
|
|
buffer = _Buffer(name)
|
|
|
|
current.window.buffer = buffer
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def _tabnew(name=None):
|
|
|
|
global windows
|
2014-08-10 14:17:22 +02:00
|
|
|
global _tabpage
|
2014-08-03 07:07:31 +02:00
|
|
|
tabpage = tabpages._new()
|
|
|
|
windows = tabpage.windows
|
|
|
|
_tabpage = len(tabpages)
|
|
|
|
_new(name)
|
2014-08-03 10:43:41 +02:00
|
|
|
return tabpage
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-05-17 06:51:33 +02:00
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def _new(name=None):
|
|
|
|
current.tabpage._new_window(buffer={'name': name})
|
2013-05-17 06:51:33 +02:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2014-08-03 07:07:31 +02:00
|
|
|
def _split():
|
|
|
|
current.tabpage._new_window(buffer=current.buffer)
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _close(winnr, wipe=True):
|
2014-08-03 07:07:31 +02:00
|
|
|
win = current.tabpage._close_window(winnr)
|
2013-02-24 11:03:14 +01:00
|
|
|
if wipe:
|
2014-08-03 07:07:31 +02:00
|
|
|
for w in current.tabpage.windows:
|
2013-02-24 11:03:14 +01:00
|
|
|
if w.buffer.number == win.buffer.number:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
_bw(win.buffer.number)
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _bw(bufnr=None):
|
2014-08-03 07:07:31 +02:00
|
|
|
bufnr = bufnr or current.buffer.number
|
2013-02-24 11:03:14 +01:00
|
|
|
winnr = 1
|
2014-08-03 07:07:31 +02:00
|
|
|
for win in current.tabpage.windows:
|
2013-02-24 11:03:14 +01:00
|
|
|
if win.buffer.number == bufnr:
|
|
|
|
_close(winnr, wipe=False)
|
|
|
|
winnr += 1
|
2014-08-03 07:07:31 +02:00
|
|
|
buffers._pop(bufnr)
|
2013-02-24 11:03:14 +01:00
|
|
|
if not buffers:
|
|
|
|
_Buffer()
|
2014-08-03 07:07:31 +02:00
|
|
|
_b(max(buffers._keys()))
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _b(bufnr):
|
2014-08-03 07:07:31 +02:00
|
|
|
current.window.buffer = buffers[bufnr]
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _set_cursor(line, col):
|
2014-08-03 07:07:31 +02:00
|
|
|
current.window.cursor = (line, col)
|
2013-02-24 11:03:14 +01:00
|
|
|
if _mode == 'n':
|
|
|
|
_launch_event('CursorMoved')
|
|
|
|
elif _mode == 'i':
|
|
|
|
_launch_event('CursorMovedI')
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _get_buffer():
|
2014-08-03 07:07:31 +02:00
|
|
|
return current.buffer
|
2013-02-24 11:03:14 +01:00
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-02-24 11:03:14 +01:00
|
|
|
def _set_bufoption(option, value, bufnr=None):
|
2014-08-03 07:07:31 +02:00
|
|
|
buffers[bufnr or current.buffer.number].options[option] = value
|
2013-03-02 21:02:07 +01:00
|
|
|
if option == 'filetype':
|
|
|
|
_launch_event('FileType')
|
|
|
|
|
|
|
|
|
|
|
|
class _WithNewBuffer(object):
|
|
|
|
def __init__(self, func, *args, **kwargs):
|
|
|
|
self.call = lambda: func(*args, **kwargs)
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.call()
|
2014-08-03 07:07:31 +02:00
|
|
|
self.bufnr = current.buffer.number
|
2013-03-02 21:02:07 +01:00
|
|
|
return _get_segment_info()
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
_bw(self.bufnr)
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-02 21:02:07 +01:00
|
|
|
def _set_dict(d, new, setfunc=None):
|
|
|
|
if not setfunc:
|
|
|
|
def setfunc(k, v):
|
|
|
|
d[k] = v
|
|
|
|
|
|
|
|
old = {}
|
|
|
|
na = []
|
|
|
|
for k, v in new.items():
|
|
|
|
try:
|
|
|
|
old[k] = d[k]
|
|
|
|
except KeyError:
|
|
|
|
na.append(k)
|
|
|
|
setfunc(k, v)
|
|
|
|
return old, na
|
|
|
|
|
|
|
|
|
|
|
|
class _WithBufOption(object):
|
|
|
|
def __init__(self, **new):
|
|
|
|
self.new = new
|
|
|
|
|
|
|
|
def __enter__(self):
|
2014-08-03 07:07:31 +02:00
|
|
|
self.buffer = current.buffer
|
2013-05-19 10:14:06 +02:00
|
|
|
self.old = _set_dict(self.buffer.options, self.new, _set_bufoption)[0]
|
2013-03-02 21:02:07 +01:00
|
|
|
|
|
|
|
def __exit__(self, *args):
|
2013-05-19 10:14:06 +02:00
|
|
|
self.buffer.options.update(self.old)
|
2013-03-02 21:02:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class _WithMode(object):
|
|
|
|
def __init__(self, new):
|
|
|
|
self.new = new
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.old = _mode
|
|
|
|
_start_mode(self.new)
|
|
|
|
return _get_segment_info()
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
_start_mode(self.old)
|
|
|
|
|
|
|
|
|
|
|
|
class _WithDict(object):
|
|
|
|
def __init__(self, d, **new):
|
|
|
|
self.new = new
|
|
|
|
self.d = d
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.old, self.na = _set_dict(self.d, self.new)
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
self.d.update(self.old)
|
|
|
|
for k in self.na:
|
|
|
|
self.d.pop(k)
|
|
|
|
|
|
|
|
|
2013-05-17 06:51:33 +02:00
|
|
|
class _WithSplit(object):
|
|
|
|
def __enter__(self):
|
|
|
|
_split()
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
_close(2, wipe=False)
|
|
|
|
|
|
|
|
|
|
|
|
class _WithBufName(object):
|
|
|
|
def __init__(self, new):
|
|
|
|
self.new = new
|
|
|
|
|
|
|
|
def __enter__(self):
|
2014-01-11 08:51:58 +01:00
|
|
|
import os
|
2014-08-03 07:07:31 +02:00
|
|
|
buffer = current.buffer
|
2013-05-17 06:51:33 +02:00
|
|
|
self.buffer = buffer
|
|
|
|
self.old = buffer.name
|
|
|
|
buffer.name = self.new
|
2014-01-11 08:51:58 +01:00
|
|
|
if buffer.name and os.path.basename(buffer.name) == 'ControlP':
|
|
|
|
buffer.vars['powerline_ctrlp_type'] = 'main'
|
|
|
|
buffer.vars['powerline_ctrlp_args'] = ['focus', 'byfname', '0', 'prev', 'item', 'next', 'marked']
|
2013-05-17 06:51:33 +02:00
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
self.buffer.name = self.old
|
|
|
|
|
|
|
|
|
2014-08-03 10:43:41 +02:00
|
|
|
class _WithNewTabPage(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.args = args
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.tab = _tabnew(*self.args, **self.kwargs)
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
self.tab._close()
|
|
|
|
|
|
|
|
|
2014-08-05 20:49:53 +02:00
|
|
|
class _WithGlobal(object):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.empty = object()
|
|
|
|
self.old = dict(((key, globals().get(key, self.empty)) for key in self.kwargs))
|
|
|
|
globals().update(self.kwargs)
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
for k, v in self.old.items():
|
|
|
|
if v is self.empty:
|
|
|
|
globals().pop(k, None)
|
|
|
|
else:
|
|
|
|
globals()[k] = v
|
|
|
|
|
|
|
|
|
2013-04-03 23:44:28 +02:00
|
|
|
@_vim
|
2013-03-02 21:02:07 +01:00
|
|
|
def _with(key, *args, **kwargs):
|
|
|
|
if key == 'buffer':
|
|
|
|
return _WithNewBuffer(_edit, *args, **kwargs)
|
2013-05-17 06:51:33 +02:00
|
|
|
elif key == 'bufname':
|
|
|
|
return _WithBufName(*args, **kwargs)
|
2013-03-02 21:02:07 +01:00
|
|
|
elif key == 'mode':
|
|
|
|
return _WithMode(*args, **kwargs)
|
|
|
|
elif key == 'bufoptions':
|
|
|
|
return _WithBufOption(**kwargs)
|
|
|
|
elif key == 'options':
|
2013-05-19 10:14:06 +02:00
|
|
|
return _WithDict(options, **kwargs)
|
2013-03-02 21:02:07 +01:00
|
|
|
elif key == 'globals':
|
2013-05-19 10:14:06 +02:00
|
|
|
return _WithDict(vars, **kwargs)
|
2014-07-10 20:21:29 +02:00
|
|
|
elif key == 'wvars':
|
2014-08-03 07:07:31 +02:00
|
|
|
return _WithDict(current.window.vars, **kwargs)
|
2014-06-25 17:55:20 +02:00
|
|
|
elif key == 'environ':
|
|
|
|
return _WithDict(_environ, **kwargs)
|
2013-05-17 06:51:33 +02:00
|
|
|
elif key == 'split':
|
|
|
|
return _WithSplit()
|
2014-08-03 10:43:41 +02:00
|
|
|
elif key == 'tabpage':
|
|
|
|
return _WithNewTabPage(*args, **kwargs)
|
2014-08-05 20:49:53 +02:00
|
|
|
elif key == 'vpos':
|
|
|
|
return _WithGlobal(_v_pos=[0, kwargs['line'], kwargs['col'], kwargs['off']])
|
2013-12-01 16:25:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
class error(Exception):
|
|
|
|
pass
|