Add basic ncm2 support

This commit is contained in:
Yuri Bochkarev
2018-07-17 18:12:36 +03:00
parent 47fb962592
commit d0009db3a9
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
if get(s:, 'loaded', 0)
finish
endif
let s:loaded = 1
let g:ncm2_tmux_complete_enabled = get(g:, 'ncm2_tmux_complete_enabled', 1)
let g:ncm2_tmux_complete#proc = yarp#py3('ncm2_tmux_complete')
let g:ncm2_tmux_complete#source = get(g:, 'ncm2_tmux_complete#source', {
\ 'name': 'tmux',
\ 'priority': 4,
\ 'mark': 'tmux',
\ 'on_complete': 'ncm2_tmux_complete#on_complete',
\ 'on_warmup': 'ncm2_tmux_complete#on_warmup'
\ })
let g:ncm2_tmux_complete#source = extend(g:ncm2_tmux_complete#source,
\ get(g:, 'ncm2_tmux_complete#source_override', {}),
\ 'force')
function! ncm2_tmux_complete#init()
call ncm2#register_source(g:ncm2_tmux_complete#source)
endfunction
function! ncm2_tmux_complete#on_warmup(ctx)
call g:ncm2_tmux_complete#proc.jobstart()
endfunction
function! ncm2_tmux_complete#on_complete(ctx)
let s:is_enabled = get(b:, 'ncm2_tmux_complete_enabled',
\ get(g:, 'ncm2_tmux_complete_enabled', 1))
if ! s:is_enabled
return
endif
call g:ncm2_tmux_complete#proc.try_notify('on_complete', a:ctx)
endfunction

View File

@@ -0,0 +1 @@
call ncm2_tmux_complete#init()

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
import vim
from ncm2 import Ncm2Source, getLogger
from subprocess import check_output
logger = getLogger(__name__)
class Source(Ncm2Source):
def __init__(self, nvim):
super(Source, self).__init__(nvim)
def on_complete(self, ctx):
command = vim.call('tmuxcomplete#getcommand', '', 'words')
words = check_output(['sh', '-c', command]
).decode('utf-8').splitlines()
matches = [{'word': x} for x in words]
self.complete(ctx, ctx['startccol'], matches)
source = Source(vim)
on_complete = source.on_complete