Add a common pythonx directory containing helper methods for snippets.
This commit is contained in:
parent
8770132e4e
commit
4b9f18c531
@ -12,6 +12,8 @@ from string import Template
|
|||||||
import re
|
import re
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
|
from vimsnippets import complete
|
||||||
|
|
||||||
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
|
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
|
||||||
TEXT_ROLES = ['emphasis','literal','code','math',
|
TEXT_ROLES = ['emphasis','literal','code','math',
|
||||||
'pep-reference','rfc-reference',
|
'pep-reference','rfc-reference',
|
||||||
@ -130,27 +132,6 @@ def get_popular_code_type():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
popular_type = "lua" # Don't break default
|
popular_type = "lua" # Don't break default
|
||||||
return popular_type
|
return popular_type
|
||||||
|
|
||||||
|
|
||||||
def complete(t, opts):
|
|
||||||
"""
|
|
||||||
get options that start with t
|
|
||||||
|
|
||||||
:param t: query string
|
|
||||||
:param opts: list that needs to be completed
|
|
||||||
|
|
||||||
:return: a string that start with t
|
|
||||||
"""
|
|
||||||
msg = "({0})"
|
|
||||||
if t:
|
|
||||||
opts = [ m[len(t):] for m in opts if m.startswith(t) ]
|
|
||||||
if len(opts) == 1:
|
|
||||||
return opts[0]
|
|
||||||
|
|
||||||
if not len(opts):
|
|
||||||
msg = "{0}"
|
|
||||||
return msg.format("|".join(opts))
|
|
||||||
|
|
||||||
endglobal
|
endglobal
|
||||||
|
|
||||||
snippet part "Part" b
|
snippet part "Part" b
|
||||||
|
37
plugin/vimsnippets.vim
Normal file
37
plugin/vimsnippets.vim
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
if exists("b:done_vimsnippets")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:done_vimsnippets = 1
|
||||||
|
|
||||||
|
" Expanding the path is not needed on Vim 7.4
|
||||||
|
if &cp || version >= 704
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Add pythonx to the python search path if needed (i.e. <= Vim 7.3).
|
||||||
|
if !has("python") && !has("python3")
|
||||||
|
finish
|
||||||
|
end
|
||||||
|
|
||||||
|
" This will fail if UltiSnips is not installed.
|
||||||
|
try
|
||||||
|
call UltiSnips#bootstrap#Bootstrap()
|
||||||
|
catch /E117/
|
||||||
|
finish
|
||||||
|
endtry
|
||||||
|
|
||||||
|
|
||||||
|
" This should have been set by UltiSnips, otherwise something is wrong.
|
||||||
|
if !exists("g:_uspy")
|
||||||
|
finish
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
" Expand our path
|
||||||
|
let s:SourcedFile=expand("<sfile>")
|
||||||
|
exec g:_uspy "import vim, os, sys"
|
||||||
|
exec g:_uspy "sourced_file = vim.eval('s:SourcedFile')"
|
||||||
|
exec g:_uspy "while not os.path.exists(os.path.join(sourced_file, 'pythonx')):
|
||||||
|
\ sourced_file = os.path.dirname(sourced_file)"
|
||||||
|
exec g:_uspy "module_path = os.path.join(sourced_file, 'pythonx')"
|
||||||
|
exec g:_uspy "sys.path.append(module_path)"
|
20
pythonx/vimsnippets.py
Normal file
20
pythonx/vimsnippets.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""Helper methods used in UltiSnips snippets."""
|
||||||
|
|
||||||
|
def complete(tab, opts):
|
||||||
|
"""
|
||||||
|
get options that start with tab
|
||||||
|
|
||||||
|
:param tab: query string
|
||||||
|
:param opts: list that needs to be completed
|
||||||
|
|
||||||
|
:return: a string that start with tab
|
||||||
|
"""
|
||||||
|
msg = "({0})"
|
||||||
|
if tab:
|
||||||
|
opts = [m[len(tab):] for m in opts if m.startswith(tab)]
|
||||||
|
if len(opts) == 1:
|
||||||
|
return opts[0]
|
||||||
|
|
||||||
|
if not len(opts):
|
||||||
|
msg = "{0}"
|
||||||
|
return msg.format("|".join(opts))
|
Loading…
Reference in New Issue
Block a user