blob: a057db9a4bf1231a63c1eeb1cfa67c3dcfaa08d7 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim settings file
Bram Moolenaard38b0552012-04-25 19:07:41 +02002" Language: Fortran 2008 (and older: Fortran 2003, 95, 90, 77, 66)
Ajit-Thakkar68630842023-12-05 23:07:27 +01003" Version: (v54) 2023 December 5
4" Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/>
5" Joshua Hollett <j.hollett@uwinnipeg.ca>
Bram Moolenaar256972a2015-12-29 19:10:25 +01006" Usage: For instructions, do :help fortran-plugin from Vim
Bram Moolenaar365bdf72010-07-24 20:57:44 +02007" Credits:
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +02008" 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,
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020011" Doug Kearns, and Fritz Reese.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012
13" Only do these settings when not done yet for this buffer
14if exists("b:did_ftplugin")
15 finish
16endif
17
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010018let s:cposet=&cpoptions
19set cpoptions&vim
20
Bram Moolenaar071d4272004-06-13 20:20:40 +000021" Don't do other file type settings for this buffer
22let b:did_ftplugin = 1
23
24" Determine whether this is a fixed or free format source file
Bram Moolenaar256972a2015-12-29 19:10:25 +010025" if this hasn't been done yet using the priority:
26" buffer-local value
27" > global value
28" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
Bram Moolenaar071d4272004-06-13 20:20:40 +000029if !exists("b:fortran_fixed_source")
30 if exists("fortran_free_source")
31 " User guarantees free source form
32 let b:fortran_fixed_source = 0
33 elseif exists("fortran_fixed_source")
34 " User guarantees fixed source form
35 let b:fortran_fixed_source = 1
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020036 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010037 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
38 let b:fortran_fixed_source = 0
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020039 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010040 " Fixed-form file extension defaults
41 let b:fortran_fixed_source = 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000042 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010043 " Modern fortran compilers still allow both fixed and free source form
Bram Moolenaar256972a2015-12-29 19:10:25 +010044 " Assume fixed source form unless signs of free source form
45 " are detected in the first five columns of the first s:lmax lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +000046 " Detection becomes more accurate and time-consuming if more lines
47 " are checked. Increase the limit below if you keep lots of comments at
Bram Moolenaar256972a2015-12-29 19:10:25 +010048 " the very top of each file and you have a fast computer.
Bram Moolenaar365bdf72010-07-24 20:57:44 +020049 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 if ( s:lmax > line("$") )
51 let s:lmax = line("$")
52 endif
53 let b:fortran_fixed_source = 1
54 let s:ln=1
55 while s:ln <= s:lmax
56 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020057 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000058 let b:fortran_fixed_source = 0
59 break
60 endif
61 let s:ln = s:ln + 1
62 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020063 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 endif
65endif
66
67" Set comments and textwidth according to source type
68if (b:fortran_fixed_source == 1)
69 setlocal comments=:!,:*,:C
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020070 " Fixed format requires a textwidth of 72 for code,
71 " but some vendor extensions allow longer lines
72 if exists("fortran_extended_line_length")
73 setlocal tw=132
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020074 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010075 " The use of columns 73-80 for sequence numbers is obsolete
76 " so almost all compilers allow a textwidth of 80
77 setlocal tw=80
Bram Moolenaar071d4272004-06-13 20:20:40 +000078 " If you need to add "&" on continued lines so that the code is
79 " compatible with both free and fixed format, then you should do so
Ajit-Thakkar68630842023-12-05 23:07:27 +010080 " in column 81 and uncomment the next line
81 " setlocal tw=81
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020082 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000083else
84 setlocal comments=:!
Bram Moolenaarb1332082013-10-06 14:22:40 +020085 " Free format allows a textwidth of 132
86 setlocal tw=132
Bram Moolenaar071d4272004-06-13 20:20:40 +000087endif
88
89" Set commentstring for foldmethod=marker
90setlocal cms=!%s
91
92" Tabs are not a good idea in Fortran so the default is to expand tabs
93if !exists("fortran_have_tabs")
94 setlocal expandtab
95endif
96
Bram Moolenaarb1332082013-10-06 14:22:40 +020097" Set 'formatoptions' to break text lines
98setlocal fo+=t
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000100setlocal include=^\\c#\\=\\s*include\\s\\+
Bram Moolenaard38b0552012-04-25 19:07:41 +0200101setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103" Define patterns for the matchit plugin
104if !exists("b:match_words")
105 let s:notend = '\%(\<end\s\+\)\@<!'
106 let s:notselect = '\%(\<select\s\+\)\@<!'
107 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000108 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100109 let s:nothash = '\%(^\s*#\s*\)\@<!'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110 let b:match_ignorecase = 1
111 let b:match_words =
Bram Moolenaard38b0552012-04-25 19:07:41 +0200112 \ '(:),' .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
114 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100115 \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
117 \ s:notend . '\<do\>:\<end\s*do\>,'.
118 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
119 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200120 \ s:notend . '\<forall\>:\<end\s*forall\>,'.
121 \ s:notend . '\<associate\>:\<end\s*associate\>,'.
122 \ s:notend . '\<enum\>:\<end\s*enum\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
124 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
125 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000126 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100127 \ s:notend . '\<program\>:\<end\s*program\>,'.
128 \ '\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129endif
130
131" File filters for :browse e
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200132if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaard38b0552012-04-25 19:07:41 +0200133 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" .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134 \ "All Files (*.*)\t*.*\n"
135endif
136
Bram Moolenaarb1332082013-10-06 14:22:40 +0200137let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
139
140let &cpoptions=s:cposet
141unlet s:cposet
142
143" vim:sw=2