Merge pull request #419 from jsit/jsit/snipmate-dupes-416

Only set alternative trigger name in SnipMate mode if duplicate exists
This commit is contained in:
Shougo 2018-02-20 07:51:36 +09:00 committed by GitHub
commit ba91a5a54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,19 +138,23 @@ function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) abort
\ } \ }
" Try using the name without the description (abbr). " Try using the name without the description (abbr).
let snippet_dict.name = matchstr(a:line, '^snippet\s\+\zs\S\+') let base_name = matchstr(a:line, '^snippet\s\+\zs\S\+')
let snippet_dict.name = base_name
" Fall back to using the name and description (abbr) combined. " Fall back to using the name with integer counter,
" but only if the name is a duplicate.
" SnipMate snippets may have duplicate names, but different " SnipMate snippets may have duplicate names, but different
" descriptions (abbrs). " descriptions (abbrs).
let description = matchstr(a:line, '^snippet\s\+\S\+\s\+\zs.*$') let description = matchstr(a:line, '^snippet\s\+\S\+\s\+\zs.*$')
if g:neosnippet#enable_snipmate_compatibility if g:neosnippet#enable_snipmate_compatibility
\ && description != '' && description !=# snippet_dict.name \ && description != '' && description !=# snippet_dict.name
\ && has_key(a:dup_check, snippet_dict.name)
" Convert description. " Convert description.
let snippet_dict.name .= '_' . let i = 0
\ substitute(substitute( while has_key(a:dup_check, snippet_dict.name)
\ substitute(description, '\a\zs\a\+', '', 'g'), let snippet_dict.name = base_name . '__' . i
\ '\W\+', '_', 'g'), '_\+$', '', '') let i += 1
endwhile
endif endif
" Collect the description (abbr) of the snippet, if set on snippet line. " Collect the description (abbr) of the snippet, if set on snippet line.