Change globbing patterns for snippets to follow Vim more closely

This commit is contained in:
Holger Rapp 2012-01-28 14:35:04 +01:00
parent 5ebad7351c
commit bcf8cc8a6d
2 changed files with 13 additions and 8 deletions

View File

@ -254,16 +254,20 @@ provide many examples to make things clearer.
See |UltiSnips-snippet-search-path| for an explanation of where directories See |UltiSnips-snippet-search-path| for an explanation of where directories
with snippet definitions are expected. with snippet definitions are expected.
While iterating over the snippet definition directories found, files are UltiSnips follows the same search pattern that Vim itself uses when searching
looked for called ft.snippets or *_ft.snippets where "ft" is the current for ftplugins: While iterating over the snippet definition directories found,
'filetype', and the "*" matches anything, for example: > files are listed with the following glob patterns: ft.snippets, ft_*.snippets,
ft/*. ft is the current 'filetype', and the "*" matches anything, for example:
ruby.snippets ruby.snippets
c.snippets c.snippets
my_c.snippets c_mine.snippets
c/a
c/b.snippets
perl.snippets perl.snippets
These files contain the snippet definitions for the various file types. A Those files are than traversed in order to gather snippet definitions for the
special file is > various file types. A special filetype is all, e.g. >
all.snippets all.snippets
all/a.snippets
which contains snippets that are always expanded, no matter what file type is which contains snippets that are always expanded, no matter what file type is
defined. For example, I keep mail signatures and date insertion snippets here. defined. For example, I keep mail signatures and date insertion snippets here.
@ -276,7 +280,7 @@ As an alternative, a snippet file may contain a line that looks like this: >
extends ft1, ft2, ft3 extends ft1, ft2, ft3
For example, the first line in cpp.snippets looks like this: > For example, the first line in cpp.snippets looks like this: >
extends c extends c
This means, first check all triggers for c, then add the triggers from this This means, first search all snippets for c, then add the snippets from this
file. This is a convenient way to add more special cases to more general ones. file. This is a convenient way to add more special cases to more general ones.
Multiple "extends" lines are permitted throughout the snippets file. Multiple "extends" lines are permitted throughout the snippets file.

View File

@ -871,12 +871,13 @@ class SnippetManager(object):
for snippet_dir in snippet_dirs: for snippet_dir in snippet_dirs:
pth = os.path.realpath(os.path.expanduser(os.path.join(rtp, snippet_dir))) pth = os.path.realpath(os.path.expanduser(os.path.join(rtp, snippet_dir)))
patterns = ["%s.snippets", "*_%s.snippets"] patterns = ["%s.snippets", "%s_*.snippets", os.path.join("%s","*")]
if not default and pth == base_snippets: if not default and pth == base_snippets:
patterns.remove("%s.snippets") patterns.remove("%s.snippets")
for pattern in patterns: for pattern in patterns:
for fn in glob.glob(os.path.join(pth, pattern % ft)): for fn in glob.glob(os.path.join(pth, pattern % ft)):
debug("fn: %r" % (fn))
if fn not in ret: if fn not in ret:
ret.append(fn) ret.append(fn)