1
0
mirror of https://github.com/amix/vimrc synced 2025-07-09 02:25:00 +08:00

Adding submodules and stuff.

This commit is contained in:
Maksim Pecherskiy
2014-02-24 22:22:30 -04:00
parent c07dfbf9d7
commit 17b77b08b1
150 changed files with 11141 additions and 120 deletions

View File

@ -0,0 +1,239 @@
if exists("g:loaded_syntastic_c_autoload")
finish
endif
let g:loaded_syntastic_c_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
" initialize c/cpp syntax checker handlers
function! s:Init()
let s:handlers = []
let s:cflags = {}
call s:RegHandler('gtk', 'syntastic#c#CheckPKG',
\ ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
call s:RegHandler('glib', 'syntastic#c#CheckPKG',
\ ['glib', 'glib-2.0', 'glib'])
call s:RegHandler('glade', 'syntastic#c#CheckPKG',
\ ['glade', 'libglade-2.0', 'libglade'])
call s:RegHandler('libsoup', 'syntastic#c#CheckPKG',
\ ['libsoup', 'libsoup-2.4', 'libsoup-2.2'])
call s:RegHandler('webkit', 'syntastic#c#CheckPKG',
\ ['webkit', 'webkit-1.0'])
call s:RegHandler('cairo', 'syntastic#c#CheckPKG',
\ ['cairo', 'cairo'])
call s:RegHandler('pango', 'syntastic#c#CheckPKG',
\ ['pango', 'pango'])
call s:RegHandler('libxml', 'syntastic#c#CheckPKG',
\ ['libxml', 'libxml-2.0', 'libxml'])
call s:RegHandler('freetype', 'syntastic#c#CheckPKG',
\ ['freetype', 'freetype2', 'freetype'])
call s:RegHandler('SDL', 'syntastic#c#CheckPKG',
\ ['sdl', 'sdl'])
call s:RegHandler('opengl', 'syntastic#c#CheckPKG',
\ ['opengl', 'gl'])
call s:RegHandler('ruby', 'syntastic#c#CheckRuby', [])
call s:RegHandler('Python\.h', 'syntastic#c#CheckPython', [])
call s:RegHandler('php\.h', 'syntastic#c#CheckPhp', [])
endfunction
" default include directories
let s:default_includes = [ '.', '..', 'include', 'includes',
\ '../include', '../includes' ]
" convenience function to determine the 'null device' parameter
" based on the current operating system
function! syntastic#c#GetNullDevice()
if has('win32')
return '-o nul'
elseif has('unix') || has('mac')
return '-o /dev/null'
endif
return ''
endfunction
" get the gcc include directory argument depending on the default
" includes and the optional user-defined 'g:syntastic_c_include_dirs'
function! syntastic#c#GetIncludeDirs(filetype)
let include_dirs = []
if !exists('g:syntastic_'.a:filetype.'_no_default_include_dirs') ||
\ !g:syntastic_{a:filetype}_no_default_include_dirs
let include_dirs = copy(s:default_includes)
endif
if exists('g:syntastic_'.a:filetype.'_include_dirs')
call extend(include_dirs, g:syntastic_{a:filetype}_include_dirs)
endif
return join(map(syntastic#util#unique(include_dirs), '"-I" . v:val'), ' ')
endfunction
" read additional compiler flags from the given configuration file
" the file format and its parsing mechanism is inspired by clang_complete
function! syntastic#c#ReadConfig(file)
" search in the current file's directory upwards
let config = findfile(a:file, '.;')
if config == '' || !filereadable(config) | return '' | endif
" convert filename into absolute path
let filepath = substitute(fnamemodify(config, ':p:h'), '\', '/', 'g')
" try to read config file
try
let lines = map(readfile(config),
\ 'substitute(v:val, ''\'', ''/'', ''g'')')
catch /E484/
return ''
endtry
let parameters = []
for line in lines
let matches = matchlist(line, '\C^\s*-I\s*\(\S\+\)')
if matches != [] && matches[1] != ''
" this one looks like an absolute path
if match(matches[1], '^\%(/\|\a:\)') != -1
call add(parameters, '-I' . matches[1])
else
call add(parameters, '-I' . filepath . '/' . matches[1])
endif
else
call add(parameters, line)
endif
endfor
return join(parameters, ' ')
endfunction
" search the first 100 lines for include statements that are
" given in the handlers dictionary
function! syntastic#c#SearchHeaders()
let includes = ''
let files = []
let found = []
let lines = filter(getline(1, 100), 'v:val =~# "#\s*include"')
" search current buffer
for line in lines
let file = matchstr(line, '"\zs\S\+\ze"')
if file != ''
call add(files, file)
continue
endif
for handler in s:handlers
if line =~# handler["regex"]
let includes .= call(handler["func"], handler["args"])
call add(found, handler["regex"])
break
endif
endfor
endfor
" search included headers
for hfile in files
if hfile != ''
let filename = expand('%:p:h') . (has('win32') ?
\ '\' : '/') . hfile
try
let lines = readfile(filename, '', 100)
catch /E484/
continue
endtry
let lines = filter(lines, 'v:val =~# "#\s*include"')
for handler in s:handlers
if index(found, handler["regex"]) != -1
continue
endif
for line in lines
if line =~# handler["regex"]
let includes .= call(handler["func"], handler["args"])
call add(found, handler["regex"])
break
endif
endfor
endfor
endif
endfor
return includes
endfunction
" try to find library with 'pkg-config'
" search possible libraries from first to last given
" argument until one is found
function! syntastic#c#CheckPKG(name, ...)
if executable('pkg-config')
if !has_key(s:cflags, a:name)
for i in range(a:0)
let l:cflags = system('pkg-config --cflags '.a:000[i])
" since we cannot necessarily trust the pkg-config exit code
" we have to check for an error output as well
if v:shell_error == 0 && l:cflags !~? 'not found'
let l:cflags = ' '.substitute(l:cflags, "\n", '', '')
let s:cflags[a:name] = l:cflags
return l:cflags
endif
endfor
else
return s:cflags[a:name]
endif
endif
return ''
endfunction
" try to find PHP includes with 'php-config'
function! syntastic#c#CheckPhp()
if executable('php-config')
if !exists('s:php_flags')
let s:php_flags = system('php-config --includes')
let s:php_flags = ' ' . substitute(s:php_flags, "\n", '', '')
endif
return s:php_flags
endif
return ''
endfunction
" try to find the ruby headers with 'rbconfig'
function! syntastic#c#CheckRuby()
if executable('ruby')
if !exists('s:ruby_flags')
let s:ruby_flags = system('ruby -r rbconfig -e '
\ . '''puts Config::CONFIG["archdir"]''')
let s:ruby_flags = substitute(s:ruby_flags, "\n", '', '')
let s:ruby_flags = ' -I' . s:ruby_flags
endif
return s:ruby_flags
endif
return ''
endfunction
" try to find the python headers with distutils
function! syntastic#c#CheckPython()
if executable('python')
if !exists('s:python_flags')
let s:python_flags = system('python -c ''from distutils import '
\ . 'sysconfig; import sys; sys.stdout.write(sysconfig.get_python_inc())''')
let s:python_flags = substitute(s:python_flags, "\n", '', '')
let s:python_flags = ' -I' . s:python_flags
endif
return s:python_flags
endif
return ''
endfunction
" return a handler dictionary object
function! s:RegHandler(regex, function, args)
let handler = {}
let handler["regex"] = a:regex
let handler["func"] = function(a:function)
let handler["args"] = a:args
call add(s:handlers, handler)
endfunction
call s:Init()
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,50 @@
if exists("g:loaded_syntastic_makeprg_autoload")
finish
endif
let g:loaded_syntastic_makeprg_autoload = 1
"Returns a makeprg of the form
"
"[exe] [args] [filename] [post_args] [tail]
"
"A (made up) example:
" ruby -a -b -c test_file.rb --more --args > /tmp/output
"
"To generate this you would call:
"
" let makeprg = syntastic#makeprg#build({
" \ 'exe': 'ruby',
" \ 'args': '-a -b -c',
" \ 'post_args': '--more --args',
" \ 'tail': '> /tmp/output',
" \ 'filetype': 'ruby',
" \ 'subchecker': 'mri' })
"
"Note that the current filename is added by default - but can be overridden by
"passing in an 'fname' arg.
"
"Arguments 'filetype' and 'subchecker' are mandatory, handling of composite
"types and user-defined variables breaks if you omit them.
"
"All other options can be overriden by the user with global variables - even
"when not specified by the checker in syntastic#makeprg#build().
"
"E.g. They could override the checker exe with
"
" let g:syntastic_ruby_mri_exe="another_ruby_checker_exe.rb"
"
"The general form of the override option is:
" syntastic_[filetype]_[subchecker]_[option-name]
"
function! syntastic#makeprg#build(opts)
let builder = g:SyntasticMakeprgBuilder.New(
\ get(a:opts, 'exe', ''),
\ get(a:opts, 'args', ''),
\ get(a:opts, 'fname', ''),
\ get(a:opts, 'post_args', ''),
\ get(a:opts, 'tail', ''),
\ get(a:opts, 'filetype', ''),
\ get(a:opts, 'subchecker', '') )
return builder.makeprg()
endfunction

View File

@ -0,0 +1,58 @@
if exists("g:loaded_syntastic_postprocess_autoload")
finish
endif
let g:loaded_syntastic_postprocess_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
function! s:compareErrorItems(a, b)
if a:a['bufnr'] != a:b['bufnr']
" group by files
return a:a['bufnr'] - a:b['bufnr']
elseif a:a['lnum'] != a:b['lnum']
return a:a['lnum'] - a:b['lnum']
elseif a:a['type'] !=? a:b['type']
" errors take precedence over warnings
return a:a['type'] ==? 'e' ? -1 : 1
else
return get(a:a, 'col') - get(a:b, 'col')
endif
endfunction
" natural sort
function! syntastic#postprocess#sort(errors)
return sort(a:errors, 's:compareErrorItems')
endfunction
function syntastic#postprocess#compressWhitespace(errors)
let llist = []
for e in a:errors
let e['text'] = substitute(e['text'], '\n', ' ', 'g')
let e['text'] = substitute(e['text'], '\s\{2,}', ' ', 'g')
call add(llist, e)
endfor
return llist
endfunction
" remove spurious CR under Cygwin
function! syntastic#postprocess#cygwinRemoveCR(errors)
if has('win32unix')
let llist = []
for e in a:errors
let e['text'] = substitute(e['text'], '\r', '', 'g')
call add(llist, e)
endfor
else
let llist = a:errors
endif
return llist
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,201 @@
if exists("g:loaded_syntastic_util_autoload")
finish
endif
let g:loaded_syntastic_util_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
if !exists("g:syntastic_debug")
let g:syntastic_debug = 0
endif
let s:deprecationNoticesIssued = []
function! syntastic#util#DevNull()
if has('win32')
return 'NUL'
endif
return '/dev/null'
endfunction
"search the first 5 lines of the file for a magic number and return a map
"containing the args and the executable
"
"e.g.
"
"#!/usr/bin/perl -f -bar
"
"returns
"
"{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
function! syntastic#util#parseShebang()
for lnum in range(1,5)
let line = getline(lnum)
if line =~ '^#!'
let exe = matchstr(line, '^#!\s*\zs[^ \t]*')
let args = split(matchstr(line, '^#!\s*[^ \t]*\zs.*'))
return {'exe': exe, 'args': args}
endif
endfor
return {'exe': '', 'args': []}
endfunction
" Run 'command' in a shell and parse output as a version string.
" Returns an array of version components.
function! syntastic#util#parseVersion(command)
return split(matchstr( system(a:command), '\v^\D*\zs\d+(\.\d+)+\ze' ), '\.')
endfunction
" Verify that the 'installed' version is at least the 'required' version.
"
" 'installed' and 'required' must be arrays. If they have different lengths,
" the "missing" elements will be assumed to be 0 for the purposes of checking.
"
" See http://semver.org for info about version numbers.
function! syntastic#util#versionIsAtLeast(installed, required)
for index in range(max([len(a:installed), len(a:required)]))
if len(a:installed) <= index
let installed_element = 0
else
let installed_element = a:installed[index]
endif
if len(a:required) <= index
let required_element = 0
else
let required_element = a:required[index]
endif
if installed_element != required_element
return installed_element > required_element
endif
endfor
" Everything matched, so it is at least the required version.
return 1
endfunction
"print as much of a:msg as possible without "Press Enter" prompt appearing
function! syntastic#util#wideMsg(msg)
let old_ruler = &ruler
let old_showcmd = &showcmd
"convert tabs to spaces so that the tabs count towards the window width
"as the proper amount of characters
let msg = substitute(a:msg, "\t", repeat(" ", &tabstop), "g")
let msg = strpart(msg, 0, winwidth(0)-1)
"This is here because it is possible for some error messages to begin with
"\n which will cause a "press enter" prompt. I have noticed this in the
"javascript:jshint checker and have been unable to figure out why it
"happens
let msg = substitute(msg, "\n", "", "g")
set noruler noshowcmd
redraw
echo msg
let &ruler=old_ruler
let &showcmd=old_showcmd
endfunction
" Check whether a buffer is loaded, listed, and not hidden
function! syntastic#util#bufIsActive(buffer)
" convert to number, or hell breaks loose
let buf = str2nr(a:buffer)
if !bufloaded(buf) || !buflisted(buf)
return 0
endif
" get rid of hidden buffers
for tab in range(1, tabpagenr('$'))
if index(tabpagebuflist(tab), buf) >= 0
return 1
endif
endfor
return 0
endfunction
" start in directory a:where and walk up the parent folders until it
" finds a file matching a:what; return path to that file
function! syntastic#util#findInParent(what, where)
let here = fnamemodify(a:where, ':p')
while !empty(here)
let p = split(globpath(here, a:what), '\n')
if !empty(p)
return fnamemodify(p[0], ':p')
elseif here == '/'
break
endif
" we use ':h:h' rather than ':h' since ':p' adds a trailing '/'
" if 'here' is a directory
let here = fnamemodify(here, ':p:h:h')
endwhile
return ''
endfunction
" Returns unique elements in a list
function! syntastic#util#unique(list)
let seen = {}
let uniques = []
for e in a:list
if !has_key(seen, e)
let seen[e] = 1
call add(uniques, e)
endif
endfor
return uniques
endfunction
" A less noisy shellescape()
function! syntastic#util#shescape(string)
return a:string =~ '\m^[A-Za-z0-9_/.-]\+$' ? a:string : shellescape(a:string, 1)
endfunction
" A less noisy shellescape(expand())
function! syntastic#util#shexpand(string)
return syntastic#util#shescape(escape(expand(a:string), '|'))
endfunction
function! syntastic#util#debug(msg)
if g:syntastic_debug
echomsg "syntastic: debug: " . a:msg
endif
endfunction
function! syntastic#util#info(msg)
echomsg "syntastic: info: " . a:msg
endfunction
function! syntastic#util#warn(msg)
echohl WarningMsg
echomsg "syntastic: warning: " . a:msg
echohl None
endfunction
function! syntastic#util#error(msg)
execute "normal \<Esc>"
echohl ErrorMsg
echomsg "syntastic: error: " . a:msg
echohl None
endfunction
function! syntastic#util#deprecationWarn(msg)
if index(s:deprecationNoticesIssued, a:msg) >= 0
return
endif
call add(s:deprecationNoticesIssued, a:msg)
call syntastic#util#warn(a:msg)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4: