blob: c817b3b78732f1c255e5689099971089da47cccd [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim settings file
2" Language: Fortran90 (and Fortran95, Fortran77, F and elf90)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003" Version: 0.45
4" Last Change: 2006 Apr. 03
Bram Moolenaar071d4272004-06-13 20:20:40 +00005" URL: http://www.unb.ca/chem/ajit/ftplugin/fortran.vim
6" Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www.unb.ca/chem/ajit/>
7" Usage: Do :help fortran-plugin from Vim
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008" Credits: Useful suggestions were made by Stefano Zacchiroli
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 Moolenaar910f66f2006-04-05 20:41:53 +000030 " are detected in the first five columns of the first 250 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 Moolenaar910f66f2006-04-05 20:41:53 +000034 let s:lmax = 250
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)
42 if s:test[0] !~ '[Cc*!#]' && s:test !~ '^ \+[!#]' && s:test =~ '[^ 0-9\t]'
43 let b:fortran_fixed_source = 0
44 break
45 endif
46 let s:ln = s:ln + 1
47 endwhile
48 endif
49endif
50
51" Set comments and textwidth according to source type
52if (b:fortran_fixed_source == 1)
53 setlocal comments=:!,:*,:C
54 " Fixed format requires a textwidth of 72 for code
55 setlocal tw=72
56 " If you need to add "&" on continued lines so that the code is
57 " compatible with both free and fixed format, then you should do so
58 " in column 73 and uncomment the next line
59 " setlocal tw=73
60else
61 setlocal comments=:!
62 " Free format allows a textwidth of 132 for code but 80 is more usual
63 setlocal tw=80
64endif
65
66" Set commentstring for foldmethod=marker
67setlocal cms=!%s
68
69" Tabs are not a good idea in Fortran so the default is to expand tabs
70if !exists("fortran_have_tabs")
71 setlocal expandtab
72endif
73
74" Set 'formatoptions' to break comment and text lines but allow long lines
75setlocal fo+=tcql
76
Bram Moolenaar910f66f2006-04-05 20:41:53 +000077setlocal include=^\\c#\\=\\s*include\\s\\+
78setlocal suffixesadd+=.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +000079
80let s:cposet=&cpoptions
81set cpoptions-=C
82
83" Define patterns for the matchit plugin
84if !exists("b:match_words")
85 let s:notend = '\%(\<end\s\+\)\@<!'
86 let s:notselect = '\%(\<select\s\+\)\@<!'
87 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +000088 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaar071d4272004-06-13 20:20:40 +000089 let b:match_ignorecase = 1
90 let b:match_words =
91 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
92 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
93 \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'.
94 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
95 \ s:notend . '\<do\>:\<end\s*do\>,'.
96 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
97 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
98 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
99 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
100 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000101 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102 \ s:notend . '\<program\>:\<end\s*program\>'
103endif
104
105" File filters for :browse e
106if has("gui_win32") && !exists("b:browsefilter")
107 let b:browsefilter = "Fortran Files (*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn)\t*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn\n" .
108 \ "All Files (*.*)\t*.*\n"
109endif
110
111let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc<"
112 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
113
114let &cpoptions=s:cposet
115unlet s:cposet
116
117" vim:sw=2