mirror of
https://github.com/gryf/snipmate.vim.git
synced 2025-12-21 05:18:01 +01:00
fixed bug with aliased filetypes (e.g. loading C snippets for Obj-C files)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
" File: snipMate.vim
|
" File: snipMate.vim
|
||||||
" Author: Michael Sanders
|
" Author: Michael Sanders
|
||||||
" Version: 0.77
|
" Version: 0.78
|
||||||
" Description: snipMate.vim implements some of TextMate's snippets features in
|
" Description: snipMate.vim implements some of TextMate's snippets features in
|
||||||
" Vim. A snippet is a piece of often-typed text that you can
|
" Vim. A snippet is a piece of often-typed text that you can
|
||||||
" insert into your document using a trigger word followed by a "<tab>".
|
" insert into your document using a trigger word followed by a "<tab>".
|
||||||
@@ -15,8 +15,6 @@ endif
|
|||||||
let loaded_snips = 1
|
let loaded_snips = 1
|
||||||
if !exists('snips_author') | let snips_author = 'Me' | endif
|
if !exists('snips_author') | let snips_author = 'Me' | endif
|
||||||
|
|
||||||
au FileType objc,cpp,cs let &ft = expand('<amatch>').'.c'
|
|
||||||
au FileType xhtml let &ft = 'xhtml.html'
|
|
||||||
au BufRead,BufNewFile *.snippets\= set ft=snippet
|
au BufRead,BufNewFile *.snippets\= set ft=snippet
|
||||||
au FileType snippet setl noet fdm=indent
|
au FileType snippet setl noet fdm=indent
|
||||||
|
|
||||||
@@ -70,17 +68,16 @@ fun s:ProcessFile(file, ft, ...)
|
|||||||
\ : MakeSnip(a:ft, keyword, text)
|
\ : MakeSnip(a:ft, keyword, text)
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fun! ExtractSnipsFile(file)
|
fun! ExtractSnipsFile(file, ft)
|
||||||
if !filereadable(a:file) | return | endif
|
if !filereadable(a:file) | return | endif
|
||||||
let text = readfile(a:file)
|
let text = readfile(a:file)
|
||||||
let ft = fnamemodify(a:file, ':t:r:s?-.*??')
|
|
||||||
let inSnip = 0
|
let inSnip = 0
|
||||||
for line in text + ["\n"]
|
for line in text + ["\n"]
|
||||||
if inSnip && (line == '' || strpart(line, 0, 1) == "\t")
|
if inSnip && (line == '' || strpart(line, 0, 1) == "\t")
|
||||||
let content .= strpart(line, 1)."\n"
|
let content .= strpart(line, 1)."\n"
|
||||||
continue
|
continue
|
||||||
elseif inSnip
|
elseif inSnip
|
||||||
call MakeSnip(ft, trigger, content[:-2], name)
|
call MakeSnip(a:ft, trigger, content[:-2], name)
|
||||||
let inSnip = 0
|
let inSnip = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -103,21 +100,31 @@ fun! ResetSnippets()
|
|||||||
endf
|
endf
|
||||||
|
|
||||||
let g:did_ft = {}
|
let g:did_ft = {}
|
||||||
fun! GetSnippets(dir, filetype)
|
fun! GetSnippets(dir, filetypes)
|
||||||
for ft in split(a:filetype, '\.')
|
for ft in split(a:filetypes, '\.')
|
||||||
if has_key(g:did_ft, ft) | continue | endif
|
if has_key(g:did_ft, ft) | continue | endif
|
||||||
for path in split(globpath(a:dir, ft.'/')."\n".
|
call s:DefineSnips(a:dir, ft, ft)
|
||||||
\ globpath(a:dir, ft.'-*/'), "\n")
|
if ft == 'objc' || ft == 'cpp' || ft == 'cs'
|
||||||
call ExtractSnips(path, ft)
|
call s:DefineSnips(a:dir, 'c', ft)
|
||||||
endfor
|
elseif ft == 'xhtml'
|
||||||
for path in split(globpath(a:dir, ft.'.snippets')."\n".
|
call s:DefineSnips(a:dir, 'html', 'xhtml')
|
||||||
\ globpath(a:dir, ft.'-*.snippets'), "\n")
|
endif
|
||||||
call ExtractSnipsFile(path)
|
|
||||||
endfor
|
|
||||||
let g:did_ft[ft] = 1
|
let g:did_ft[ft] = 1
|
||||||
endfor
|
endfor
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
" Define "aliasft" snippets for the filetype "realft".
|
||||||
|
fun s:DefineSnips(dir, aliasft, realft)
|
||||||
|
for path in split(globpath(a:dir, a:aliasft.'/')."\n".
|
||||||
|
\ globpath(a:dir, a:aliasft.'-*/'), "\n")
|
||||||
|
call ExtractSnips(path, a:realft)
|
||||||
|
endfor
|
||||||
|
for path in split(globpath(a:dir, a:aliasft.'.snippets')."\n".
|
||||||
|
\ globpath(a:dir, a:aliasft.'-*.snippets'), "\n")
|
||||||
|
call ExtractSnipsFile(path, a:realft)
|
||||||
|
endfor
|
||||||
|
endf
|
||||||
|
|
||||||
fun! TriggerSnippet()
|
fun! TriggerSnippet()
|
||||||
if exists('g:SuperTabMappingForward')
|
if exists('g:SuperTabMappingForward')
|
||||||
if g:SuperTabMappingForward == "<tab>"
|
if g:SuperTabMappingForward == "<tab>"
|
||||||
|
|||||||
Reference in New Issue
Block a user