blob: 3c325818d31cfcc407f6924ddcf5d2ba728463e0 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim settings file
Ajit-Thakkarea9964a2023-12-23 06:31:38 -04002" Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66)
3" Version: (v55) 2023 December 22
Ajit-Thakkar68630842023-12-05 23:07:27 +01004" 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.
Doug Kearns93197fd2024-01-14 20:59:02 +010012" Last Change: 2023 Dec 22
13" 2024 Jan 14 by Vim Project (browsefilter)
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
15" Only do these settings when not done yet for this buffer
16if exists("b:did_ftplugin")
17 finish
18endif
19
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010020let s:cposet=&cpoptions
21set cpoptions&vim
22
Bram Moolenaar071d4272004-06-13 20:20:40 +000023" Don't do other file type settings for this buffer
24let b:did_ftplugin = 1
25
26" Determine whether this is a fixed or free format source file
Bram Moolenaar256972a2015-12-29 19:10:25 +010027" if this hasn't been done yet using the priority:
28" buffer-local value
29" > global value
30" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
Bram Moolenaar071d4272004-06-13 20:20:40 +000031if !exists("b:fortran_fixed_source")
32 if exists("fortran_free_source")
33 " User guarantees free source form
34 let b:fortran_fixed_source = 0
35 elseif exists("fortran_fixed_source")
36 " User guarantees fixed source form
37 let b:fortran_fixed_source = 1
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020038 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010039 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
40 let b:fortran_fixed_source = 0
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020041 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010042 " Fixed-form file extension defaults
43 let b:fortran_fixed_source = 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000044 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010045 " Modern fortran compilers still allow both fixed and free source form
Bram Moolenaar256972a2015-12-29 19:10:25 +010046 " Assume fixed source form unless signs of free source form
47 " are detected in the first five columns of the first s:lmax lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 " Detection becomes more accurate and time-consuming if more lines
49 " are checked. Increase the limit below if you keep lots of comments at
Bram Moolenaar256972a2015-12-29 19:10:25 +010050 " the very top of each file and you have a fast computer.
Bram Moolenaar365bdf72010-07-24 20:57:44 +020051 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 if ( s:lmax > line("$") )
53 let s:lmax = line("$")
54 endif
55 let b:fortran_fixed_source = 1
56 let s:ln=1
57 while s:ln <= s:lmax
58 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020059 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 let b:fortran_fixed_source = 0
61 break
62 endif
63 let s:ln = s:ln + 1
64 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020065 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 endif
67endif
68
69" Set comments and textwidth according to source type
70if (b:fortran_fixed_source == 1)
71 setlocal comments=:!,:*,:C
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020072 " Fixed format requires a textwidth of 72 for code,
73 " but some vendor extensions allow longer lines
74 if exists("fortran_extended_line_length")
75 setlocal tw=132
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020076 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010077 " The use of columns 73-80 for sequence numbers is obsolete
78 " so almost all compilers allow a textwidth of 80
79 setlocal tw=80
Bram Moolenaar071d4272004-06-13 20:20:40 +000080 " If you need to add "&" on continued lines so that the code is
81 " compatible with both free and fixed format, then you should do so
Ajit-Thakkar68630842023-12-05 23:07:27 +010082 " in column 81 and uncomment the next line
83 " setlocal tw=81
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020084 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000085else
86 setlocal comments=:!
Bram Moolenaarb1332082013-10-06 14:22:40 +020087 " Free format allows a textwidth of 132
88 setlocal tw=132
Bram Moolenaar071d4272004-06-13 20:20:40 +000089endif
90
91" Set commentstring for foldmethod=marker
92setlocal cms=!%s
93
94" Tabs are not a good idea in Fortran so the default is to expand tabs
95if !exists("fortran_have_tabs")
96 setlocal expandtab
97endif
98
Bram Moolenaarb1332082013-10-06 14:22:40 +020099" Set 'formatoptions' to break text lines
100setlocal fo+=t
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000102setlocal include=^\\c#\\=\\s*include\\s\\+
Bram Moolenaard38b0552012-04-25 19:07:41 +0200103setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105" Define patterns for the matchit plugin
106if !exists("b:match_words")
107 let s:notend = '\%(\<end\s\+\)\@<!'
108 let s:notselect = '\%(\<select\s\+\)\@<!'
109 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000110 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100111 let s:nothash = '\%(^\s*#\s*\)\@<!'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112 let b:match_ignorecase = 1
113 let b:match_words =
Bram Moolenaard38b0552012-04-25 19:07:41 +0200114 \ '(:),' .
Ajit-Thakkarea9964a2023-12-23 06:31:38 -0400115 \ s:notend .'\<select\s\+type\>:' . s:notselect. '\<type\|class\>:\<end\s*select\>,' .
116 \ s:notend .'\<select\s\+rank\>:' . s:notselect. '\<rank\>:\<end\s*select\>,' .
117 \ s:notend .'\<select\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100119 \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
121 \ s:notend . '\<do\>:\<end\s*do\>,'.
122 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
123 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200124 \ s:notend . '\<forall\>:\<end\s*forall\>,'.
125 \ s:notend . '\<associate\>:\<end\s*associate\>,'.
Ajit-Thakkarea9964a2023-12-23 06:31:38 -0400126 \ s:notend . '\<change\s\+team\>:\<end\s*team\>,'.
127 \ s:notend . '\<critical\>:\<end\s*critical\>,'.
128 \ s:notend . '\<block\>:\<end\s*block\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200129 \ s:notend . '\<enum\>:\<end\s*enum\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
131 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
132 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000133 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100134 \ s:notend . '\<program\>:\<end\s*program\>,'.
135 \ '\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136endif
137
138" File filters for :browse e
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200139if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Doug Kearns93197fd2024-01-14 20:59:02 +0100140 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"
141 if has("win32")
142 let b:browsefilter .= "All Files (*.*)\t*\n"
143 else
144 let b:browsefilter .= "All Files (*)\t*\n"
145 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146endif
147
Bram Moolenaarb1332082013-10-06 14:22:40 +0200148let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
150
151let &cpoptions=s:cposet
152unlet s:cposet
153
154" vim:sw=2