Mercurial > hg > RemoteEditor > vim7
comparison runtime/indent/vhdl.vim @ 48:67300faee616 v7-3-618
v7-3-618
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Aug 2012 18:08:28 +0900 |
parents | c16898406ff2 |
children |
comparison
equal
deleted
inserted
replaced
47:6c0584ec21b1 | 48:67300faee616 |
---|---|
1 " VHDL indent ('93 syntax) | 1 " VHDL indent ('93 syntax) |
2 " Language: VHDL | 2 " Language: VHDL |
3 " Maintainer: Gerald Lai <laigera+vim?gmail.com> | 3 " Maintainer: Gerald Lai <laigera+vim?gmail.com> |
4 " Version: 1.56 | 4 " Version: 1.58 |
5 " Last Change: 2010 Jun 29 | 5 " Last Change: 2011 Sep 27 |
6 " URL: http://www.vim.org/scripts/script.php?script_id=1450 | 6 " URL: http://www.vim.org/scripts/script.php?script_id=1450 |
7 | 7 |
8 " only load this indent file when no other was loaded | 8 " only load this indent file when no other was loaded |
9 if exists("b:did_indent") | 9 if exists("b:did_indent") |
10 finish | 10 finish |
93 endif | 93 endif |
94 endif | 94 endif |
95 | 95 |
96 " **************************************************************************************** | 96 " **************************************************************************************** |
97 " indent: align generic variables & port names | 97 " indent: align generic variables & port names |
98 " keywords: "generic", "map", "port" + "(", provided current line is part of mapping | 98 " keywords: "procedure" + name, "generic", "map", "port" + "(", provided current line is part of mapping |
99 " where: anywhere in previous 2 lines | 99 " where: anywhere in previous 2 lines |
100 " find following previous non-comment line | 100 " find following previous non-comment line |
101 let pn = prevnonblank(prevn - 1) | 101 let pn = prevnonblank(prevn - 1) |
102 let ps = getline(pn) | 102 let ps = getline(pn) |
103 while pn > 0 && ps =~ '^\s*--' | 103 while pn > 0 && ps =~ '^\s*--' |
104 let pn = prevnonblank(pn - 1) | 104 let pn = prevnonblank(pn - 1) |
105 let ps = getline(pn) | 105 let ps = getline(pn) |
106 endwhile | 106 endwhile |
107 if (curs =~ '^\s*)' || curs =~? '^\s*\%(\<\%(generic\|map\|port\)\>.*\)\@<!\S\+\s*\%(=>\s*\S\+\|:[^=]\@=\s*\%(\%(in\|out\|inout\|buffer\|linkage\)\>\|\w\+\s\+:=\)\)') && (prevs =~? s:NC.'\<\%(generic\|map\|port\)\s*(\%(\s*\w\)\=' || (ps =~? s:NC.'\<\%(generic\|map\|port\)'.s:ES && prevs =~ '^\s*(')) | 107 if (curs =~ '^\s*)' || curs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*\%(=>\s*\S\+\|:[^=]\@=\s*\%(\%(in\|out\|inout\|buffer\|linkage\)\>\|\w\+\s\+:=\)\)') && (prevs =~? s:NC.'\<\%(procedure\s\+\S\+\|generic\|map\|port\)\s*(\%(\s*\w\)\=' || (ps =~? s:NC.'\<\%(procedure\|generic\|map\|port\)'.s:ES && prevs =~ '^\s*(')) |
108 " align closing ")" with opening "(" | 108 " align closing ")" with opening "(" |
109 if curs =~ '^\s*)' | 109 if curs =~ '^\s*)' |
110 return ind2 + stridx(prevs_noi, '(') | 110 return ind2 + stridx(prevs_noi, '(') |
111 endif | 111 endif |
112 let m = matchend(prevs_noi, '(\s*\ze\w') | 112 let m = matchend(prevs_noi, '(\s*\ze\w') |
158 let t = indent(pn) | 158 let t = indent(pn) |
159 if ps !~ '^\s*--' && (t < ind || (t == ind && m == 3)) | 159 if ps !~ '^\s*--' && (t < ind || (t == ind && m == 3)) |
160 " make sure one of these is true | 160 " make sure one of these is true |
161 " keywords: variable + "<=" without ";" ending | 161 " keywords: variable + "<=" without ";" ending |
162 " where: start of previous non-comment line | 162 " where: start of previous non-comment line |
163 " keywords: "generic", "map", "port" | 163 " keywords: "procedure", "generic", "map", "port" |
164 " where: anywhere in previous non-comment line | 164 " where: anywhere in previous non-comment line |
165 " keyword: "(" | 165 " keyword: "(" |
166 " where: start of previous non-comment line | 166 " where: start of previous non-comment line |
167 if m < 3 && ps !~? '^\s*\S\+\s*<=[^;]*'.s:ES | 167 if m < 3 && ps !~? '^\s*\S\+\s*<=[^;]*'.s:ES |
168 if ps =~? s:NC.'\<\%(generic\|map\|port\)\>' || ps =~ '^\s*(' | 168 if ps =~? s:NC.'\<\%(procedure\|generic\|map\|port\)\>' || ps =~ '^\s*(' |
169 let ind = t | 169 let ind = t |
170 endif | 170 endif |
171 break | 171 break |
172 endif | 172 endif |
173 let ind = t | 173 let ind = t |
205 | 205 |
206 " indent: follow indent of previous opening statement, otherwise -sw | 206 " indent: follow indent of previous opening statement, otherwise -sw |
207 " keyword: "begin" | 207 " keyword: "begin" |
208 " where: anywhere in current line | 208 " where: anywhere in current line |
209 if curs =~? s:NC.'\<begin\>' | 209 if curs =~? s:NC.'\<begin\>' |
210 let ind = ind - &sw | |
211 " find previous opening statement of | 210 " find previous opening statement of |
212 " keywords: "architecture", "block", "entity", "function", "generate", "procedure", "process" | 211 " keywords: "architecture", "block", "entity", "function", "generate", "procedure", "process" |
213 let s2 = s:NC.s:NE.'\<\%(architecture\|block\|entity\|function\|generate\|procedure\|process\)\>' | 212 let s2 = s:NC.s:NE.'\<\%(architecture\|block\|entity\|function\|generate\|procedure\|process\)\>' |
214 if (curs !~? s2.'.*'.s:NC.'\<begin\>.*'.s:ES && prevs =~? s2) || m == 1 | 213 |
215 let ind = ind + &sw | 214 let pn = prevnonblank(curn - 1) |
216 endif | 215 let ps = getline(pn) |
217 return ind | 216 while pn > 0 && (ps =~ '^\s*--' || ps !~? s2) |
217 let pn = prevnonblank(pn - 1) | |
218 let ps = getline(pn) | |
219 | |
220 if (ps =~? s:NC.'\<begin\>') | |
221 return indent(pn) - &sw | |
222 endif | |
223 endwhile | |
224 | |
225 if (pn == 0) | |
226 return ind - &sw | |
227 else | |
228 return indent(pn) | |
229 endif | |
218 endif | 230 endif |
219 | 231 |
220 " indent: +sw if previous line is previous opening statement | 232 " indent: +sw if previous line is previous opening statement |
221 " keywords: "record", "units" | 233 " keywords: "record", "units" |
222 " where: anywhere in current line | 234 " where: anywhere in current line |
317 endif | 329 endif |
318 | 330 |
319 " indent: -sw | 331 " indent: -sw |
320 " keywords: "else", "elsif", "end" + "block", "for", "function", "generate", "if", "loop", "procedure", "process", "record", "units" | 332 " keywords: "else", "elsif", "end" + "block", "for", "function", "generate", "if", "loop", "procedure", "process", "record", "units" |
321 " where: start of current line | 333 " where: start of current line |
322 if curs =~? '^\s*\%(else\|elsif\|end\s\+\%(block\|for\|function\|generate\|if\|loop\|procedure\|process\|record\|units\)\)\>' | 334 let s5 = 'block\|for\|function\|generate\|if\|loop\|procedure\|process\|record\|units' |
323 return ind - &sw | 335 if curs =~? '^\s*\%(else\|elsif\|end\s\+\%('.s5.'\)\)\>' |
336 if prevs =~? '^\s*\%(elsif\|'.s5.'\)' | |
337 return ind | |
338 else | |
339 return ind - &sw | |
340 endif | |
324 endif | 341 endif |
325 | 342 |
326 " indent: backtrace previous non-comment lines | 343 " indent: backtrace previous non-comment lines |
327 " keyword: "end" + "case", "component" | 344 " keyword: "end" + "case", "component" |
328 " where: start of current line | 345 " where: start of current line |
393 return ind - &sw | 410 return ind - &sw |
394 endif | 411 endif |
395 | 412 |
396 " **************************************************************************************** | 413 " **************************************************************************************** |
397 " indent: maintain indent of previous opening statement | 414 " indent: maintain indent of previous opening statement |
398 " keywords: without "generic", "map", "port" + ":" but not ":=" + "in", "out", "inout", "buffer", "linkage", variable & ":=" | 415 " keywords: without "procedure", "generic", "map", "port" + ":" but not ":=" + "in", "out", "inout", "buffer", "linkage", variable & ":=" |
399 " where: start of current line | 416 " where: start of current line |
400 if curs =~? '^\s*\%(\<\%(generic\|map\|port\)\>.*\)\@<!\S\+\s*:[^=]\@=\s*\%(\%(in\|out\|inout\|buffer\|linkage\)\>\|\w\+\s\+:=\)' | 417 if curs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=]\@=\s*\%(\%(in\|out\|inout\|buffer\|linkage\)\>\|\w\+\s\+:=\)' |
401 return ind2 | 418 return ind2 |
402 endif | 419 endif |
403 | 420 |
404 " return leftover filtered indent | 421 " return leftover filtered indent |
405 return ind | 422 return ind |