yamlxs.vim 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "============================================================================
  2. "File: yamlxs.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  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() . ' -e ' . syntastic#util#shescape('exit(0)'))
  28. return v:shell_error == 0
  29. endfunction
  30. function! SyntaxCheckers_yaml_yamlxs_GetLocList() dict
  31. let makeprg = self.makeprgBuild({
  32. \ 'args_before': s:Modules() . ' -e ' . syntastic#util#shescape('YAML::XS::LoadFile($ARGV[0])') })
  33. let errorformat =
  34. \ '%EYAML::XS::Load Error: The problem:,' .
  35. \ '%-C,' .
  36. \ '%C %m,' .
  37. \ '%Cwas found at document: %\d%\+\, line: %l\, column: %c,' .
  38. \ '%-G%.%#'
  39. return SyntasticMake({
  40. \ 'makeprg': makeprg,
  41. \ 'errorformat': errorformat,
  42. \ 'postprocess': ['compressWhitespace'],
  43. \ 'defaults': {'bufnr': bufnr('')} })
  44. endfunction
  45. function s:Modules()
  46. if type(g:syntastic_perl_lib_path) == type('')
  47. call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list')
  48. let includes = split(g:syntastic_perl_lib_path, ',')
  49. else
  50. let includes = copy(syntastic#util#var('perl_lib_path'))
  51. endif
  52. return join(map(includes, '"-I" . v:val') + ['-MYAML::XS'])
  53. endfunction
  54. call g:SyntasticRegistry.CreateAndRegisterChecker({
  55. \ 'filetype': 'yaml',
  56. \ 'name': 'yamlxs',
  57. \ 'exec': 'perl' })
  58. let &cpo = s:save_cpo
  59. unlet s:save_cpo
  60. " vim: set sw=4 sts=4 et fdm=marker: