fortran.vim 5.1 KB

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