Mercurial > vim
annotate runtime/indent/fortran.vim @ 34217:0f125612fd33 v9.1.0057
patch 9.1.0057: MS-Windows: Key event test still fails
Commit: https://github.com/vim/vim/commit/6a02eb073e1c801a5a92837d4b2d44b6a80afddd
Author: Christian Brabandt <cb@256bit.org>
Date: Thu Jan 25 22:28:37 2024 +0100
patch 9.1.0057: MS-Windows: Key event test still fails
Problem: MS-Windows: Key event test still fails
Solution: Skip testing CTRL-C, since it causes an Interrupt
which causes a test failure (after 9.1.0053)
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 25 Jan 2024 22:45:02 +0100 |
parents | 7bbae0fa2d7d |
children |
rev | line source |
---|---|
7 | 1 " Vim indent file |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
2 " Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) |
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
3 " Version: (v50) 2023 December 22 |
33894
cf2ae76cbbf7
runtime(fortran): update syntax and ftplugins
Christian Brabandt <cb@256bit.org>
parents:
28933
diff
changeset
|
4 " Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> |
cf2ae76cbbf7
runtime(fortran): update syntax and ftplugins
Christian Brabandt <cb@256bit.org>
parents:
28933
diff
changeset
|
5 " Joshua Hollett <j.hollett@uwinnipeg.ca> |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
6 " Usage: For instructions, do :help fortran-indent from Vim |
6530 | 7 " Credits: |
22565 | 8 " 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 " Albert Oliver Serra, Takuya Fujiwara, Philipp Edelmann, Eisuke Kawashima, | |
28933 | 11 " Louis Cochen, and Doug Kearns. |
7 | 12 |
13 " Only load this indent file when no other was loaded. | |
14 if exists("b:did_indent") | |
15 finish | |
16 endif | |
17 let b:did_indent = 1 | |
18 | |
3237 | 19 let s:cposet=&cpoptions |
20 set cpoptions&vim | |
28933 | 21 let b:undo_indent = "setl inde< indk<" |
3237 | 22 |
7 | 23 setlocal indentkeys+==~end,=~case,=~if,=~else,=~do,=~where,=~elsewhere,=~select |
2908 | 24 setlocal indentkeys+==~endif,=~enddo,=~endwhere,=~endselect,=~elseif |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
25 setlocal indentkeys+==~interface,=~forall,=~associate,=~block,=~enum,=~critical |
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
26 setlocal indentkeys+==~endforall,=~endassociate,=~endblock,=~endenum,=~endcritical |
2908 | 27 if exists("b:fortran_indent_more") || exists("g:fortran_indent_more") |
28 setlocal indentkeys+==~function,=~subroutine,=~module,=~contains,=~program | |
29 setlocal indentkeys+==~endfunction,=~endsubroutine,=~endmodule | |
30 setlocal indentkeys+==~endprogram | |
31 endif | |
7 | 32 |
33 " Determine whether this is a fixed or free format source file | |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
34 " if this hasn't been done yet using the priority: |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
35 " buffer-local value |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
36 " > global value |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
37 " > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers |
7 | 38 if !exists("b:fortran_fixed_source") |
39 if exists("fortran_free_source") | |
40 " User guarantees free source form | |
41 let b:fortran_fixed_source = 0 | |
42 elseif exists("fortran_fixed_source") | |
43 " User guarantees fixed source form | |
44 let b:fortran_fixed_source = 1 | |
20115 | 45 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$' |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
46 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
47 let b:fortran_fixed_source = 0 |
20115 | 48 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$' |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
49 " Fixed-form file extension defaults |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
50 let b:fortran_fixed_source = 1 |
7 | 51 else |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
52 " Modern fortran compilers still allow both fixed and free source form |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
53 " Assume fixed source form unless signs of free source form |
6530 | 54 " are detected in the first five columns of the first s:lmax lines. |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
55 " Detection becomes more accurate and time-consuming if more lines |
7 | 56 " are checked. Increase the limit below if you keep lots of comments at |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6530
diff
changeset
|
57 " the very top of each file and you have a fast computer. |
2377
878562053ba3
Update Fortran indent and syntax file. (Ajit Thakkar)
Bram Moolenaar <bram@vim.org>
parents:
1125
diff
changeset
|
58 let s:lmax = 500 |
7 | 59 if ( s:lmax > line("$") ) |
60 let s:lmax = line("$") | |
61 endif | |
62 let b:fortran_fixed_source = 1 | |
63 let s:ln=1 | |
64 while s:ln <= s:lmax | |
65 let s:test = strpart(getline(s:ln),0,5) | |
2377
878562053ba3
Update Fortran indent and syntax file. (Ajit Thakkar)
Bram Moolenaar <bram@vim.org>
parents:
1125
diff
changeset
|
66 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t' |
7 | 67 let b:fortran_fixed_source = 0 |
68 break | |
69 endif | |
70 let s:ln = s:ln + 1 | |
71 endwhile | |
72 endif | |
73 endif | |
74 | |
75 " Define the appropriate indent function but only once | |
76 if (b:fortran_fixed_source == 1) | |
77 setlocal indentexpr=FortranGetFixedIndent() | |
78 if exists("*FortranGetFixedIndent") | |
23737 | 79 let &cpoptions = s:cposet |
80 unlet s:cposet | |
7 | 81 finish |
82 endif | |
83 else | |
84 setlocal indentexpr=FortranGetFreeIndent() | |
85 if exists("*FortranGetFreeIndent") | |
23737 | 86 let &cpoptions = s:cposet |
87 unlet s:cposet | |
7 | 88 finish |
89 endif | |
90 endif | |
91 | |
92 function FortranGetIndent(lnum) | |
93 let ind = indent(a:lnum) | |
94 let prevline=getline(a:lnum) | |
95 " Strip tail comment | |
96 let prevstat=substitute(prevline, '!.*$', '', '') | |
2908 | 97 let prev2line=getline(a:lnum-1) |
98 let prev2stat=substitute(prev2line, '!.*$', '', '') | |
7 | 99 |
100 "Indent do loops only if they are all guaranteed to be of do/end do type | |
1125 | 101 if exists("b:fortran_do_enddo") || exists("g:fortran_do_enddo") |
7 | 102 if prevstat =~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*do\>' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
103 let ind = ind + shiftwidth() |
7 | 104 endif |
105 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*end\s*do\>' | |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
106 let ind = ind - shiftwidth() |
7 | 107 endif |
108 endif | |
109 | |
10385
368468ef35cf
commit https://github.com/vim/vim/commit/c0514bf4777a1d55f5785b3887c5686fd0bbe870
Christian Brabandt <cb@256bit.org>
parents:
10244
diff
changeset
|
110 "Add a shiftwidth to statements following if, else, else if, case, class, |
2908 | 111 "where, else where, forall, type, interface and associate statements |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
112 if prevstat =~? '^\s*\(case\|class\s\+is\|else\|else\s*if\|else\s*where\)\>' |
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
113 \ ||prevstat=~? '^\s*\(type\|rank\|interface\|associate\|enum\|critical\)\>' |
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
114 \ ||prevstat=~? '^\s*change\s\+team\>' |
2908 | 115 \ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>' |
116 \ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>' | |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
117 let ind = ind + shiftwidth() |
7 | 118 " Remove unwanted indent after logical and arithmetic ifs |
119 if prevstat =~? '\<if\>' && prevstat !~? '\<then\>' | |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
120 let ind = ind - shiftwidth() |
7 | 121 endif |
840 | 122 " Remove unwanted indent after type( statements |
2908 | 123 if prevstat =~? '^\s*type\s*(' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
124 let ind = ind - shiftwidth() |
840 | 125 endif |
7 | 126 endif |
127 | |
2908 | 128 "Indent program units unless instructed otherwise |
129 if !exists("b:fortran_indent_less") && !exists("g:fortran_indent_less") | |
130 let prefix='\(\(pure\|impure\|elemental\|recursive\)\s\+\)\{,2}' | |
131 let type='\(\(integer\|real\|double\s\+precision\|complex\|logical' | |
132 \.'\|character\|type\|class\)\s*\S*\s\+\)\=' | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
133 if prevstat =~? '^\s*\(contains\|submodule\|program\)\>' |
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
134 \ ||prevstat =~? '^\s*'.'module\>\(\s*\procedure\)\@!' |
2908 | 135 \ ||prevstat =~? '^\s*'.prefix.'subroutine\>' |
136 \ ||prevstat =~? '^\s*'.prefix.type.'function\>' | |
137 \ ||prevstat =~? '^\s*'.type.prefix.'function\>' | |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
138 let ind = ind + shiftwidth() |
2908 | 139 endif |
140 if getline(v:lnum) =~? '^\s*contains\>' | |
141 \ ||getline(v:lnum)=~? '^\s*end\s*' | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
142 \ .'\(function\|subroutine\|module\|submodule\|program\)\>' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
143 let ind = ind - shiftwidth() |
2908 | 144 endif |
145 endif | |
146 | |
10385
368468ef35cf
commit https://github.com/vim/vim/commit/c0514bf4777a1d55f5785b3887c5686fd0bbe870
Christian Brabandt <cb@256bit.org>
parents:
10244
diff
changeset
|
147 "Subtract a shiftwidth from else, else if, elsewhere, case, class, end if, |
2908 | 148 " end where, end select, end forall, end interface, end associate, |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
149 " end enum, end type, end block, end team and end type statements |
7 | 150 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*' |
34010
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
151 \. '\(else\|else\s*if\|else\s*where\|case\|class\|rank\|type\s\+is\|' |
7bbae0fa2d7d
Runtime(fortran): updates to indent, syntax and ftplugin (#13752)
Christian Brabandt <cb@256bit.org>
parents:
33894
diff
changeset
|
152 \. 'end\s*\(if\|where\|select\|interface\|critical\|team\|' |
6530 | 153 \. 'type\|forall\|associate\|enum\|block\)\)\>' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
154 let ind = ind - shiftwidth() |
7 | 155 " Fix indent for case statement immediately after select |
22565 | 156 if prevstat =~? '\<select\s*\(case\|type\)\>' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
157 let ind = ind + shiftwidth() |
7 | 158 endif |
159 endif | |
160 | |
2908 | 161 "First continuation line |
162 if prevstat =~ '&\s*$' && prev2stat !~ '&\s*$' | |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
163 let ind = ind + shiftwidth() |
2908 | 164 endif |
165 "Line after last continuation line | |
6530 | 166 if prevstat !~ '&\s*$' && prev2stat =~ '&\s*$' && prevstat !~? '\<then\>' |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
167 let ind = ind - shiftwidth() |
2908 | 168 endif |
169 | |
7 | 170 return ind |
171 endfunction | |
172 | |
173 function FortranGetFreeIndent() | |
174 "Find the previous non-blank line | |
175 let lnum = prevnonblank(v:lnum - 1) | |
176 | |
177 "Use zero indent at the top of the file | |
178 if lnum == 0 | |
179 return 0 | |
180 endif | |
181 | |
182 let ind=FortranGetIndent(lnum) | |
183 return ind | |
184 endfunction | |
185 | |
186 function FortranGetFixedIndent() | |
187 let currline=getline(v:lnum) | |
188 "Don't indent comments, continuation lines and labelled lines | |
189 if strpart(currline,0,6) =~ '[^ \t]' | |
190 let ind = indent(v:lnum) | |
191 return ind | |
192 endif | |
193 | |
194 "Find the previous line which is not blank, not a comment, | |
195 "not a continuation line, and does not have a label | |
196 let lnum = v:lnum - 1 | |
197 while lnum > 0 | |
198 let prevline=getline(lnum) | |
199 if (prevline =~ "^[C*!]") || (prevline =~ "^\s*$") | |
200 \ || (strpart(prevline,5,1) !~ "[ 0]") | |
201 " Skip comments, blank lines and continuation lines | |
202 let lnum = lnum - 1 | |
203 else | |
204 let test=strpart(prevline,0,5) | |
205 if test =~ "[0-9]" | |
206 " Skip lines with statement numbers | |
207 let lnum = lnum - 1 | |
208 else | |
209 break | |
210 endif | |
211 endif | |
212 endwhile | |
213 | |
214 "First line must begin at column 7 | |
215 if lnum == 0 | |
216 return 6 | |
217 endif | |
218 | |
219 let ind=FortranGetIndent(lnum) | |
220 return ind | |
221 endfunction | |
222 | |
23737 | 223 let &cpoptions = s:cposet |
7 | 224 unlet s:cposet |
225 | |
226 " vim:sw=2 tw=130 |