blob: 741465da188117c6cfe8f6566e0903a99280914b [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim settings file
2" Language: Fortran90 (and Fortran95, Fortran77, F and elf90)
Bram Moolenaar365bdf72010-07-24 20:57:44 +02003" Version: 0.46
4" Last Change: 2010 July 24
Bram Moolenaar071d4272004-06-13 20:20:40 +00005" Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www.unb.ca/chem/ajit/>
6" Usage: Do :help fortran-plugin from Vim
Bram Moolenaar365bdf72010-07-24 20:57:44 +02007" Credits:
8" Useful suggestions were made by Stefano Zacchiroli and Hendrik Merx.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
10" Only do these settings when not done yet for this buffer
11if exists("b:did_ftplugin")
12 finish
13endif
14
15" Don't do other file type settings for this buffer
16let b:did_ftplugin = 1
17
18" Determine whether this is a fixed or free format source file
19" if this hasn't been done yet
20if !exists("b:fortran_fixed_source")
21 if exists("fortran_free_source")
22 " User guarantees free source form
23 let b:fortran_fixed_source = 0
24 elseif exists("fortran_fixed_source")
25 " User guarantees fixed source form
26 let b:fortran_fixed_source = 1
27 else
28 " f90 and f95 allow both fixed and free source form
29 " assume fixed source form unless signs of free source form
Bram Moolenaar365bdf72010-07-24 20:57:44 +020030 " are detected in the first five columns of the first s:lmax lines
Bram Moolenaar071d4272004-06-13 20:20:40 +000031 " Detection becomes more accurate and time-consuming if more lines
32 " are checked. Increase the limit below if you keep lots of comments at
33 " the very top of each file and you have a fast computer
Bram Moolenaar365bdf72010-07-24 20:57:44 +020034 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000035 if ( s:lmax > line("$") )
36 let s:lmax = line("$")
37 endif
38 let b:fortran_fixed_source = 1
39 let s:ln=1
40 while s:ln <= s:lmax
41 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020042 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 let b:fortran_fixed_source = 0
44 break
45 endif
46 let s:ln = s:ln + 1
47 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020048 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000049 endif
50endif
51
52" Set comments and textwidth according to source type
53if (b:fortran_fixed_source == 1)
54 setlocal comments=:!,:*,:C
55 " Fixed format requires a textwidth of 72 for code
56 setlocal tw=72
57 " If you need to add "&" on continued lines so that the code is
58 " compatible with both free and fixed format, then you should do so
59 " in column 73 and uncomment the next line
60 " setlocal tw=73
61else
62 setlocal comments=:!
63 " Free format allows a textwidth of 132 for code but 80 is more usual
64 setlocal tw=80
65endif
66
67" Set commentstring for foldmethod=marker
68setlocal cms=!%s
69
70" Tabs are not a good idea in Fortran so the default is to expand tabs
71if !exists("fortran_have_tabs")
72 setlocal expandtab
73endif
74
75" Set 'formatoptions' to break comment and text lines but allow long lines
76setlocal fo+=tcql
77
Bram Moolenaar910f66f2006-04-05 20:41:53 +000078setlocal include=^\\c#\\=\\s*include\\s\\+
79setlocal suffixesadd+=.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
81let s:cposet=&cpoptions
82set cpoptions-=C
83
84" Define patterns for the matchit plugin
85if !exists("b:match_words")
86 let s:notend = '\%(\<end\s\+\)\@<!'
87 let s:notselect = '\%(\<select\s\+\)\@<!'
88 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +000089 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaar071d4272004-06-13 20:20:40 +000090 let b:match_ignorecase = 1
91 let b:match_words =
92 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
93 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
94 \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'.
95 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
96 \ s:notend . '\<do\>:\<end\s*do\>,'.
97 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
98 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
99 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
100 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
101 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000102 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103 \ s:notend . '\<program\>:\<end\s*program\>'
104endif
105
106" File filters for :browse e
107if has("gui_win32") && !exists("b:browsefilter")
108 let b:browsefilter = "Fortran Files (*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn)\t*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn\n" .
109 \ "All Files (*.*)\t*.*\n"
110endif
111
112let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc<"
113 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
114
115let &cpoptions=s:cposet
116unlet s:cposet
117
118" vim:sw=2