blob: 7591edd8218f8b8a5ee31373116120170ea07f29 [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 Moolenaarb1332082013-10-06 14:22:40 +02003" Version: 0.49
4" Last Change: 2013 Oct. 01
5" Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
Bram Moolenaar071d4272004-06-13 20:20:40 +00006" Usage: Do :help fortran-plugin from Vim
Bram Moolenaar365bdf72010-07-24 20:57:44 +02007" Credits:
Bram Moolenaarb1332082013-10-06 14:22:40 +02008" Useful suggestions were made by Stefano Zacchiroli, Hendrik Merx, Ben
9" Fritz, and David Barnett.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11" Only do these settings when not done yet for this buffer
12if exists("b:did_ftplugin")
13 finish
14endif
15
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010016let s:cposet=&cpoptions
17set cpoptions&vim
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" Don't do other file type settings for this buffer
20let b:did_ftplugin = 1
21
22" Determine whether this is a fixed or free format source file
23" if this hasn't been done yet
24if !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 else
Bram Moolenaard38b0552012-04-25 19:07:41 +020032 " Modern Fortran allows both fixed and free source form
Bram Moolenaar071d4272004-06-13 20:20:40 +000033 " assume fixed source form unless signs of free source form
Bram Moolenaar365bdf72010-07-24 20:57:44 +020034 " are detected in the first five columns of the first s:lmax lines
Bram Moolenaar071d4272004-06-13 20:20:40 +000035 " Detection becomes more accurate and time-consuming if more lines
36 " are checked. Increase the limit below if you keep lots of comments at
37 " the very top of each file and you have a fast computer
Bram Moolenaar365bdf72010-07-24 20:57:44 +020038 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000039 if ( s:lmax > line("$") )
40 let s:lmax = line("$")
41 endif
42 let b:fortran_fixed_source = 1
43 let s:ln=1
44 while s:ln <= s:lmax
45 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020046 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000047 let b:fortran_fixed_source = 0
48 break
49 endif
50 let s:ln = s:ln + 1
51 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020052 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 endif
54endif
55
56" Set comments and textwidth according to source type
57if (b:fortran_fixed_source == 1)
58 setlocal comments=:!,:*,:C
59 " Fixed format requires a textwidth of 72 for code
60 setlocal tw=72
61 " If you need to add "&" on continued lines so that the code is
62 " compatible with both free and fixed format, then you should do so
63 " in column 73 and uncomment the next line
64 " setlocal tw=73
65else
66 setlocal comments=:!
Bram Moolenaarb1332082013-10-06 14:22:40 +020067 " Free format allows a textwidth of 132
68 setlocal tw=132
Bram Moolenaar071d4272004-06-13 20:20:40 +000069endif
70
71" Set commentstring for foldmethod=marker
72setlocal cms=!%s
73
74" Tabs are not a good idea in Fortran so the default is to expand tabs
75if !exists("fortran_have_tabs")
76 setlocal expandtab
77endif
78
Bram Moolenaarb1332082013-10-06 14:22:40 +020079" Set 'formatoptions' to break text lines
80setlocal fo+=t
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
Bram Moolenaar910f66f2006-04-05 20:41:53 +000082setlocal include=^\\c#\\=\\s*include\\s\\+
Bram Moolenaard38b0552012-04-25 19:07:41 +020083setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +000084
Bram Moolenaar071d4272004-06-13 20:20:40 +000085" Define patterns for the matchit plugin
86if !exists("b:match_words")
87 let s:notend = '\%(\<end\s\+\)\@<!'
88 let s:notselect = '\%(\<select\s\+\)\@<!'
89 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +000090 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaar071d4272004-06-13 20:20:40 +000091 let b:match_ignorecase = 1
92 let b:match_words =
Bram Moolenaard38b0552012-04-25 19:07:41 +020093 \ '(:),' .
Bram Moolenaar071d4272004-06-13 20:20:40 +000094 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
95 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
96 \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'.
97 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
98 \ s:notend . '\<do\>:\<end\s*do\>,'.
99 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
100 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200101 \ s:notend . '\<forall\>:\<end\s*forall\>,'.
102 \ s:notend . '\<associate\>:\<end\s*associate\>,'.
103 \ s:notend . '\<enum\>:\<end\s*enum\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
105 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
106 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000107 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108 \ s:notend . '\<program\>:\<end\s*program\>'
109endif
110
111" File filters for :browse e
112if has("gui_win32") && !exists("b:browsefilter")
Bram Moolenaard38b0552012-04-25 19:07:41 +0200113 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 +0000114 \ "All Files (*.*)\t*.*\n"
115endif
116
Bram Moolenaarb1332082013-10-06 14:22:40 +0200117let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
119
120let &cpoptions=s:cposet
121unlet s:cposet
122
123" vim:sw=2