1
0

ghc-mod.vim 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "============================================================================
  2. "File: ghc-mod.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Anthony Carapetis <anthony.carapetis 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_haskell_ghc_mod_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_haskell_ghc_mod_checker = 1
  16. let s:ghc_mod_new = -1
  17. let s:save_cpo = &cpo
  18. set cpo&vim
  19. function! SyntaxCheckers_haskell_ghc_mod_IsAvailable() dict
  20. if !executable(self.getExec())
  21. return 0
  22. endif
  23. " ghc-mod 5.0.0 and later needs the "version" command to print the
  24. " version. But the "version" command appeared in 4.1.0. Thus, we need to
  25. " know the version in order to know how to find out the version. :)
  26. " Try "ghc-mod version".
  27. let ver = filter(split(syntastic#util#system(self.getExecEscaped() . ' version'), '\n'), 'v:val =~# ''\m\sversion''')
  28. if !len(ver)
  29. " That didn't work. Try "ghc-mod" alone.
  30. let ver = filter(split(syntastic#util#system(self.getExecEscaped()), '\n'), 'v:val =~# ''\m\sversion''')
  31. endif
  32. if len(ver)
  33. " Encouraged by the great success in finding out the version, now we
  34. " need either a Vim that can handle NULs in system() output, or a
  35. " ghc-mod that has the "--boundary" option.
  36. let parsed_ver = syntastic#util#parseVersion(ver[0])
  37. call self.setVersion(parsed_ver)
  38. let s:ghc_mod_new = syntastic#util#versionIsAtLeast(parsed_ver, [2, 1, 2])
  39. else
  40. call syntastic#log#error("checker haskell/ghc_mod: can't parse version string (abnormal termination?)")
  41. let s:ghc_mod_new = -1
  42. endif
  43. return (s:ghc_mod_new >= 0) && (v:version >= 704 || s:ghc_mod_new)
  44. endfunction
  45. function! SyntaxCheckers_haskell_ghc_mod_GetLocList() dict
  46. let makeprg = self.makeprgBuild({
  47. \ 'exe': self.getExecEscaped() . ' check' . (s:ghc_mod_new ? ' --boundary=""' : '') })
  48. let errorformat =
  49. \ '%-G%\s%#,' .
  50. \ '%f:%l:%c:%trror: %m,' .
  51. \ '%f:%l:%c:%tarning: %m,'.
  52. \ '%f:%l:%c: %trror: %m,' .
  53. \ '%f:%l:%c: %tarning: %m,' .
  54. \ '%f:%l:%c:%m,' .
  55. \ '%E%f:%l:%c:,' .
  56. \ '%Z%m'
  57. return SyntasticMake({
  58. \ 'makeprg': makeprg,
  59. \ 'errorformat': errorformat,
  60. \ 'postprocess': ['compressWhitespace'],
  61. \ 'returns': [0] })
  62. endfunction
  63. call g:SyntasticRegistry.CreateAndRegisterChecker({
  64. \ 'filetype': 'haskell',
  65. \ 'name': 'ghc_mod',
  66. \ 'exec': 'ghc-mod' })
  67. let &cpo = s:save_cpo
  68. unlet s:save_cpo
  69. " vim: set sw=4 sts=4 et fdm=marker: