yamlxs.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "============================================================================
  2. "File: yamlxs.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: LCD 47 <lcd047 at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_yaml_yamlxs_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_yaml_yamlxs_checker = 1
  16. if !exists('g:syntastic_perl_lib_path')
  17. let g:syntastic_perl_lib_path = []
  18. endif
  19. let s:save_cpo = &cpo
  20. set cpo&vim
  21. function! SyntaxCheckers_yaml_yamlxs_IsAvailable() dict
  22. if !exists('g:syntastic_yaml_yamlxs_exec') && exists('g:syntastic_perl_interpreter')
  23. let g:syntastic_yaml_yamlxs_exec = g:syntastic_perl_interpreter
  24. endif
  25. " don't call executable() here, to allow things like
  26. " let g:syntastic_perl_interpreter='/usr/bin/env perl'
  27. silent! call syntastic#util#system(self.getExecEscaped() . ' ' . s:Modules(bufnr('')) . ' -e ' . syntastic#util#shescape('exit(0)'))
  28. return v:shell_error == 0
  29. endfunction
  30. function! SyntaxCheckers_yaml_yamlxs_GetLocList() dict
  31. let buf = bufnr('')
  32. let makeprg = self.makeprgBuild({
  33. \ 'args_before': s:Modules(buf) . ' -e ' . syntastic#util#shescape('YAML::XS::LoadFile($ARGV[0])') })
  34. let errorformat =
  35. \ '%EYAML::XS::Load Error: The problem:,' .
  36. \ '%-C,' .
  37. \ '%C %m,' .
  38. \ '%Cwas found at document: %\d%\+\, line: %l\, column: %c,' .
  39. \ '%-G%.%#'
  40. return SyntasticMake({
  41. \ 'makeprg': makeprg,
  42. \ 'errorformat': errorformat,
  43. \ 'postprocess': ['compressWhitespace'],
  44. \ 'defaults': {'bufnr': bufnr('')} })
  45. endfunction
  46. function s:Modules(buf)
  47. let lib_path = syntastic#util#bufVar(a:buf, 'perl_lib_path')
  48. if type(lib_path) == type('')
  49. call syntastic#log#oneTimeWarn('variable syntastic_perl_lib_path should be a list')
  50. let includes = split(lib_path, ',')
  51. else
  52. let includes = copy(lib_path)
  53. endif
  54. return join(map(includes, '"-I" . v:val') + ['-MYAML::XS'])
  55. endfunction
  56. call g:SyntasticRegistry.CreateAndRegisterChecker({
  57. \ 'filetype': 'yaml',
  58. \ 'name': 'yamlxs',
  59. \ 'exec': 'perl' })
  60. let &cpo = s:save_cpo
  61. unlet s:save_cpo
  62. " vim: set sw=4 sts=4 et fdm=marker: