Skip to content

Commit

Permalink
Merge remote-tracking branch 'cazador481/python'
Browse files Browse the repository at this point in the history
  • Loading branch information
chumakd committed Feb 9, 2019
2 parents d1d8cde + 5d1d118 commit d1700ca
Show file tree
Hide file tree
Showing 5 changed files with 921 additions and 90 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ nytprof.out
*.o
*.bs
/_eumm/

.ropeproject/
__pycache__
*.bk

### Vim ###
[._]*.s[a-w][a-z]
Expand All @@ -30,4 +32,3 @@ nytprof.out
Session.vim
.netrwhist
*~

102 changes: 15 additions & 87 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -8,124 +8,48 @@ http://www.youtube.com/watch?v=hZ7871WcIv0
Description
===========

perl-completion plugin supports basic perl completion and Moose / DBIx::Class completion.
Deoplete source completion engine for perl includes Mo* / DBIx::Class completion.

the rules could be easily extended. see ( ftplugin/perl/perlomni.vim )
Based off of https://github.com/c9s/perlomni.vim

core rules including:

* variable name completion
* function name completion
* package method name completion
* base class method name completion
* basic Moose completion
* basic Moo completion
* basic DBIx completion


Requirement
===========

perlomni completion requires *vim 7.2 or newer.*
perlomni completion requires *neovim*

and filetype feature should be enabled.
https://github.com/Shougo/deoplete.nvim

Install
========

just run make:

$ make install

and add ~/.vim/bin/ to your $PATH env variable , for example, add these lines to your .bashrc or .zshrc:

export PATH=~/.vim/bin:$PATH

please make sure you've enable filetype plugin your `.vimrc`:

filetype on
filetype plugin on
filetype indent on

NOTE) If you install pathogen.vim , you can make this working without installing.

Usage
=====

In insert mode , press C-x C-o to emit omni completion.

P.S. The completion works in terminal vim is faster than gvim/MacVim.

Write your perl omni completion extensions
=========================================

Perl omni completion plugin is extensible, you can extend completion rules by
simple regular expressions.

your omni completion extension should put in ~/.vim/after/ftplugin/perl/what-ever.vim.

## API Functions

**AddPerlOmniRule(rule)**, for example:

cal AddPerlOmniRule({ 'only':1, 'head': '^has\s\+\w\+' ,
\'context': '\s\+is\s*=>\s*$' ,
\'backward': '[''"]\?\w*$' ,
\'comp': function('s:CompMooseIs') } )

cal AddPerlOmniRule({
\'only':1,
\'context': '&$',
\'backward': '\<\U\w\+$',
\'comp': function('s:CompBufferFunction') })

Available Rule attributes

only:
if one rule is matched, then rest rules won't be check.

contains:
if file contains some string (can be regexp)

context:
completion context pattern

backward:
regexp for moving cursor back to the completion position.

head:
pattern that matches paragraph head.

comp:
completion function reference.


### Cache Functions

**GetCacheNS(ns,key)**

ns: cache namespace
key: cache key

**SetCacheNS(ns,key,value)**

ns: cache namespace
key: cache key
value: cache value

NeoBundle
NeoBundle 'cazador481/perlomni.vim', 'python'


Development
===========

Please feel free to ask commit bit of this. just drop me a line. :-)


Author
======
- cazador481 (Edward Ash) [email protected]

Original Author of perlomni
=====
- Cornelius (林佑安) [email protected]
- Mattn (Yasuhiro Matsumoto) [email protected]


Samples
=======

Expand Down Expand Up @@ -194,3 +118,7 @@ Samples
};

" }}}

VARIABLES
========
g:perlomni_export_functions = enables export functions
167 changes: 167 additions & 0 deletions rplugin/python3/deoplete/sources/perl_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# ============================================================================
# FILE: base.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 re
import time
#from abc import abstractmethod
from .base import Base
from deoplete import logger
import deoplete.util


class Perl_base(Base):

def __init__(self, vim):
Base.__init__(self, vim)
self.filetypes = ['perl']
self._last_cache_ts = time.clock()
self._cache_expiry = {}
self._cache_last = {}
self._cache = {} # g:perlomni_cache
self._cpan_mod_cache = [] # lists of classnames for completion
self._comps = []
# self.is_async = 1
self._perlomni_cache_expiry = 30 # default value
deoplete.util.set_default(self.vim, 'g:perlomni_use_cache', 1)
self.debug_enabled = 1

def get_complete_position(self, context):
# todo remove
loc = self.PerlComplete(1)
self.debug("Completion_pos:"+str(loc))
return loc


def PerlComplete(self, findstart): # , base):
buffer = self.vim.current.buffer
lines = buffer[1:200]
# if ! exists('b:lines')
# " max 200 lines , to '$' will be very slow
# let b:lines = getline( 1, 200 )
# endif

line = self.vim.current.line
(lnum, lcolpos) = self.vim.current.window.cursor
# start = lcolpos - 1
if findstart == 1:

self._comps = [] # " will hold rules that we use on the next step
# self._comps = self.vim.bindeval('b:comps=[]')
# "let s_pos = s:FindSpace(star,lnum,line)
#
# " XXX: read lines from current buffer
# " let b:lines =
context = line

lcontext = context[0:lcolpos]
# lcontext = context[:-1]
# let b:lcontext = strpart(getline('.'),0,col('.')-1)

# " let b:pcontext
# TODO ddefine parseParagraphhead
paragraph_head = self.parseParagraphHead(lnum)

first_bwidx = -1

for rule in self._rules:

# let match = matchstr( b:lcontext , rule.backward )
match = re.search(rule['backward'], lcontext)
if match:
bwidx = match.start()
else:
bwidx = -1
# if backward regexp matched is empty, check if context regexp
# is matched ? if yes, set bwidx to length, if not , set to
# -1
# if re.match(rule['context'], lcontext):
# bwidx = len(lcontext)
# else:
# bwidx = -1

# see if there is first matched index
if first_bwidx != -1 and first_bwidx != bwidx:
continue

if bwidx == -1:
continue

# lefttext: context matched text
# basetext: backward matched text
# self.debug('bwidx:'+str(bwidx))
lefttext = lcontext[0:bwidx]
basetext = lcontext[bwidx:]

# if ( has_key( rule ,'head')
# \ && b:paragraph_head =~ rule.head
# \ && lefttext =~ rule.context )
# \ || ( ! has_key(rule,'head') && lefttext =~ rule.context)
if re.search(rule['context'], lefttext):
self.debug('--------------------')
self.debug('context match')
self.debug('function:' + str(rule['comp']))
self.debug('head:' + paragraph_head)
self.debug('lefttext:' + lefttext)
self.debug('context:' + rule['context'])
self.debug('basetext:' + basetext)
self.debug('--------------------')
# else :
# self.debug('context does not match')
if (('head' in rule and re.search(rule['head'], paragraph_head) and re.search(rule[
'context'], lefttext))
or (not ('head' in rule)
and re.search(rule['context'], lefttext))):

if 'contains' in rule:
# text = rule['contains']
found = 0
# check content
for line in lines:
if re.search(rule['contains'], line):
found = 1
self.debug('found contains')
break
if not found:
# next rule
self.debug('Did not find contains')
continue
if isinstance(rule['comp'], list):
self._comps += rule['comp']
else:
self._comps += rule['comp'](basetext, lefttext)

if 'only' in rule and rule['only'] == 1:
return bwidx

# save first backward index
if first_bwidx == -1:
first_bwidx = bwidx

# else:
# self.debug('does not match')
return first_bwidx
else:
return self._comps

Loading

0 comments on commit d1700ca

Please sign in to comment.