blob: 26dc90a184dc2de4ede4ff8ae56abdf5159a96fe [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)
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02003" Version: (v53) 2021 April 06
Bram Moolenaarb1332082013-10-06 14:22:40 +02004" Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
Bram Moolenaar256972a2015-12-29 19:10:25 +01005" Usage: For instructions, do :help fortran-plugin from Vim
Bram Moolenaar365bdf72010-07-24 20:57:44 +02006" Credits:
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +02007" 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,
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020010" Doug Kearns, and Fritz Reese.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
12" Only do these settings when not done yet for this buffer
13if exists("b:did_ftplugin")
14 finish
15endif
16
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010017let s:cposet=&cpoptions
18set cpoptions&vim
19
Bram Moolenaar071d4272004-06-13 20:20:40 +000020" Don't do other file type settings for this buffer
21let b:did_ftplugin = 1
22
23" Determine whether this is a fixed or free format source file
Bram Moolenaar256972a2015-12-29 19:10:25 +010024" if this hasn't been done yet using the priority:
25" buffer-local value
26" > global value
27" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
Bram Moolenaar071d4272004-06-13 20:20:40 +000028if !exists("b:fortran_fixed_source")
29 if exists("fortran_free_source")
30 " User guarantees free source form
31 let b:fortran_fixed_source = 0
32 elseif exists("fortran_fixed_source")
33 " User guarantees fixed source form
34 let b:fortran_fixed_source = 1
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020035 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010036 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
37 let b:fortran_fixed_source = 0
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020038 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010039 " Fixed-form file extension defaults
40 let b:fortran_fixed_source = 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000041 else
Bram Moolenaar256972a2015-12-29 19:10:25 +010042 " Modern fortran still allows both fixed and free source form
43 " Assume fixed source form unless signs of free source form
44 " are detected in the first five columns of the first s:lmax lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 " Detection becomes more accurate and time-consuming if more lines
46 " are checked. Increase the limit below if you keep lots of comments at
Bram Moolenaar256972a2015-12-29 19:10:25 +010047 " the very top of each file and you have a fast computer.
Bram Moolenaar365bdf72010-07-24 20:57:44 +020048 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000049 if ( s:lmax > line("$") )
50 let s:lmax = line("$")
51 endif
52 let b:fortran_fixed_source = 1
53 let s:ln=1
54 while s:ln <= s:lmax
55 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020056 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 let b:fortran_fixed_source = 0
58 break
59 endif
60 let s:ln = s:ln + 1
61 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020062 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000063 endif
64endif
65
66" Set comments and textwidth according to source type
67if (b:fortran_fixed_source == 1)
68 setlocal comments=:!,:*,:C
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020069 " Fixed format requires a textwidth of 72 for code,
70 " but some vendor extensions allow longer lines
71 if exists("fortran_extended_line_length")
72 setlocal tw=132
73 elseif exists("fortran_cardimage_line_length")
74 setlocal tw=80
75 else
76 setlocal tw=72
Bram Moolenaar071d4272004-06-13 20:20:40 +000077 " If you need to add "&" on continued lines so that the code is
78 " compatible with both free and fixed format, then you should do so
79 " in column 73 and uncomment the next line
80 " setlocal tw=73
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020081 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000082else
83 setlocal comments=:!
Bram Moolenaarb1332082013-10-06 14:22:40 +020084 " Free format allows a textwidth of 132
85 setlocal tw=132
Bram Moolenaar071d4272004-06-13 20:20:40 +000086endif
87
88" Set commentstring for foldmethod=marker
89setlocal cms=!%s
90
91" Tabs are not a good idea in Fortran so the default is to expand tabs
92if !exists("fortran_have_tabs")
93 setlocal expandtab
94endif
95
Bram Moolenaarb1332082013-10-06 14:22:40 +020096" Set 'formatoptions' to break text lines
97setlocal fo+=t
Bram Moolenaar071d4272004-06-13 20:20:40 +000098
Bram Moolenaar910f66f2006-04-05 20:41:53 +000099setlocal include=^\\c#\\=\\s*include\\s\\+
Bram Moolenaard38b0552012-04-25 19:07:41 +0200100setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102" Define patterns for the matchit plugin
103if !exists("b:match_words")
104 let s:notend = '\%(\<end\s\+\)\@<!'
105 let s:notselect = '\%(\<select\s\+\)\@<!'
106 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000107 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108 let b:match_ignorecase = 1
109 let b:match_words =
Bram Moolenaard38b0552012-04-25 19:07:41 +0200110 \ '(:),' .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
112 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
113 \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'.
114 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
115 \ s:notend . '\<do\>:\<end\s*do\>,'.
116 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
117 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200118 \ s:notend . '\<forall\>:\<end\s*forall\>,'.
119 \ s:notend . '\<associate\>:\<end\s*associate\>,'.
120 \ s:notend . '\<enum\>:\<end\s*enum\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
122 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
123 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000124 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125 \ s:notend . '\<program\>:\<end\s*program\>'
126endif
127
128" File filters for :browse e
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200129if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaard38b0552012-04-25 19:07:41 +0200130 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 +0000131 \ "All Files (*.*)\t*.*\n"
132endif
133
Bram Moolenaarb1332082013-10-06 14:22:40 +0200134let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
136
137let &cpoptions=s:cposet
138unlet s:cposet
139
140" vim:sw=2