Skip to content

Commit

Permalink
Version 0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Jun 4, 2015
1 parent 45402be commit 3eb9a4c
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 96 deletions.
43 changes: 43 additions & 0 deletions README.md
@@ -0,0 +1,43 @@
deoplete
========

Deoplete is the abbreviation of "dark powered neo-completion". It
provides asynchronous keyword completion system in the
current buffer. Deoplete cannot be customized and has not many
features currently. It is provided for testing purpose.

**Note:** It is still alpha version! It is not for production use.

## Installation

**Note:** deoplete requires Neovim(latest is recommended) with Python3 enabled.
See [requirements](#requirements) if you aren't sure whether you have this.

1. Extract the files and put them in your Neovim directory
(usually `~/.nvim/`).
2. Execute the `:UpdateRemotePlugins` and restart Neovim.
3. Execute the `:DeopleteEnable` command or set `let g:deoplete#enable_at_startup = 1`
in your `.nvimrc`

## Requirements

deoplete requires Neovim with if\_python3.
If `:echo has("python3")` returns `1`, then you're done; otherwise, see below.

You can enable Python3 interface with pip:

sudo pip3 install neovim

If you want to read for Neovim-python/python3 interface install documentation,
you should read `:help nvim-python`.

## Screenshots

Nothing...

## Configuration Examples

```vim
" Use deoplete.
let g:deoplete#enable_at_startup = 1
```
2 changes: 1 addition & 1 deletion autoload/deoplete/mappings.vim
Expand Up @@ -30,7 +30,7 @@ function! deoplete#mappings#_init() abort "{{{
endfunction"}}}

function! deoplete#mappings#_do_auto_complete(context) abort "{{{
if b:changedtick == a:context.changedtick
if b:changedtick == get(a:context, 'changedtick', -1)
call complete(match(
\ deoplete#helpers#get_input('TextChangedI'), '\h\w*$') + 1,
\ a:context.candidates)
Expand Down
Empty file removed python3/deoplete/__init__.py
Empty file.
82 changes: 0 additions & 82 deletions rplugin/python3/deoplete.py
@@ -1,82 +0,0 @@
#=============================================================================
# FILE: deoplete.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license {{{
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# }}}
#=============================================================================

import neovim
import re

class Buffer(object):
def __init__(self):
pass

def get_complete_position(self, vim, context):
m = re.search(context.input, r'[a-zA-Z_][a-zA-Z0-9_]')
if m:
return m.start()
else:
return -1

def gather_candidates(self, vim, context):
candidates = []
p = re.compile('[a-zA-Z_]\w*')

for l in vim.current.buffer:
candidates += p.findall(l)
return candidates

class Deoplete(object):
def __init__(self, base_dir):
self.base_dir = base_dir
def gather_candidates(self, vim, context):
buffer = Buffer()
return buffer.gather_candidates(vim, {})

@neovim.plugin
class DeopleteHandlers(object):
def __init__(self, vim):
self.vim = vim

@neovim.command('DeopleteInitializePython', sync=True, nargs=1)
def init_python(self, base_dir):
self.deoplete = Deoplete(base_dir)
self.vim.command('let g:deoplete#_channel_id = '
+ str(self.vim.channel_id))

@neovim.rpc_export('completion_begin')
def completion_begin(self, context):
candidates = self.deoplete.gather_candidates(self.vim, context)
if not candidates:
return
self.vim.command(
'let g:deoplete#_context = {}')
self.vim.command(
'let g:deoplete#_context.complete_position = 0')
self.vim.command(
'let g:deoplete#_context.changedtick = '
+ str(context[b'changedtick']))
self.vim.command(
'let g:deoplete#_context.candidates = ' + str(candidates))
self.vim.command(
'call feedkeys("\<Plug>(deoplete_start_auto_complete)")')

56 changes: 56 additions & 0 deletions rplugin/python3/deoplete/__init__.py
@@ -0,0 +1,56 @@
#=============================================================================
# FILE: __init__.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license {{{
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# }}}
#=============================================================================

import neovim
from .deoplete import Deoplete

@neovim.plugin
class DeopleteHandlers(object):
def __init__(self, vim):
self.vim = vim

@neovim.command('DeopleteInitializePython', sync=True, nargs=1)
def init_python(self, base_dir):
self.deoplete = Deoplete(base_dir)
self.vim.command('let g:deoplete#_channel_id = '
+ str(self.vim.channel_id))

@neovim.rpc_export('completion_begin')
def completion_begin(self, context):
candidates = self.deoplete.gather_candidates(self.vim, context)
if not candidates:
return
self.vim.command(
'let g:deoplete#_context = {}')
self.vim.command(
'let g:deoplete#_context.complete_position = 0')
self.vim.command(
'let g:deoplete#_context.changedtick = '
+ str(context[b'changedtick']))
self.vim.command(
'let g:deoplete#_context.candidates = ' + str(candidates))
self.vim.command(
'call feedkeys("\<Plug>(deoplete_start_auto_complete)")')

59 changes: 59 additions & 0 deletions rplugin/python3/deoplete/deoplete.py
@@ -0,0 +1,59 @@
#=============================================================================
# FILE: deoplete.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license {{{
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# }}}
#=============================================================================

import neovim
import importlib
from .sources.buffer import Buffer
# from .filters.matcher_head import Filter
from .filters.matcher_fuzzy import Filter

class Deoplete(object):
def __init__(self, base_dir):
self.base_dir = base_dir
def gather_candidates(self, vim, context):
# Skip completion
if vim.eval('&l:completefunc') != '' \
and vim.eval('&l:buftype').find('nofile') >= 0:
return []

# Encoding conversion
encoding = vim.eval('&encoding')
context = { k.decode(encoding) :
(v.decode(encoding) if isinstance(v, bytes) else v)
for k, v in context.items()}
# debug(vim, context)

if context['complete_str'] == '':
return []

buffer = Buffer()
context['candidates'] = buffer.gather_candidates(vim, context)

filter = Filter()
context['candidates'] = filter.filter(vim, context)
return context['candidates']

def debug(vim, msg):
vim.command('echomsg string(' + str(msg) + ')')
@@ -1,5 +1,5 @@
#=============================================================================
# FILE: deoplete.py
# FILE: matcher_fuzzy.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license {{{
# Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -23,13 +23,25 @@
# }}}
#=============================================================================

import neovim
import deoplete.sources.buffer
import re

class Deoplete(object):
def __init__(self, base_dir):
self.base_dir = base_dir
def gather_candidates(self, vim, context):
buffer = deoplete.sources.buffer.Buffer()
return buffer.gather_candidates(vim, {})
class Filter(object):
def __init__(self):
pass

def filter(self, vim, context):
p = re.compile(fuzzy_escape(context['complete_str']))
# debug(vim, fuzzy_escape(context['complete_str']))
return [x for x in context['candidates'] if p.match(x)]

def fuzzy_escape(string):
# Escape string for python regexp.
string = re.sub(r'([a-zA-Z0-9_])', r'\1.*', escape(string))
return string

def escape(string):
# Escape string for python regexp.
return re.sub('[\[\]().*+?^$-]', '\\\1', string)

def debug(vim, msg):
vim.command('echomsg string("' + msg + '")')
@@ -1,5 +1,5 @@
#=============================================================================
# FILE: context.py
# FILE: matcher_head.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license {{{
# Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -23,8 +23,11 @@
# }}}
#=============================================================================

class Context(object):
class Filter(object):
def __init__(self):
self.base_dir = base_dir

pass

def filter(self, vim, context):
max = len(context['complete_str'])
return [x for x in context['candidates']
if x.find(context['complete_str'], 0, max) == 0]
File renamed without changes.

0 comments on commit 3eb9a4c

Please sign in to comment.