Pulled from saikobee's branch.

This commit is contained in:
Holger Rapp 2014-01-04 07:30:01 +01:00
commit 8622753d3b
2 changed files with 51 additions and 5 deletions

View File

@ -335,12 +335,17 @@ You can also redefine the search path on a buffer by buffer basis by setting
the variable b:UltiSnipsSnippetDirectories. This variable takes precedence
over the global variable.
UltiSnips searches in 'runtimepath' for snippet directories but traverses
'runtimepath' in reverse order (last item first). If you would like to have
UltiSnips traverse 'runtimepath' in the standard order, add this to your vimrc
UltiSnips searches in 'runtimepath' for snippet directories and attempts to
determine if 'runtimepath' should be traversed in normal or reverse order. If
you would like to override the order UltiSnips detected for 'runtimepath', add
this to your vimrc
file: >
" Traverse in normal order
let g:UltiSnipsDontReverseSearchPath="1"
" Traverse in reverse order
let g:UltiSnipsDontReverseSearchPath="0"
By default, whenever a snippet expand is triggered, UltiSnips will check for
modifications to the snippet file associated with the filetype and reload it
if necessary. This behavior can be disabled as follows: >
@ -1391,6 +1396,7 @@ Contributors listed in chronological order:
Jonas Diemer - diemer
Romain Giot - rgiot
Sergey Alexandrov - taketwo
Brian Mock - saikobee
8.2 Snippets *UltiSnips-contrisnippets*

View File

@ -16,6 +16,47 @@ from UltiSnips.text_objects import SnippetInstance
from UltiSnips.util import IndentUtil
import UltiSnips._vim as _vim
def _plugin_dir():
""" Calculates the plugin directory for UltiSnips. This depends on the
current file being 3 levels deep from the plugin directory, so it needs to
be updated if the code moves.
"""
d = __file__
for i in xrange(10):
d = os.path.dirname(d)
if os.path.isdir(os.path.join(d, "plugin")) and os.path.isdir(os.path.join(d, "doc")):
return d
raise Exception("Unable to find the plugin directory.")
def _snippets_dir_is_before_plugin_dir():
""" Returns True if the snippets directory comes before the plugin
directory in Vim's runtime path. False otherwise.
"""
paths = [ os.path.expanduser(p).rstrip(os.path.sep)
for p in _vim.eval("&runtimepath").split(',') ]
home = _vim.eval("$HOME")
def vim_path_index(suffix):
path = os.path.join(home, suffix).rstrip(os.path.sep)
try:
return paths.index(path)
except ValueError:
return -1
try:
real_vim_path_index = max(vim_path_index(".vim"), vim_path_index("vimfiles"))
return paths.index(_plugin_dir()) < real_vim_path_index
except ValueError:
return False
def _should_reverse_search_path():
""" If the user defined g:UltiSnipsDontReverseSearchPath then return True
or False based on the value of that variable, else defer to
_snippets_dir_is_before_plugin_dir to determine whether this is True or
False.
"""
if _vim.eval("exists('g:UltiSnipsDontReverseSearchPath')") != "0":
return _vim.eval("g:UltiSnipsDontReverseSearchPath") != "0"
return not _snippets_dir_is_before_plugin_dir()
def err_to_scratch_buffer(f):
@wraps(f)
def wrapper(self, *args, **kwds):
@ -968,8 +1009,7 @@ class SnippetManager(object):
paths = _vim.eval("&runtimepath").split(',')
if _vim.eval("exists('g:UltiSnipsDontReverseSearchPath')") == "0" or \
_vim.eval("g:UltiSnipsDontReverseSearchPath") == "0":
if _should_reverse_search_path():
paths = paths[::-1]
for rtp in paths: