Skip to content
Snippets Groups Projects
Commit af7a6adb authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

First version

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1251 additions and 0 deletions
" Vim indent file
" Language: OCaml
" Maintainers: Jean-Francois Yuen <jfyuen@happycoders.org>
" Mike Leary <leary@nwlink.com>
" Markus Mottl <markus.mottl@gmail.com>
" URL: http://www.ocaml.info/vim/indent/ocaml.vim
" Last Change: 2010 Sep 04 - Added an indentation improvement by Mark Weber
" 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
" 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal expandtab
setlocal indentexpr=GetOCamlIndent()
setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=initializer,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0)
setlocal nolisp
setlocal nosmartindent
setlocal textwidth=80
setlocal shiftwidth=2
" Comment formatting
if !exists("no_ocaml_comments")
if (has("comments"))
setlocal comments=sr:(**,mb:\ ,ex:*),sr:(*,m:*,ex:*)
setlocal fo=cqort
endif
endif
" Only define the function once.
if exists("*GetOCamlIndent")
finish
endif
" Define some patterns:
let s:beflet = '^\s*\(initializer\|method\|try\)\|\(\<\(begin\|do\|else\|in\|then\|try\)\|->\|<-\|=\|;\|(\)\s*$'
let s:letpat = '^\s*\(let\|type\|module\|class\|open\|exception\|val\|include\|external\)\>'
let s:letlim = '\(\<\(sig\|struct\)\|;;\)\s*$'
let s:lim = '^\s*\(exception\|external\|include\|let\|module\|open\|type\|val\)\>'
let s:module = '\<\%(begin\|sig\|struct\|object\)\>'
let s:obj = '^\s*\(constraint\|inherit\|initializer\|method\|val\)\>\|\<\(object\|object\s*(.*)\)\s*$'
let s:type = '^\s*\%(class\|let\|type\)\>.*='
" Skipping pattern, for comments
function! s:GetLineWithoutFullComment(lnum)
let lnum = prevnonblank(a:lnum - 1)
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
while lline =~ '^\s*$' && lnum > 0
let lnum = prevnonblank(lnum - 1)
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
endwhile
return lnum
endfunction
" Indent for ';;' to match multiple 'let'
function! s:GetInd(lnum, pat, lim)
let llet = search(a:pat, 'bW')
let old = indent(a:lnum)
while llet > 0
let old = indent(llet)
let nb = s:GetLineWithoutFullComment(llet)
if getline(nb) =~ a:lim
return old
endif
let llet = search(a:pat, 'bW')
endwhile
return old
endfunction
" Indent pairs
function! s:FindPair(pstart, pmid, pend)
call search(a:pend, 'bW')
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
endfunction
" Indent 'let'
function! s:FindLet(pstart, pmid, pend)
call search(a:pend, 'bW')
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\<in\\s*$" || getline(prevnonblank(".") - 1) =~ s:beflet'))
endfunction
function! GetOCamlIndent()
" Find a non-commented line above the current line.
let lnum = s:GetLineWithoutFullComment(v:lnum)
" At the start of the file use zero indent.
if lnum == 0
return 0
endif
let ind = indent(lnum)
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
" Return double 'shiftwidth' after lines matching:
"if lline =~ '^\s*|.*->\s*$'
" return ind + &sw + &sw
"endif
let line = getline(v:lnum)
" Indent if line ends with 'match ... with':
"if lline =~ '\<match\>.*\<with\s*$'
" return ind + &sw
" Indent if current line begins with 'end':
if line =~ '^\s*end\>'
return s:FindPair(s:module, '','\<end\>')
" Indent if current line begins with 'done' for 'do':
elseif line =~ '^\s*done\>'
return s:FindPair('\<do\>', '','\<done\>')
" Indent if current line begins with '}' or '>}':
elseif line =~ '^\s*\(\|>\)}'
return s:FindPair('{', '','}')
" Indent if current line begins with ']', '|]' or '>]':
elseif line =~ '^\s*\(\||\|>\)\]'
return s:FindPair('\[', '','\]')
" Indent if current line begins with ')':
elseif line =~ '^\s*)'
return s:FindPair('(', '',')')
" Indent if current line begins with 'let':
elseif line =~ '^\s*let\>'
if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet
return s:FindLet(s:type, '','\<let\s*$')
endif
" Indent if current line begins with 'class' or 'type':
elseif line =~ '^\s*\(class\|type\)\>'
if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim
return s:FindLet(s:type, '','\<\(class\|type\)\s*$')
endif
" Indent for pattern matching:
elseif line =~ '^\s*|'
if lline !~ '^\s*\(|[^\]]\|\(match\|type\|with\)\>\)\|\<\(function\|parser\|private\|with\)\s*$'
call search('|', 'bW')
return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|parser\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"'))
endif
" Indent if current line begins with ';;':
elseif line =~ '^\s*;;'
if lline !~ ';;\s*$'
return s:GetInd(v:lnum, s:letpat, s:letlim)
endif
" Indent if current line begins with 'in':
elseif line =~ '^\s*in\>'
if lline !~ '^\s*\(let\|and\)\>'
return s:FindPair('\<let\>', '', '\<in\>')
endif
" Indent if current line begins with 'else':
elseif line =~ '^\s*else\>'
if lline !~ '^\s*\(if\|then\)\>'
return s:FindPair('\<if\>', '', '\<else\>')
endif
" Indent if current line begins with 'then':
elseif line =~ '^\s*then\>'
if lline !~ '^\s*\(if\|else\)\>'
return s:FindPair('\<if\>', '', '\<then\>')
endif
" Indent if current line begins with 'and':
elseif line =~ '^\s*and\>'
if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
return ind - &sw
endif
" Indent if current line begins with 'with':
elseif line =~ '^\s*with\>'
if lline !~ '^\s*\(match\|try\)\>'
return s:FindPair('\<\%(match\|try\)\>', '','\<with\>')
endif
" Indent if current line begins with 'exception', 'external', 'include' or
" 'open':
elseif line =~ '^\s*\(exception\|external\|include\|open\)\>'
if lline !~ s:lim . '\|' . s:letlim
call search(line)
return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW'))
endif
" Indent if current line begins with 'val':
elseif line =~ '^\s*val\>'
if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim
return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW'))
endif
" Indent if current line begins with 'constraint', 'inherit', 'initializer'
" or 'method':
elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
if lline !~ s:obj
return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw
endif
endif
" Add a 'shiftwidth' after lines ending with:
if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|parser\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
let ind = ind + &sw
" Back to normal indent after lines ending with ';;':
elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
let ind = s:GetInd(v:lnum, s:letpat, s:letlim)
" Back to normal indent after lines ending with 'end':
elseif lline =~ '\<end\s*$'
let ind = s:FindPair(s:module, '','\<end\>')
" Back to normal indent after lines ending with 'in':
elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>'
let ind = s:FindPair('\<let\>', '', '\<in\>')
" Back to normal indent after lines ending with 'done':
elseif lline =~ '\<done\s*$'
let ind = s:FindPair('\<do\>', '','\<done\>')
" Back to normal indent after lines ending with '}' or '>}':
elseif lline =~ '\(\|>\)}\s*$'
let ind = s:FindPair('{', '', '}')
" Back to normal indent after lines ending with ']', '|]' or '>]':
elseif lline =~ '\(\||\|>\)\]\s*$'
let ind = s:FindPair('\[', '', '\]')
" Back to normal indent after comments:
elseif lline =~ '\*)\s*$'
call search('\*)', 'bW')
let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
" Back to normal indent after lines ending with ')':
elseif lline =~ ')\s*$'
let ind = s:FindPair('(', '', ')')
" Indent closing brachet for ocamldoc comment properly
"elseif lline =~ '^\s*(\*\*' && line =~ '^\s*\*)'
" let ind = s:FindPair('(\*\*', '', '\*)') + 1
" If this is an ocamldoc comment then indent with 4 spaces
elseif lline =~ '^\s*(\*\*'
let ind = 4
" If this is a multiline comment then align '*':
"elseif lline =~ '^\s*(\*' && line =~ '^\s*\*'
" let ind = ind + 1
" String with continuation character -> indent continuation on next line
elseif lline =~ '\\\s*$'
call search('\\', 'bW')
let ind = searchpairpos('"', '', '"', 'bWn', 'getline(".")[col(".")-2] =~ "\\"')[1]
" Return to original indent when string ends
elseif lline =~ '"\s*$'
call search('"', 'bW')
let ind = indent(searchpair('"', '', '"', 'bWn', 'getline(".")[col(".")-2] =~ "\\"'))
"let ind = searchpairpos('"', '', '"', 'bWn', 'getline(".")[col(".")-2] =~ "\\"')[1] - 1
else
" Don't change indentation of this line
" for new lines (indent==0) use indentation of previous line
" This is for preventing removing indentation of these args:
" let f x =
" let y = x + 1 in
" Printf.printf
" "o" << here
" "oeuth" << don't touch indentation
let i = indent(v:lnum)
return i == 0 ? ind : i
endif
" Subtract a 'shiftwidth' after lines matching 'match ... with parser':
if lline =~ '\<match\>.*\<with\>\s*\<parser\s*$'
let ind = ind - &sw
endif
return ind
endfunction
" vim:sw=2
"
" File: clang_complete.vim
" Author: Xavier Deguillard <deguilx@gmail.com>
"
" Description: Use of clang to complete in C/C++.
"
" Configuration: Each project can have a .clang_complete at his root,
" containing the compiler options. This is useful if
" you're using some non-standard include paths.
" For simplicity, please don't put relative and
" absolute include path on the same line. It is not
" currently correctly handled.
"
" Options:
" - g:clang_complete_auto:
" if equal to 1, automatically complete after ->, ., ::
" Default: 1
"
" - g:clang_complete_copen:
" if equal to 1, open quickfix window on error.
" Default: 0
"
" - g:clang_hl_errors:
" if equal to 1, it will highlight the warnings and errors the
" same way clang does it.
" Default: 1
"
" - g:clang_periodic_quickfix:
" if equal to 1, it will periodically update the quickfix window
" Note: You could use the g:ClangUpdateQuickFix() to do the same
" with a mapping.
" Default: 0
"
" - g:clang_snippets:
" if equal to 1, it will do some snippets magic after a ( or a ,
" inside function call. Not currently fully working.
" Default: 0
"
" - g:clang_conceal_snippets:
" if equal to 1, vim will use vim 7.3 conceal feature to hide <#
" and #> which delimit a snippets.
" Note: See concealcursor and conceallevel for conceal configuration.
" Default: 1 (0 if conceal not available)
"
" - g:clang_exec:
" Name or path of clang executable.
" Note: Use this if clang has a non-standard name, or isn't in the
" path.
" Default: 'clang'
"
" - g:clang_user_options:
" Option added at the end of clang command. Useful if you want to
" filter the result, or if you want to ignore the error code
" returned by clang: on error, the completion is not shown.
" Default: ''
" Example: '|| exit 0' (it will discard clang return value)
"
" Todo: - Fix bugs
" - Parse fix-its and do something useful with it.
" - -code-completion-macros -code-completion-patterns
"
au FileType c,cpp,objc,objcpp call s:ClangCompleteInit()
let b:clang_parameters = ''
let b:clang_user_options = ''
let b:my_changedtick = 0
function s:ClangCompleteInit()
let l:local_conf = findfile(".clang_complete", '.;')
let b:clang_user_options = ''
if l:local_conf != ""
let l:opts = readfile(l:local_conf)
for l:opt in l:opts
" Better handling of absolute path
" I don't know if those pattern will work on windows
" platform
if matchstr(l:opt, '\C-I\s*/') != ""
let l:opt = substitute(l:opt, '\C-I\s*\(/\%(\w\|\\\s\)*\)',
\ '-I' . '\1', "g")
else
let l:opt = substitute(l:opt, '\C-I\s*\(\%(\w\|\\\s\)*\)',
\ '-I' . l:local_conf[:-16] . '\1', "g")
endif
let b:clang_user_options .= " " . l:opt
endfor
endif
if !exists('g:clang_complete_auto')
let g:clang_complete_auto = 1
endif
if !exists('g:clang_complete_copen')
let g:clang_complete_copen = 0
endif
if !exists('g:clang_hl_errors')
let g:clang_hl_errors = 1
endif
if !exists('g:clang_periodic_quickfix')
let g:clang_periodic_quickfix = 0
endif
if !exists('g:clang_snippets')
let g:clang_snippets = 0
endif
if !exists('g:clang_conceal_snippets')
let g:clang_conceal_snippets = has("conceal")
endif
if !exists('g:clang_exec')
let g:clang_exec = 'clang'
endif
if !exists('g:clang_user_options')
let g:clang_user_options = ''
endif
let b:clang_user_options .= ' ' . g:clang_user_options
if g:clang_complete_auto == 1
inoremap <expr> <buffer> <C-X><C-U> LaunchCompletion()
inoremap <expr> <buffer> . CompleteDot()
inoremap <expr> <buffer> > CompleteArrow()
inoremap <expr> <buffer> : CompleteColon()
endif
if g:clang_snippets == 1
noremap <expr> <buffer> <tab> UpdateSnips()
snoremap <expr> <buffer> <tab> UpdateSnips()
if g:clang_conceal_snippets == 1
syntax match Conceal /<#/ conceal
syntax match Conceal /#>/ conceal
endif
endif
" Disable every autocmd that could have been set.
augroup ClangComplete
autocmd!
augroup end
let b:should_overload = 0
let b:my_changedtick = b:changedtick
let b:clang_parameters = '-x c'
if &filetype == 'objc'
let b:clang_parameters = '-x objective-c'
endif
if &filetype == 'cpp' || &filetype == 'objcpp'
let b:clang_parameters .= '++'
endif
if expand('%:e') =~ 'h*'
let b:clang_parameters .= '-header'
endif
setlocal completefunc=ClangComplete
if g:clang_periodic_quickfix == 1
augroup ClangComplete
au CursorHold,CursorHoldI <buffer> call s:DoPeriodicQuickFix()
augroup end
endif
endfunction
function s:GetKind(proto)
if a:proto == ""
return 't'
endif
let l:ret = match(a:proto, '^\[#')
let l:params = match(a:proto, '(')
if l:ret == -1 && l:params == -1
return 't'
endif
if l:ret != -1 && l:params == -1
return 'v'
endif
if l:params != -1
return 'f'
endif
return 'm'
endfunction
function s:DoPeriodicQuickFix()
" Don't do any superfluous reparsing.
if b:my_changedtick == b:changedtick
return
endif
let b:my_changedtick = b:changedtick
let l:buf = getline(1, '$')
let l:tempfile = expand('%:p:h') . '/' . localtime() . expand('%:t')
try
call writefile(l:buf, l:tempfile)
catch /^Vim\%((\a\+)\)\=:E482/
return
endtry
let l:escaped_tempfile = shellescape(l:tempfile)
let l:command = g:clang_exec . " -cc1 -fsyntax-only"
\ . " -fno-caret-diagnostics -fdiagnostics-print-source-range-info"
\ . " " . l:escaped_tempfile
\ . " " . b:clang_parameters . " " . b:clang_user_options
let l:clang_output = split(system(l:command), "\n")
call delete(l:tempfile)
call s:ClangQuickFix(l:clang_output, l:tempfile)
endfunction
function s:ClangQuickFix(clang_output, tempfname)
" Clear the bad spell, the user may have corrected them.
syntax clear SpellBad
syntax clear SpellLocal
let l:list = []
for l:line in a:clang_output
let l:erridx = match(l:line, '\%(error\|warning\): ')
if l:erridx == -1
" Error are always at the beginning.
if l:line[:11] == 'COMPLETION: ' || l:line[:9] == 'OVERLOAD: '
break
endif
continue
endif
let l:pattern = '^\(.*\):\(\d*\):\(\d*\):\(\%({\d\+:\d\+-\d\+:\d\+}\)*\)'
let l:tmp = matchstr(l:line, l:pattern)
let l:fname = substitute(l:tmp, l:pattern, '\1', '')
if l:fname == a:tempfname
let l:fname = "%"
endif
let l:bufnr = bufnr(l:fname, 1)
let l:lnum = substitute(l:tmp, l:pattern, '\2', '')
let l:col = substitute(l:tmp, l:pattern, '\3', '')
let l:errors = substitute(l:tmp, l:pattern, '\4', '')
if l:line[l:erridx] == 'e'
let l:text = l:line[l:erridx + 7:]
let l:type = 'E'
let l:hlgroup = " SpellBad "
else
let l:text = l:line[l:erridx + 9:]
let l:type = 'W'
let l:hlgroup = " SpellLocal "
endif
let l:item = {
\ "bufnr": l:bufnr,
\ "lnum": l:lnum,
\ "col": l:col,
\ "text": l:text,
\ "type": l:type }
let l:list = add(l:list, l:item)
if g:clang_hl_errors == 0 || l:fname != "%"
continue
endif
" Highlighting the ^
let l:pat = '/\%' . l:lnum . 'l' . '\%' . l:col . 'c./'
exe "syntax match" . l:hlgroup . l:pat
if l:errors == ""
continue
endif
let l:ranges = split(l:errors, '}')
for l:range in l:ranges
" Doing precise error and warning handling.
" The highlight will be the same as clang's carets.
let l:pattern = '{\%(\d\+\):\(\d\+\)-\%(\d\+\):\(\d\+\)'
let l:tmp = matchstr(l:range, l:pattern)
let l:startcol = substitute(l:tmp, l:pattern, '\1', '')
let l:endcol = substitute(l:tmp, l:pattern, '\2', '')
" Highlighting the ~~~~
let l:pat = '/\%' . l:lnum . 'l'
\ . '\%' . l:startcol . 'c'
\ . '.*'
\ . '\%' . l:endcol . 'c/'
exe "syntax match" . l:hlgroup . l:pat
endfor
endfor
call setqflist(l:list)
doautocmd QuickFixCmdPost make
if g:clang_complete_copen == 1
" We should get back to the original buffer
let l:bufnr = bufnr("%")
cwindow
let l:winbufnr = bufwinnr(l:bufnr)
exe l:winbufnr . "wincmd w"
endif
endfunction
function s:DemangleProto(prototype)
let l:proto = substitute(a:prototype, '[#', "", "g")
let l:proto = substitute(l:proto, '#]', ' ', "g")
let l:proto = substitute(l:proto, '#>', "", "g")
let l:proto = substitute(l:proto, '<#', "", "g")
" TODO: add a candidate for each optional parameter
let l:proto = substitute(l:proto, '{#', "", "g")
let l:proto = substitute(l:proto, '#}', "", "g")
return l:proto
endfunction
let b:col = 0
function ClangComplete(findstart, base)
if a:findstart
let l:line = getline('.')
let l:start = col('.') - 1
let l:wsstart = l:start
if l:line[l:wsstart - 1] =~ '\s'
while l:wsstart > 0 && l:line[l:wsstart - 1] =~ '\s'
let l:wsstart -= 1
endwhile
endif
if l:line[l:wsstart - 1] =~ '[(,]'
let b:should_overload = 1
let b:col = l:wsstart + 1
return l:wsstart
endif
let b:should_overload = 0
while l:start > 0 && l:line[l:start - 1] =~ '\i'
let l:start -= 1
endwhile
let b:col = l:start + 1
return l:start
else
let l:buf = getline(1, '$')
let l:tempfile = expand('%:p:h') . '/' . localtime() . expand('%:t')
try
call writefile(l:buf, l:tempfile)
catch /^Vim\%((\a\+)\)\=:E482/
return {}
endtry
let l:escaped_tempfile = shellescape(l:tempfile)
let l:command = g:clang_exec . " -cc1 -fsyntax-only"
\ . " -fno-caret-diagnostics -fdiagnostics-print-source-range-info"
\ . " -code-completion-at=" . l:escaped_tempfile . ":"
\ . line('.') . ":" . b:col . " " . l:escaped_tempfile
\ . " " . b:clang_parameters . " " . b:clang_user_options
let l:clang_output = split(system(l:command), "\n")
call delete(l:tempfile)
call s:ClangQuickFix(l:clang_output, l:tempfile)
if v:shell_error
return {}
endif
if l:clang_output == []
return {}
endif
let l:res = []
for l:line in l:clang_output
if l:line[:11] == 'COMPLETION: ' && b:should_overload != 1
let l:value = l:line[12:]
if l:value =~ 'Pattern'
if g:clang_snippets != 1
continue
endif
let l:value = l:value[10:]
endif
if l:value !~ '^' . a:base
continue
endif
let l:colonidx = stridx(l:value, " : ")
if l:colonidx == -1
let l:wabbr = s:DemangleProto(l:value)
let l:word = l:value
let l:proto = l:value
else
let l:word = l:value[:l:colonidx - 1]
" WTF is that?
if l:word =~ '(Hidden)'
let l:word = l:word[:-10]
endif
let l:wabbr = l:word
let l:proto = l:value[l:colonidx + 3:]
endif
let l:kind = s:GetKind(l:proto)
if g:clang_snippets == 1
let l:word = substitute(l:proto, '\[#[^#]*#\]', "", "g")
else
let l:word = l:wabbr
endif
let l:proto = s:DemangleProto(l:proto)
elseif l:line[:9] == 'OVERLOAD: ' && b:should_overload == 1
\ && g:clang_snippets == 1
let l:value = l:line[10:]
if match(l:value, '<#') == -1
continue
endif
" TODO: handle optionnal parameters correctly.
let l:word = substitute(l:value, '.*<#', '<#', "g")
let l:word = substitute(l:word, '#>.*', '#>', "g")
let l:wabbr = substitute(l:word, '<#\([^#]*\)#>', '\1', "g")
let l:proto = s:DemangleProto(l:value)
let l:kind = ""
else
continue
endif
let l:item = {
\ "word": l:word,
\ "abbr": l:wabbr,
\ "menu": l:proto,
\ "info": l:proto,
\ "dup": 1,
\ "kind": l:kind }
call add(l:res, l:item)
endfor
if g:clang_snippets == 1
augroup ClangComplete
au CursorMovedI <buffer> call BeginSnips()
augroup end
endif
return l:res
endif
endfunction
function ShouldComplete()
if (getline(".") =~ '#\s*\(include\|import\)')
return 0
else
return match(synIDattr(synID(line("."), col(".") - 1, 1), "name"),
\'\C\<cComment\|\<cCppString\|\<cString\|\<cNumber') == -1
endfunction
function LaunchCompletion()
if ShouldComplete()
return "\<C-X>\<C-U>"
else
return ""
endif
endfunction
function CompleteDot()
return '.' . LaunchCompletion()
endfunction
function CompleteArrow()
if getline('.')[col('.') - 2] != '-'
return '>'
endif
return '>' . LaunchCompletion()
endfunction
function CompleteColon()
if getline('.')[col('.') - 2] != ':'
return ':'
endif
return ':' . LaunchCompletion()
endfunction
function UpdateSnips()
let l:line = getline(".")
let l:pattern = '<#[^#]*#>'
if match(l:line, l:pattern) == -1
return ""
endif
" Is it possible to use f/t/F/T on multiple chars?
"return "\<esc>f<va>\<C-G>"
return "\<esc>/<#\<CR>v/#>\<CR>l\<C-G>"
endfunction
function BeginSnips()
if pumvisible() != 0
return ""
endif
augroup ClangComplete
au! CursorMovedI <buffer>
augroup end
" Do we need to launch UpdateSnippets()?
let l:line = getline(".")
let l:pattern = '<#[^#]*#>'
if match(l:line, l:pattern) == -1
return ""
endif
call feedkeys("\<esc>^\<tab>")
return ""
endfunction
" May be used in a mapping to update the quickfix window.
function g:ClangUpdateQuickFix()
call s:DoPeriodicQuickFix()
return ""
endfunction
" command-t.vim
" Copyright 2010-2014 Wincent Colaiuta. All rights reserved.
"
" Redistribution and use in source and binary forms, with or without
" modification, are permitted provided that the following conditions are met:
"
" 1. Redistributions of source code must retain the above copyright notice,
" this list of conditions and the following disclaimer.
" 2. Redistributions in binary form must reproduce the above copyright notice,
" this list of conditions and the following disclaimer in the documentation
" and/or other materials provided with the distribution.
"
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
" POSSIBILITY OF SUCH DAMAGE.
if exists("g:command_t_loaded") || &cp
finish
endif
let g:command_t_loaded = 1
command CommandTBuffer call <SID>CommandTShowBufferFinder()
command CommandTJump call <SID>CommandTShowJumpFinder()
command CommandTTag call <SID>CommandTShowTagFinder()
command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
command CommandTFlush call <SID>CommandTFlush()
if !hasmapto(':CommandT<CR>')
silent! nnoremap <unique> <silent> <Leader>t :CommandT<CR>
endif
if !hasmapto(':CommandTBuffer<CR>')
silent! nnoremap <unique> <silent> <Leader>b :CommandTBuffer<CR>
endif
function s:CommandTRubyWarning()
echohl WarningMsg
echo "command-t.vim requires Vim to be compiled with Ruby support"
echo "For more information type: :help command-t"
echohl none
endfunction
function s:CommandTShowBufferFinder()
if has('ruby')
ruby $command_t.show_buffer_finder
else
call s:CommandTRubyWarning()
endif
endfunction
function s:CommandTShowFileFinder(arg)
if has('ruby')
ruby $command_t.show_file_finder
else
call s:CommandTRubyWarning()
endif
endfunction
function s:CommandTShowJumpFinder()
if has('ruby')
ruby $command_t.show_jump_finder
else
call s:CommandTRubyWarning()
endif
endfunction
function s:CommandTShowTagFinder()
if has('ruby')
ruby $command_t.show_tag_finder
else
call s:CommandTRubyWarning()
endif
endfunction
function s:CommandTFlush()
if has('ruby')
ruby $command_t.flush
else
call s:CommandTRubyWarning()
endif
endfunction
if !has('ruby')
finish
endif
function CommandTListMatches()
ruby $command_t.list_matches
endfunction
function CommandTHandleKey(arg)
ruby $command_t.handle_key
endfunction
function CommandTBackspace()
ruby $command_t.backspace
endfunction
function CommandTDelete()
ruby $command_t.delete
endfunction
function CommandTAcceptSelection()
ruby $command_t.accept_selection
endfunction
function CommandTAcceptSelectionTab()
ruby $command_t.accept_selection :command => 'tabe'
endfunction
function CommandTAcceptSelectionSplit()
ruby $command_t.accept_selection :command => 'sp'
endfunction
function CommandTAcceptSelectionVSplit()
ruby $command_t.accept_selection :command => 'vs'
endfunction
function CommandTQuickfix()
ruby $command_t.quickfix
endfunction
function CommandTRefresh()
ruby $command_t.refresh
endfunction
function CommandTToggleFocus()
ruby $command_t.toggle_focus
endfunction
function CommandTCancel()
ruby $command_t.cancel
endfunction
function CommandTSelectNext()
ruby $command_t.select_next
endfunction
function CommandTSelectPrev()
ruby $command_t.select_prev
endfunction
function CommandTClear()
ruby $command_t.clear
endfunction
function CommandTCursorLeft()
ruby $command_t.cursor_left
endfunction
function CommandTCursorRight()
ruby $command_t.cursor_right
endfunction
function CommandTCursorEnd()
ruby $command_t.cursor_end
endfunction
function CommandTCursorStart()
ruby $command_t.cursor_start
endfunction
ruby << EOF
# require Ruby files
begin
# prepare controller
require 'command-t/vim'
require 'command-t/controller'
$command_t = CommandT::Controller.new
rescue LoadError
load_path_modified = false
::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
lib = "#{path}/ruby"
if !$LOAD_PATH.include?(lib) and File.exist?(lib)
$LOAD_PATH << lib
load_path_modified = true
end
end
retry if load_path_modified
# could get here if C extension was not compiled, or was compiled
# for the wrong architecture or Ruby version
require 'command-t/stub'
$command_t = CommandT::Stub.new
end
EOF
This diff is collapsed.
This diff is collapsed.
" File: snipMate.vim
" Author: Michael Sanders
" Version: 0.84
" Description: snipMate.vim implements some of TextMate's snippets features in
" 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>".
"
" For more help see snipMate.txt; you can do this by using:
" :helptags ~/.vim/doc
" :h snipMate.txt
if exists('loaded_snips') || &cp || version < 700
finish
endif
let loaded_snips = 1
if !exists('snips_author') | let snips_author = 'Me' | endif
au BufRead,BufNewFile *.snippets\= set ft=snippet
au FileType snippet setl noet fdm=indent
let s:snippets = {} | let s:multi_snips = {}
if !exists('snippets_dir')
let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g')
endif
fun! MakeSnip(scope, trigger, content, ...)
let multisnip = a:0 && a:1 != ''
let var = multisnip ? 's:multi_snips' : 's:snippets'
if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif
if !has_key({var}[a:scope], a:trigger)
let {var}[a:scope][a:trigger] = multisnip ? [[a:1, a:content]] : a:content
elseif multisnip | let {var}[a:scope][a:trigger] += [[a:1, a:content]]
else
echom 'Warning in snipMate.vim: Snippet '.a:trigger.' is already defined.'
\ .' See :h multi_snip for help on snippets with multiple matches.'
endif
endf
fun! ExtractSnips(dir, ft)
for path in split(globpath(a:dir, '*'), "\n")
if isdirectory(path)
let pathname = fnamemodify(path, ':t')
for snipFile in split(globpath(path, '*.snippet'), "\n")
call s:ProcessFile(snipFile, a:ft, pathname)
endfor
elseif fnamemodify(path, ':e') == 'snippet'
call s:ProcessFile(path, a:ft)
endif
endfor
endf
" Processes a single-snippet file; optionally add the name of the parent
" directory for a snippet with multiple matches.
fun s:ProcessFile(file, ft, ...)
let keyword = fnamemodify(a:file, ':t:r')
if keyword == '' | return | endif
try
let text = join(readfile(a:file), "\n")
catch /E484/
echom "Error in snipMate.vim: couldn't read file: ".a:file
endtry
return a:0 ? MakeSnip(a:ft, a:1, text, keyword)
\ : MakeSnip(a:ft, keyword, text)
endf
fun! ExtractSnipsFile(file, ft)
if !filereadable(a:file) | return | endif
let text = readfile(a:file)
let inSnip = 0
for line in text + ["\n"]
if inSnip && (line[0] == "\t" || line == '')
let content .= strpart(line, 1)."\n"
continue
elseif inSnip
call MakeSnip(a:ft, trigger, content[:-2], name)
let inSnip = 0
endif
if line[:6] == 'snippet'
let inSnip = 1
let trigger = strpart(line, 8)
let name = ''
let space = stridx(trigger, ' ') + 1
if space " Process multi snip
let name = strpart(trigger, space)
let trigger = strpart(trigger, 0, space - 1)
endif
let content = ''
endif
endfor
endf
" Reset snippets for filetype.
fun! ResetSnippets(ft)
let ft = a:ft == '' ? '_' : a:ft
for dict in [s:snippets, s:multi_snips, g:did_ft]
if has_key(dict, ft)
unlet dict[ft]
endif
endfor
endf
" Reset snippets for all filetypes.
fun! ResetAllSnippets()
let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {}
endf
" Reload snippets for filetype.
fun! ReloadSnippets(ft)
let ft = a:ft == '' ? '_' : a:ft
call ResetSnippets(ft)
call GetSnippets(g:snippets_dir, ft)
endf
" Reload snippets for all filetypes.
fun! ReloadAllSnippets()
for ft in keys(g:did_ft)
call ReloadSnippets(ft)
endfor
endf
let g:did_ft = {}
fun! GetSnippets(dir, filetypes)
for ft in split(a:filetypes, '\.')
if has_key(g:did_ft, ft) | continue | endif
call s:DefineSnips(a:dir, ft, ft)
if ft == 'objc' || ft == 'cpp' || ft == 'cs'
call s:DefineSnips(a:dir, 'c', ft)
elseif ft == 'xhtml'
call s:DefineSnips(a:dir, 'html', 'xhtml')
endif
let g:did_ft[ft] = 1
endfor
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()
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<tab>"
let SuperTabKey = "\<c-n>"
elseif g:SuperTabMappingBackward == "<tab>"
let SuperTabKey = "\<c-p>"
endif
endif
if pumvisible() " Update snippet if completion is used, or deal with supertab
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
call feedkeys("\<esc>a", 'n') " Close completion menu
call feedkeys("\<tab>") | return ''
endif
if exists('g:snipPos') | return snipMate#jumpTabStop(0) | endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let [trigger, snippet] = s:GetSnippet(word, scope)
" If word is a trigger for a snippet, delete the trigger & expand
" the snippet.
if snippet != ''
let col = col('.') - len(trigger)
sil exe 's/\V'.escape(trigger, '/\.').'\%#//'
return snipMate#expandSnip(snippet, col)
endif
endfor
if exists('SuperTabKey')
call feedkeys(SuperTabKey)
return ''
endif
return "\<tab>"
endf
fun! BackwardsSnippet()
if exists('g:snipPos') | return snipMate#jumpTabStop(1) | endif
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingBackward == "<s-tab>"
let SuperTabKey = "\<c-p>"
elseif g:SuperTabMappingForward == "<s-tab>"
let SuperTabKey = "\<c-n>"
endif
endif
if exists('SuperTabKey')
call feedkeys(SuperTabKey)
return ''
endif
return "\<s-tab>"
endf
" Check if word under cursor is snippet trigger; if it isn't, try checking if
" the text after non-word characters is (e.g. check for "foo" in "bar.foo")
fun s:GetSnippet(word, scope)
let word = a:word | let snippet = ''
while snippet == ''
if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:snippets[a:scope][word]
elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:ChooseSnippet(a:scope, word)
if snippet == '' | break | endif
else
if match(word, '\W') == -1 | break | endif
let word = substitute(word, '.\{-}\W', '', '')
endif
endw
if word == '' && a:word != '.' && stridx(a:word, '.') != -1
let [word, snippet] = s:GetSnippet('.', a:scope)
endif
return [word, snippet]
endf
fun s:ChooseSnippet(scope, trigger)
let snippet = []
let i = 1
for snip in s:multi_snips[a:scope][a:trigger]
let snippet += [i.'. '.snip[0]]
let i += 1
endfor
if i == 2 | return s:multi_snips[a:scope][a:trigger][0][1] | endif
let num = inputlist(snippet) - 1
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
endf
fun! ShowAvailableSnips()
let line = getline('.')
let col = col('.')
let word = matchstr(getline('.'), '\S\+\%'.col.'c')
let words = [word]
if stridx(word, '.')
let words += split(word, '\.', 1)
endif
let matchlen = 0
let matches = []
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let triggers = has_key(s:snippets, scope) ? keys(s:snippets[scope]) : []
if has_key(s:multi_snips, scope)
let triggers += keys(s:multi_snips[scope])
endif
for trigger in triggers
for word in words
if word == ''
let matches += [trigger] " Show all matches if word is empty
elseif trigger =~ '^'.word
let matches += [trigger]
let len = len(word)
if len > matchlen | let matchlen = len | endif
endif
endfor
endfor
endfor
" This is to avoid a bug with Vim when using complete(col - matchlen, matches)
" (Issue#46 on the Google Code snipMate issue tracker).
call setline(line('.'), substitute(line, repeat('.', matchlen).'\%'.col.'c', '', ''))
call complete(col, matches)
return ''
endf
" vim:noet:sw=4:ts=4:ft=vim
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment