blob: 19a4c1e62b0d95dff1f049a872c8c88b965692e4 [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)
Riley Bruins0a083062024-06-03 20:40:45 +020014" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
16" Only do these settings when not done yet for this buffer
17if exists("b:did_ftplugin")
18 finish
19endif
20
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010021let s:cposet=&cpoptions
22set cpoptions&vim
23
Bram Moolenaar071d4272004-06-13 20:20:40 +000024" Don't do other file type settings for this buffer
25let b:did_ftplugin = 1
26
27" Determine whether this is a fixed or free format source file
Bram Moolenaar256972a2015-12-29 19:10:25 +010028" if this hasn't been done yet using the priority:
29" buffer-local value
30" > global value
31" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
Bram Moolenaar071d4272004-06-13 20:20:40 +000032if !exists("b:fortran_fixed_source")
33 if exists("fortran_free_source")
34 " User guarantees free source form
35 let b:fortran_fixed_source = 0
36 elseif exists("fortran_fixed_source")
37 " User guarantees fixed source form
38 let b:fortran_fixed_source = 1
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020039 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010040 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
41 let b:fortran_fixed_source = 0
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020042 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$'
Bram Moolenaar256972a2015-12-29 19:10:25 +010043 " Fixed-form file extension defaults
44 let b:fortran_fixed_source = 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010046 " Modern fortran compilers still allow both fixed and free source form
Bram Moolenaar256972a2015-12-29 19:10:25 +010047 " Assume fixed source form unless signs of free source form
48 " are detected in the first five columns of the first s:lmax lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +000049 " Detection becomes more accurate and time-consuming if more lines
50 " are checked. Increase the limit below if you keep lots of comments at
Bram Moolenaar256972a2015-12-29 19:10:25 +010051 " the very top of each file and you have a fast computer.
Bram Moolenaar365bdf72010-07-24 20:57:44 +020052 let s:lmax = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 if ( s:lmax > line("$") )
54 let s:lmax = line("$")
55 endif
56 let b:fortran_fixed_source = 1
57 let s:ln=1
58 while s:ln <= s:lmax
59 let s:test = strpart(getline(s:ln),0,5)
Bram Moolenaar365bdf72010-07-24 20:57:44 +020060 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 let b:fortran_fixed_source = 0
62 break
63 endif
64 let s:ln = s:ln + 1
65 endwhile
Bram Moolenaar365bdf72010-07-24 20:57:44 +020066 unlet! s:lmax s:ln s:test
Bram Moolenaar071d4272004-06-13 20:20:40 +000067 endif
68endif
69
70" Set comments and textwidth according to source type
71if (b:fortran_fixed_source == 1)
72 setlocal comments=:!,:*,:C
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020073 " Fixed format requires a textwidth of 72 for code,
74 " but some vendor extensions allow longer lines
75 if exists("fortran_extended_line_length")
76 setlocal tw=132
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020077 else
Ajit-Thakkar68630842023-12-05 23:07:27 +010078 " The use of columns 73-80 for sequence numbers is obsolete
79 " so almost all compilers allow a textwidth of 80
80 setlocal tw=80
Bram Moolenaar071d4272004-06-13 20:20:40 +000081 " If you need to add "&" on continued lines so that the code is
82 " compatible with both free and fixed format, then you should do so
Ajit-Thakkar68630842023-12-05 23:07:27 +010083 " in column 81 and uncomment the next line
84 " setlocal tw=81
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020085 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000086else
87 setlocal comments=:!
Bram Moolenaarb1332082013-10-06 14:22:40 +020088 " Free format allows a textwidth of 132
89 setlocal tw=132
Bram Moolenaar071d4272004-06-13 20:20:40 +000090endif
91
92" Set commentstring for foldmethod=marker
Riley Bruins0a083062024-06-03 20:40:45 +020093setlocal cms=!\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
95" Tabs are not a good idea in Fortran so the default is to expand tabs
96if !exists("fortran_have_tabs")
97 setlocal expandtab
98endif
99
Bram Moolenaarb1332082013-10-06 14:22:40 +0200100" Set 'formatoptions' to break text lines
101setlocal fo+=t
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000103setlocal include=^\\c#\\=\\s*include\\s\\+
Bram Moolenaard38b0552012-04-25 19:07:41 +0200104setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106" Define patterns for the matchit plugin
107if !exists("b:match_words")
108 let s:notend = '\%(\<end\s\+\)\@<!'
109 let s:notselect = '\%(\<select\s\+\)\@<!'
110 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000111 let s:notprocedure = '\%(\s\+procedure\>\)\@!'
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100112 let s:nothash = '\%(^\s*#\s*\)\@<!'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113 let b:match_ignorecase = 1
114 let b:match_words =
Bram Moolenaard38b0552012-04-25 19:07:41 +0200115 \ '(:),' .
Ajit-Thakkarea9964a2023-12-23 06:31:38 -0400116 \ s:notend .'\<select\s\+type\>:' . s:notselect. '\<type\|class\>:\<end\s*select\>,' .
117 \ s:notend .'\<select\s\+rank\>:' . s:notselect. '\<rank\>:\<end\s*select\>,' .
118 \ s:notend .'\<select\>:' . s:notselect. '\<case\>:\<end\s*select\>,' .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119 \ s:notelse . '\<if\s*(.\+)\s*then\>:' .
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100120 \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'.
122 \ s:notend . '\<do\>:\<end\s*do\>,'.
123 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'.
124 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200125 \ s:notend . '\<forall\>:\<end\s*forall\>,'.
126 \ s:notend . '\<associate\>:\<end\s*associate\>,'.
Ajit-Thakkarea9964a2023-12-23 06:31:38 -0400127 \ s:notend . '\<change\s\+team\>:\<end\s*team\>,'.
128 \ s:notend . '\<critical\>:\<end\s*critical\>,'.
129 \ s:notend . '\<block\>:\<end\s*block\>,'.
Bram Moolenaard38b0552012-04-25 19:07:41 +0200130 \ s:notend . '\<enum\>:\<end\s*enum\>,'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131 \ s:notend . '\<interface\>:\<end\s*interface\>,'.
132 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'.
133 \ s:notend . '\<function\>:\<end\s*function\>,'.
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000134 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'.
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +0100135 \ s:notend . '\<program\>:\<end\s*program\>,'.
136 \ '\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137endif
138
139" File filters for :browse e
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200140if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Doug Kearns93197fd2024-01-14 20:59:02 +0100141 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"
142 if has("win32")
143 let b:browsefilter .= "All Files (*.*)\t*\n"
144 else
145 let b:browsefilter .= "All Files (*)\t*\n"
146 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147endif
148
Bram Moolenaarb1332082013-10-06 14:22:40 +0200149let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter"
151
152let &cpoptions=s:cposet
153unlet s:cposet
154
155" vim:sw=2