gfortran.vim 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "============================================================================
  2. "File: fortran.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Karl Yngve Lervåg <karl.yngve@lervag.net>
  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_fortran_gfortran_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_fortran_gfortran_checker = 1
  16. if !exists('g:syntastic_fortran_compiler_options')
  17. let g:syntastic_fortran_compiler_options = ''
  18. endif
  19. let s:type_map = {}
  20. let s:save_cpo = &cpo
  21. set cpo&vim
  22. function! SyntaxCheckers_fortran_gfortran_IsAvailable() dict " {{{1
  23. if !exists('g:syntastic_fortran_compiler')
  24. let g:syntastic_fortran_compiler = self.getExec()
  25. endif
  26. call self.log('g:syntastic_fortran_compiler = ', g:syntastic_fortran_compiler)
  27. return executable(expand(g:syntastic_fortran_compiler, 1))
  28. endfunction " }}}1
  29. " @vimlint(EVL104, 1, l:errorformat)
  30. function! SyntaxCheckers_fortran_gfortran_GetLocList() dict " {{{1
  31. call s:SetCompilerType(g:syntastic_fortran_compiler)
  32. if !has_key(s:type_map, g:syntastic_fortran_compiler)
  33. call syntastic#log#error("checker fortran/gfortran: can't parse version string (abnormal termination?)")
  34. return []
  35. endif
  36. if s:type_map[g:syntastic_fortran_compiler] ==# 'gfortran'
  37. let errorformat =
  38. \ '%-C %#,'.
  39. \ '%-C %#%.%#,'.
  40. \ '%A%f:%l%[.:]%c:,'.
  41. \ '%Z%\m%\%%(Fatal %\)%\?%trror: %m,'.
  42. \ '%Z%tarning: %m,'.
  43. \ '%-G%.%#'
  44. if !exists('g:syntastic_fortran_gfortran_sort')
  45. let g:syntastic_fortran_gfortran_sort = 0
  46. endif
  47. elseif s:type_map[g:syntastic_fortran_compiler] ==# 'ifort'
  48. let errorformat =
  49. \ '%E%f(%l): error #%n: %m,'.
  50. \ '%W%f(%l): warning #%n: %m,'.
  51. \ '%W%f(%l): remark #%n: %m,'.
  52. \ '%-Z%p^,'.
  53. \ '%-G%.%#'
  54. if !exists('g:syntastic_fortran_gfortran_sort')
  55. let g:syntastic_fortran_gfortran_sort = 1
  56. endif
  57. endif
  58. return syntastic#c#GetLocList('fortran', 'gfortran', {
  59. \ 'errorformat': errorformat,
  60. \ 'main_flags': '-fsyntax-only' })
  61. endfunction " }}}1
  62. " @vimlint(EVL104, 0, l:errorformat)
  63. " Utilities {{{1
  64. function! s:SetCompilerType(exe) " {{{2
  65. if !has_key(s:type_map, a:exe)
  66. try
  67. let ver = filter( split(syntastic#util#system(syntastic#util#shescape(a:exe) . ' --version'), '\n'),
  68. \ 'v:val =~# "\\v^%(GNU Fortran|ifort) "' )[0]
  69. if ver =~# '\m^GNU Fortran '
  70. let s:type_map[a:exe] = 'gfortran'
  71. elseif ver =~# '\m^ifort '
  72. let s:type_map[a:exe] = 'ifort'
  73. endif
  74. catch /\m^Vim\%((\a\+)\)\=:E684/
  75. " do nothing
  76. endtry
  77. endif
  78. endfunction " }}}2
  79. " }}}
  80. call g:SyntasticRegistry.CreateAndRegisterChecker({
  81. \ 'filetype': 'fortran',
  82. \ 'name': 'gfortran' })
  83. let &cpo = s:save_cpo
  84. unlet s:save_cpo
  85. " vim: set sw=4 sts=4 et fdm=marker: