fortran.vim 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. " Vim settings file
  2. " Language: Fortran 2008 (and older: Fortran 2003, 95, 90, 77, 66)
  3. " Version: 0.50
  4. " Last Change: 2015 Nov. 30
  5. " Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
  6. " Usage: For instructions, do :help fortran-plugin from Vim
  7. " Credits:
  8. " Useful suggestions were made by Stefano Zacchiroli, Hendrik Merx, Ben
  9. " Fritz, and David Barnett.
  10. " Only do these settings when not done yet for this buffer
  11. if exists("b:did_ftplugin")
  12. finish
  13. endif
  14. let s:cposet=&cpoptions
  15. set cpoptions&vim
  16. " Don't do other file type settings for this buffer
  17. let b:did_ftplugin = 1
  18. " Determine whether this is a fixed or free format source file
  19. " if this hasn't been done yet using the priority:
  20. " buffer-local value
  21. " > global value
  22. " > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
  23. if !exists("b:fortran_fixed_source")
  24. if exists("fortran_free_source")
  25. " User guarantees free source form
  26. let b:fortran_fixed_source = 0
  27. elseif exists("fortran_fixed_source")
  28. " User guarantees fixed source form
  29. let b:fortran_fixed_source = 1
  30. elseif expand("%:e") ==? "f\<90\|95\|03\|08\>"
  31. " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
  32. let b:fortran_fixed_source = 0
  33. elseif expand("%:e") ==? "f\|f77\|for"
  34. " Fixed-form file extension defaults
  35. let b:fortran_fixed_source = 1
  36. else
  37. " Modern fortran still allows both fixed and free source form
  38. " Assume fixed source form unless signs of free source form
  39. " are detected in the first five columns of the first s:lmax lines.
  40. " Detection becomes more accurate and time-consuming if more lines
  41. " are checked. Increase the limit below if you keep lots of comments at
  42. " the very top of each file and you have a fast computer.
  43. let s:lmax = 500
  44. if ( s:lmax > line("$") )
  45. let s:lmax = line("$")
  46. endif
  47. let b:fortran_fixed_source = 1
  48. let s:ln=1
  49. while s:ln <= s:lmax
  50. let s:test = strpart(getline(s:ln),0,5)
  51. if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
  52. let b:fortran_fixed_source = 0
  53. break
  54. endif
  55. let s:ln = s:ln + 1
  56. endwhile
  57. unlet! s:lmax s:ln s:test
  58. endif
  59. endif
  60. " Set comments and textwidth according to source type
  61. if (b:fortran_fixed_source == 1)
  62. setlocal comments=:!,:*,:C
  63. " Fixed format requires a textwidth of 72 for code
  64. setlocal tw=72
  65. " If you need to add "&" on continued lines so that the code is
  66. " compatible with both free and fixed format, then you should do so
  67. " in column 73 and uncomment the next line
  68. " setlocal tw=73
  69. else
  70. setlocal comments=:!
  71. " Free format allows a textwidth of 132
  72. setlocal tw=132
  73. endif
  74. " Set commentstring for foldmethod=marker
  75. setlocal cms=!%s
  76. " Tabs are not a good idea in Fortran so the default is to expand tabs
  77. if !exists("fortran_have_tabs")
  78. setlocal expandtab
  79. endif
  80. " Set 'formatoptions' to break text lines
  81. setlocal fo+=t
  82. setlocal include=^\\c#\\=\\s*include\\s\\+
  83. setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
  84. " Define patterns for the matchit plugin
  85. if !exists("b:match_words")
  86. let s:notend = '\%(\<end\s\+\)\@<!'
  87. let s:notselect = '\%(\<select\s\+\)\@<!'
  88. let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
  89. let s:notprocedure = '\%(\s\+procedure\>\)\@!'
  90. let b:match_ignorecase = 1
  91. let b:match_words =
  92. \ '(:),' .
  93. \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
  94. \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
  95. \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'.
  96. \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
  97. \ s:notend . '\<do\>:\<end\s*do\>,'.
  98. \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
  99. \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
  100. \ s:notend . '\<forall\>:\<end\s*forall\>,'.
  101. \ s:notend . '\<associate\>:\<end\s*associate\>,'.
  102. \ s:notend . '\<enum\>:\<end\s*enum\>,'.
  103. \ s:notend . '\<interface\>:\<end\s*interface\>,'.
  104. \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
  105. \ s:notend . '\<function\>:\<end\s*function\>,'.
  106. \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
  107. \ s:notend . '\<program\>:\<end\s*program\>'
  108. endif
  109. " File filters for :browse e
  110. if has("gui_win32") && !exists("b:browsefilter")
  111. let b:browsefilter = "Fortran Files (*.f;*.for;*.f77;*.f90;*.f95;*.f03;*.f08;*.fpp;*.ftn)\t*.f;*.for;*.f77;*.f90;*.f95;*.f03;*.f08;*.fpp;*.ftn\n" .
  112. \ "All Files (*.*)\t*.*\n"
  113. endif
  114. let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
  115. \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
  116. let &cpoptions=s:cposet
  117. unlet s:cposet
  118. " vim:sw=2