comparison runtime/indent/fortran.vim @ 7790:ca19726d5e83

commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 28 22:38:53 2016 +0100 Update runtime files.
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Jan 2016 22:45:05 +0100
parents aea5ebf352c4
children 03fa8a51e9dc
comparison
equal deleted inserted replaced
7789:b2fc0ad0a694 7790:ca19726d5e83
1 " Vim indent file 1 " Vim indent file
2 " Language: Fortran 2008 (and older: Fortran 2003, 95, 90, and 77) 2 " Language: Fortran 2008 (and older: Fortran 2003, 95, 90, and 77)
3 " Version: 0.42 3 " Version: 0.44
4 " Last Change: 2015 Nov. 30 4 " Last Change: 2016 Jan. 26
5 " Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/> 5 " Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
6 " Usage: For instructions, do :help fortran-indent from Vim 6 " Usage: For instructions, do :help fortran-indent from Vim
7 " Credits: 7 " Credits:
8 " Useful suggestions were made by: Albert Oliver Serra. 8 " Useful suggestions were made by: Albert Oliver Serra and Takuya Fujiwara.
9 9
10 " Only load this indent file when no other was loaded. 10 " Only load this indent file when no other was loaded.
11 if exists("b:did_indent") 11 if exists("b:did_indent")
12 finish 12 finish
13 endif 13 endif
90 let prev2stat=substitute(prev2line, '!.*$', '', '') 90 let prev2stat=substitute(prev2line, '!.*$', '', '')
91 91
92 "Indent do loops only if they are all guaranteed to be of do/end do type 92 "Indent do loops only if they are all guaranteed to be of do/end do type
93 if exists("b:fortran_do_enddo") || exists("g:fortran_do_enddo") 93 if exists("b:fortran_do_enddo") || exists("g:fortran_do_enddo")
94 if prevstat =~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*do\>' 94 if prevstat =~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*do\>'
95 let ind = ind + &sw 95 let ind = ind + shiftwidth()
96 endif 96 endif
97 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*end\s*do\>' 97 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*end\s*do\>'
98 let ind = ind - &sw 98 let ind = ind - shiftwidth()
99 endif 99 endif
100 endif 100 endif
101 101
102 "Add a shiftwidth to statements following if, else, else if, case, 102 "Add a shiftwidth to statements following if, else, else if, case,
103 "where, else where, forall, type, interface and associate statements 103 "where, else where, forall, type, interface and associate statements
104 if prevstat =~? '^\s*\(case\|else\|else\s*if\|else\s*where\)\>' 104 if prevstat =~? '^\s*\(case\|else\|else\s*if\|else\s*where\)\>'
105 \ ||prevstat=~? '^\s*\(type\|interface\|associate\|enum\)\>' 105 \ ||prevstat=~? '^\s*\(type\|interface\|associate\|enum\)\>'
106 \ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>' 106 \ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>'
107 \ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>' 107 \ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>'
108 let ind = ind + &sw 108 let ind = ind + shiftwidth()
109 " Remove unwanted indent after logical and arithmetic ifs 109 " Remove unwanted indent after logical and arithmetic ifs
110 if prevstat =~? '\<if\>' && prevstat !~? '\<then\>' 110 if prevstat =~? '\<if\>' && prevstat !~? '\<then\>'
111 let ind = ind - &sw 111 let ind = ind - shiftwidth()
112 endif 112 endif
113 " Remove unwanted indent after type( statements 113 " Remove unwanted indent after type( statements
114 if prevstat =~? '^\s*type\s*(' 114 if prevstat =~? '^\s*type\s*('
115 let ind = ind - &sw 115 let ind = ind - shiftwidth()
116 endif 116 endif
117 endif 117 endif
118 118
119 "Indent program units unless instructed otherwise 119 "Indent program units unless instructed otherwise
120 if !exists("b:fortran_indent_less") && !exists("g:fortran_indent_less") 120 if !exists("b:fortran_indent_less") && !exists("g:fortran_indent_less")
123 \.'\|character\|type\|class\)\s*\S*\s\+\)\=' 123 \.'\|character\|type\|class\)\s*\S*\s\+\)\='
124 if prevstat =~? '^\s*\(module\|contains\|program\)\>' 124 if prevstat =~? '^\s*\(module\|contains\|program\)\>'
125 \ ||prevstat =~? '^\s*'.prefix.'subroutine\>' 125 \ ||prevstat =~? '^\s*'.prefix.'subroutine\>'
126 \ ||prevstat =~? '^\s*'.prefix.type.'function\>' 126 \ ||prevstat =~? '^\s*'.prefix.type.'function\>'
127 \ ||prevstat =~? '^\s*'.type.prefix.'function\>' 127 \ ||prevstat =~? '^\s*'.type.prefix.'function\>'
128 let ind = ind + &sw 128 let ind = ind + shiftwidth()
129 endif 129 endif
130 if getline(v:lnum) =~? '^\s*contains\>' 130 if getline(v:lnum) =~? '^\s*contains\>'
131 \ ||getline(v:lnum)=~? '^\s*end\s*' 131 \ ||getline(v:lnum)=~? '^\s*end\s*'
132 \ .'\(function\|subroutine\|module\|program\)\>' 132 \ .'\(function\|subroutine\|module\|program\)\>'
133 let ind = ind - &sw 133 let ind = ind - shiftwidth()
134 endif 134 endif
135 endif 135 endif
136 136
137 "Subtract a shiftwidth from else, else if, elsewhere, case, end if, 137 "Subtract a shiftwidth from else, else if, elsewhere, case, end if,
138 " end where, end select, end forall, end interface, end associate, 138 " end where, end select, end forall, end interface, end associate,
139 " end enum, and end type statements 139 " end enum, and end type statements
140 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*' 140 if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*'
141 \. '\(else\|else\s*if\|else\s*where\|case\|' 141 \. '\(else\|else\s*if\|else\s*where\|case\|'
142 \. 'end\s*\(if\|where\|select\|interface\|' 142 \. 'end\s*\(if\|where\|select\|interface\|'
143 \. 'type\|forall\|associate\|enum\|block\)\)\>' 143 \. 'type\|forall\|associate\|enum\|block\)\)\>'
144 let ind = ind - &sw 144 let ind = ind - shiftwidth()
145 " Fix indent for case statement immediately after select 145 " Fix indent for case statement immediately after select
146 if prevstat =~? '\<select\s\+\(case\|type\)\>' 146 if prevstat =~? '\<select\s\+\(case\|type\)\>'
147 let ind = ind + &sw 147 let ind = ind + shiftwidth()
148 endif 148 endif
149 endif 149 endif
150 150
151 "First continuation line 151 "First continuation line
152 if prevstat =~ '&\s*$' && prev2stat !~ '&\s*$' 152 if prevstat =~ '&\s*$' && prev2stat !~ '&\s*$'
153 let ind = ind + &sw 153 let ind = ind + shiftwidth()
154 endif 154 endif
155 if prevstat =~ '&\s*$' && prevstat =~ '\<else\s*if\>' 155 if prevstat =~ '&\s*$' && prevstat =~ '\<else\s*if\>'
156 let ind = ind - &sw 156 let ind = ind - shiftwidth()
157 endif 157 endif
158 "Line after last continuation line 158 "Line after last continuation line
159 if prevstat !~ '&\s*$' && prev2stat =~ '&\s*$' && prevstat !~? '\<then\>' 159 if prevstat !~ '&\s*$' && prev2stat =~ '&\s*$' && prevstat !~? '\<then\>'
160 let ind = ind - &sw 160 let ind = ind - shiftwidth()
161 endif 161 endif
162 162
163 return ind 163 return ind
164 endfunction 164 endfunction
165 165