fortran.vim 5.7 KB

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