Permalink
Browse files

Update snippets/snippet filetype settings

* :RetabSnip is removed
* A simple indent script is added
* Unify snippets/snippet filetypes but not syntaxes
  • Loading branch information...
ajzafar committed Mar 1, 2015
1 parent d704f34 commit 98edb94cf59537e5be54de0378517fb7655194d0
Showing with 61 additions and 55 deletions.
  1. +0 −38 autoload/snipMate.vim
  2. +0 −8 ftplugin/snippet.vim
  3. +20 −1 ftplugin/snippets.vim
  4. +32 −0 indent/snippets.vim
  5. +6 −5 plugin/snipMate.vim
  6. +3 −3 syntax/snippets.vim
View
@@ -385,44 +385,6 @@ fun! snipMate#GetSnippets(scopes, trigger) abort
return result
endf
" adds leading tab
" and replaces leading spaces by tabs
" see ftplugin/snippet.vim
fun! snipMate#RetabSnip() range abort
let leadingTab = expand('%:e') == 'snippets'
let lines = getline(a:firstline, a:lastline)
" remove leading "\t"
let allIndented = 1
for l in lines
if l[0] != '\t' | let allIndented = 0 | endif
endfor
" retab
if allIndented
call map(lines, 'v:val[1:]')
endif
let leadingSp = filter(map(copy(lines),'matchstr(v:val,"^\\s*") '),'v:val !=""')
if !empty(leadingSp)
" lines containing leading spaces found
let smallestInd = len(sort(leadingSp)[-1])
let ind = input('retab, spaces per tab: ', smallestInd)
for i in range(0, len(lines)-1)
let ml = matchlist(lines[i], '^\(\s*\)\(.*\)')
let lines[i] = repeat("\t", len(ml[1]) / ind)
\ . repeat( " ", len(ml[1]) % ind)
\ . ml[2]
endfor
endif
" readd tab
let tab = leadingTab ? "\t" : ""
for i in range(0,len(lines)-1)
call setline(a:firstline + i, tab.lines[i])
endfor
endf
function! snipMate#OpenSnippetFiles() abort
let files = []
let scopes_done = []
View

This file was deleted.

Oops, something went wrong.
View
@@ -1 +1,20 @@
runtime! ftplugin/snippet.vim
" Vim filetype plugin for SnipMate snippets (.snippets and .snippet files)
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let b:undo_ftplugin = "setl et< sts< cms< fdm< fde<"
" Use hard tabs
setlocal noexpandtab softtabstop=0
setlocal foldmethod=expr foldexpr=getline(v:lnum)!~'^\\t\\\\|^$'?'>1':1
setlocal commentstring=#\ %s
setlocal nospell
command! -buffer -range=% RetabSnip
\ echom "This command is deprecated. Use :retab and = instead. Doing that now."
\ | <line1>,<line2>retab! | <line1>,<line2>normal =
View
@@ -0,0 +1,32 @@
" Simple indent support for SnipMate snippets files
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal nosmartindent
setlocal indentkeys=!^F,o,O,=snippet,=version,=extends
setlocal indentexpr=GetSnippetIndent()
if exists("*GetSnippetIndent")
finish
endif
function! GetSnippetIndent()
let line = getline(v:lnum)
let prev_lnum = v:lnum - 1
let prev_line = prev_lnum != 0 ? getline(prev_lnum) : ""
if line =~# '\v^(snippet|extends|version) '
return 0
elseif indent(v:lnum) > 0
return indent(v:lnum)
elseif prev_line =~# '^snippet '
return &sw
elseif indent(prev_lnum) > 0
return indent(prev_lnum)
endif
return 0
endfunction
View
@@ -28,11 +28,12 @@ if (!exists('g:snipMateSources'))
let g:snipMateSources['default'] = funcref#Function('snipMate#DefaultPool')
endif
au BufRead,BufNewFile *.snippet set ft=snippet
au FileType snippet setl noet nospell
au BufRead,BufNewFile *.snippets set ft=snippets
au FileType snippets setl noet nospell fdm=expr fde=getline(v:lnum)!~'^\\t\\\\|^$'?'>1':1
au BufRead,BufNewFile *.snippet,*.snippets setlocal filetype=snippets
au FileType snippets if expand('<afile>:e') =~# 'snippet$'
\ | setlocal syntax=snippet
\ | else
\ | setlocal syntax=snippets
\ | endif
inoremap <silent> <Plug>snipMateNextOrTrigger <C-R>=snipMate#TriggerSnippet()<CR>
snoremap <silent> <Plug>snipMateNextOrTrigger <Esc>a<C-R>=snipMate#TriggerSnippet()<CR>
View
@@ -7,10 +7,10 @@ syn match snipEscape '\\\\\|\\`'
syn match snipCommand '\%(\\\@<!\%(\\\\\)*\)\@<=`.\{-}\%(\\\@<!\%(\\\\\)*\)\@<=`'
syn match snippet '^snippet.*' contains=multiSnipText,snipKeyword
syn match snippet '^extends.*' contains=snipKeyword
syn match snippet '^guard\s\+.*' contains=multiSnipText,snipKeyword
syn match snippet '^version.*' contains=snipKeyword
syn match multiSnipText '\S\+ \zs.*' contained
syn match snipKeyword '^(snippet|extends)'me=s+8 contained
syn match snipError "^[^#se\t].*$"
syn match snipKeyword '^(snippet|extends|version)'me=s+8 contained
syn match snipError "^[^#vse\t].*$"
hi link snippet Identifier
hi link snipComment Comment

0 comments on commit 98edb94

Please sign in to comment.