Mercurial > vim
annotate runtime/indent/systemverilog.vim @ 33132:811555b5ab8b v9.0.1848
patch 9.0.1848: [security] buffer-overflow in vim_regsub_both()
Commit: https://github.com/vim/vim/commit/ced2c7394aafdc90fb7845e09b3a3fee23d48cb1
Author: Christian Brabandt <cb@256bit.org>
Date: Sat Sep 2 21:15:52 2023 +0200
patch 9.0.1848: [security] buffer-overflow in vim_regsub_both()
Problem: buffer-overflow in vim_regsub_both()
Solution: Check remaining space
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 02 Sep 2023 21:45:03 +0200 |
parents | 2198955f9e27 |
children | d6dde6229b36 |
rev | line source |
---|---|
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1 " Vim indent file |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2 " Language: SystemVerilog |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
3 " Maintainer: kocha <kocha.lsifrontend@gmail.com> |
18186 | 4 " Last Change: 05-Feb-2017 by Bilal Wasim |
29659 | 5 " 03-Aug-2022 Improved indent |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
7 " Only load this indent file when no other was loaded. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
8 if exists("b:did_indent") |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
9 finish |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
10 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
11 let b:did_indent = 1 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
12 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
13 setlocal indentexpr=SystemVerilogIndent() |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
14 setlocal indentkeys=!^F,o,O,0),0},=begin,=end,=join,=endcase,=join_any,=join_none |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 setlocal indentkeys+==endmodule,=endfunction,=endtask,=endspecify |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
16 setlocal indentkeys+==endclass,=endpackage,=endsequence,=endclocking |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
17 setlocal indentkeys+==endinterface,=endgroup,=endprogram,=endproperty,=endchecker |
29659 | 18 setlocal indentkeys+==`else,=`elsif,=`endif |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
19 |
28379 | 20 let b:undo_indent = "setl inde< indk<" |
21 | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
22 " Only define the function once. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
23 if exists("*SystemVerilogIndent") |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
24 finish |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
25 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
26 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
27 let s:cpo_save = &cpo |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
28 set cpo&vim |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
29 |
29659 | 30 let s:multiple_comment = 0 |
31 let s:open_statement = 0 | |
32 | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
33 function SystemVerilogIndent() |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
34 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
35 if exists('b:systemverilog_indent_width') |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
36 let offset = b:systemverilog_indent_width |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
37 else |
11518 | 38 let offset = shiftwidth() |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
39 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
40 if exists('b:systemverilog_indent_modules') |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
41 let indent_modules = offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
42 else |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
43 let indent_modules = 0 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
44 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
45 |
29659 | 46 if exists('b:systemverilog_indent_ifdef_off') |
47 let indent_ifdef = 0 | |
48 else | |
49 let indent_ifdef = 1 | |
50 endif | |
51 | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
52 " Find a non-blank line above the current line. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
53 let lnum = prevnonblank(v:lnum - 1) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
54 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
55 " At the start of the file use zero indent. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
56 if lnum == 0 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
57 return 0 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
58 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
59 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
60 let lnum2 = prevnonblank(lnum - 1) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
61 let curr_line = getline(v:lnum) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
62 let last_line = getline(lnum) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
63 let last_line2 = getline(lnum2) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
64 let ind = indent(lnum) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
65 let ind2 = indent(lnum - 1) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
66 " Define the condition of an open statement |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
67 " Exclude the match of //, /* or */ |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
68 let sv_openstat = '\(\<or\>\|\([*/]\)\@<![*(,{><+-/%^&|!=?:]\([*/]\)\@!\)' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
69 " Define the condition when the statement ends with a one-line comment |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
70 let sv_comment = '\(//.*\|/\*.*\*/\s*\)' |
29659 | 71 if exists('b:systemverilog_indent_verbose') |
72 let vverb_str = 'INDENT VERBOSE: '. v:lnum .":" | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
73 let vverb = 1 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
74 else |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
75 let vverb = 0 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
76 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
77 |
29659 | 78 " Multiple-line comment count |
79 if curr_line =~ '^\s*/\*' && curr_line !~ '/\*.\{-}\*/' | |
80 let s:multiple_comment += 1 | |
81 if vverb | echom vverb_str "Start of multiple-line commnt" | endif | |
82 elseif curr_line =~ '\*/\s*$' && curr_line !~ '/\*.\{-}\*/' | |
83 let s:multiple_comment -= 1 | |
84 if vverb | echom vverb_str "End of multiple-line commnt" | endif | |
85 return ind | |
86 endif | |
87 " Maintain indentation during commenting. | |
88 if s:multiple_comment > 0 | |
89 return ind | |
90 endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
91 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
92 " Indent after if/else/for/case/always/initial/specify/fork blocks |
29659 | 93 if last_line =~ '^\s*\(end\)\=\s*`\@<!\<\(if\|else\)\>' || |
94 \ last_line =~ '^\s*\<\(for\|while\|repeat\|case\%[[zx]]\|do\|foreach\|forever\|randcase\)\>' || | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
95 \ last_line =~ '^\s*\<\(always\|always_comb\|always_ff\|always_latch\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
96 \ last_line =~ '^\s*\<\(initial\|specify\|fork\|final\)\>' |
29659 | 97 if last_line !~ '\(;\|\<end\>\|\*/\)\s*' . sv_comment . '*$' || |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
98 \ last_line =~ '\(//\|/\*\).*\(;\|\<end\>\)\s*' . sv_comment . '*$' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
99 let ind = ind + offset |
29659 | 100 if vverb | echom vverb_str "Indent after a block statement." | endif |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
101 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
102 " Indent after function/task/class/package/sequence/clocking/ |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
103 " interface/covergroup/property/checkerprogram blocks |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
104 elseif last_line =~ '^\s*\<\(function\|task\|class\|package\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
105 \ last_line =~ '^\s*\<\(sequence\|clocking\|interface\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
106 \ last_line =~ '^\s*\(\w\+\s*:\)\=\s*\<covergroup\>' || |
29659 | 107 \ last_line =~ '^\s*\<\(property\|checker\|program\)\>' || |
108 \ ( last_line =~ '^\s*\<virtual\>' && last_line =~ '\<\(function\|task\|class\|interface\)\>' ) || | |
109 \ ( last_line =~ '^\s*\<pure\>' && last_line =~ '\<virtual\>' && last_line =~ '\<\(function\|task\)\>' ) | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
110 if last_line !~ '\<end\>\s*' . sv_comment . '*$' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
111 \ last_line =~ '\(//\|/\*\).*\(;\|\<end\>\)\s*' . sv_comment . '*$' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
112 let ind = ind + offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
113 if vverb |
29659 | 114 echom vverb_str "Indent after function/task/class block statement." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
115 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
116 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
117 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
118 " Indent after module/function/task/specify/fork blocks |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
119 elseif last_line =~ '^\s*\(\<extern\>\s*\)\=\<module\>' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
120 let ind = ind + indent_modules |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
121 if vverb && indent_modules |
29659 | 122 echom vverb_str "Indent after module statement." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
123 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
124 if last_line =~ '[(,]\s*' . sv_comment . '*$' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
125 \ last_line !~ '\(//\|/\*\).*[(,]\s*' . sv_comment . '*$' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
126 let ind = ind + offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
127 if vverb |
29659 | 128 echom vverb_str "Indent after a multiple-line module statement." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
129 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
130 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
131 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
132 " Indent after a 'begin' statement |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
133 elseif last_line =~ '\(\<begin\>\)\(\s*:\s*\w\+\)*' . sv_comment . '*$' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
134 \ last_line !~ '\(//\|/\*\).*\(\<begin\>\)' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
135 \ ( last_line2 !~ sv_openstat . '\s*' . sv_comment . '*$' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
136 \ last_line2 =~ '^\s*[^=!]\+\s*:\s*' . sv_comment . '*$' ) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
137 let ind = ind + offset |
29659 | 138 if vverb | echom vverb_str "Indent after begin statement." | endif |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
139 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
140 " Indent after a '{' or a '(' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
141 elseif last_line =~ '[{(]' . sv_comment . '*$' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
142 \ last_line !~ '\(//\|/\*\).*[{(]' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
143 \ ( last_line2 !~ sv_openstat . '\s*' . sv_comment . '*$' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
144 \ last_line2 =~ '^\s*[^=!]\+\s*:\s*' . sv_comment . '*$' ) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
145 let ind = ind + offset |
29659 | 146 if vverb | echom vverb_str "Indent after begin statement." | endif |
147 | |
148 " Ignore de-indent for the end of one-line block | |
149 elseif ( last_line !~ '\<begin\>' || | |
150 \ last_line =~ '\(//\|/\*\).*\<begin\>' ) && | |
151 \ last_line2 =~ '\<\(`\@<!if\|`\@<!else\|for\|always\|initial\|do\|foreach\|forever\|final\)\>.*' . | |
152 \ sv_comment . '*$' && | |
153 \ last_line2 !~ '\(//\|/\*\).*\<\(`\@<!if\|`\@<!else\|for\|always\|initial\|do\|foreach\|forever\|final\)\>' && | |
154 \ last_line2 !~ sv_openstat . '\s*' . sv_comment . '*$' && | |
155 \ ( last_line2 !~ '\<begin\>' || | |
156 \ last_line2 =~ '\(//\|/\*\).*\<begin\>' ) && | |
157 \ last_line2 =~ ')*\s*;\s*' . sv_comment . '*$' | |
158 if vverb | |
159 echom vverb_str "Ignore de-indent after the end of one-line statement." | |
160 endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
161 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
162 " De-indent for the end of one-line block |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
163 elseif ( last_line !~ '\<begin\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
164 \ last_line =~ '\(//\|/\*\).*\<begin\>' ) && |
18186 | 165 \ last_line2 =~ '\<\(`\@<!if\|`\@<!else\|for\|always\|initial\|do\|foreach\|forever\|final\)\>.*' . |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
166 \ sv_comment . '*$' && |
18186 | 167 \ last_line2 !~ '\(//\|/\*\).*\<\(`\@<!if\|`\@<!else\|for\|always\|initial\|do\|foreach\|forever\|final\)\>' && |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
168 \ last_line2 !~ sv_openstat . '\s*' . sv_comment . '*$' && |
29659 | 169 \ last_line2 !~ '\(;\|\<end\>\|\*/\)\s*' . sv_comment . '*$' && |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
170 \ ( last_line2 !~ '\<begin\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
171 \ last_line2 =~ '\(//\|/\*\).*\<begin\>' ) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
172 let ind = ind - offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
173 if vverb |
29659 | 174 echom vverb_str "De-indent after the end of one-line statement." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
175 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
176 |
29659 | 177 " Multiple-line statement (including case statement) |
178 " Open statement | |
179 " Ident the first open line | |
180 elseif last_line =~ sv_openstat . '\s*' . sv_comment . '*$' && | |
181 \ last_line !~ '\(//\|/\*\).*' . sv_openstat . '\s*$' && | |
182 \ last_line2 !~ sv_openstat . '\s*' . sv_comment . '*$' | |
183 let ind = ind + offset | |
184 let s:open_statement = 1 | |
185 if vverb | echom vverb_str "Indent after an open statement." | endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
186 |
29659 | 187 " `ifdef or `ifndef or `elsif or `else |
188 elseif last_line =~ '^\s*`\<\(ifn\?def\|elsif\|else\)\>' && indent_ifdef | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
189 let ind = ind + offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
190 if vverb |
29659 | 191 echom vverb_str "Indent after a `ifdef or `ifndef or `elsif or `else statement." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
192 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
193 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
194 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
195 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
196 " Re-indent current line |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
197 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
198 " De-indent on the end of the block |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
199 " join/end/endcase/endfunction/endtask/endspecify |
29659 | 200 if curr_line =~ '^\s*\<\(join\|join_any\|join_none\|\|end\|endcase\)\>' || |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
201 \ curr_line =~ '^\s*\<\(endfunction\|endtask\|endspecify\|endclass\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
202 \ curr_line =~ '^\s*\<\(endpackage\|endsequence\|endclocking\|endinterface\)\>' || |
29659 | 203 \ curr_line =~ '^\s*\<\(endgroup\|endproperty\|endchecker\|endprogram\)\>' |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
204 let ind = ind - offset |
29659 | 205 if vverb | echom vverb_str "De-indent the end of a block." | endif |
206 if s:open_statement == 1 | |
207 let ind = ind - offset | |
208 let s:open_statement = 0 | |
209 if vverb | echom vverb_str "De-indent the close statement." | endif | |
210 endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
211 elseif curr_line =~ '^\s*\<endmodule\>' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
212 let ind = ind - indent_modules |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
213 if vverb && indent_modules |
29659 | 214 echom vverb_str "De-indent the end of a module." |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
215 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
216 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
217 " De-indent on a stand-alone 'begin' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
218 elseif curr_line =~ '^\s*\<begin\>' |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
219 if last_line !~ '^\s*\<\(function\|task\|specify\|module\|class\|package\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
220 \ last_line !~ '^\s*\<\(sequence\|clocking\|interface\|covergroup\)\>' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
221 \ last_line !~ '^\s*\<\(property\|checker\|program\)\>' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
222 \ last_line !~ '^\s*\()*\s*;\|)\+\)\s*' . sv_comment . '*$' && |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
223 \ ( last_line =~ |
18186 | 224 \ '\<\(`\@<!if\|`\@<!else\|for\|case\%[[zx]]\|always\|initial\|do\|foreach\|forever\|randcase\|final\)\>' || |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
225 \ last_line =~ ')\s*' . sv_comment . '*$' || |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
226 \ last_line =~ sv_openstat . '\s*' . sv_comment . '*$' ) |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
227 let ind = ind - offset |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
228 if vverb |
29659 | 229 echom vverb_str "De-indent a stand alone begin statement." |
230 endif | |
231 if s:open_statement == 1 | |
232 let ind = ind - offset | |
233 let s:open_statement = 0 | |
234 if vverb | echom vverb_str "De-indent the close statement." | endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
235 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
236 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
237 |
29659 | 238 " " Close statement |
239 " " De-indent for an optional close parenthesis and a semicolon, and only | |
240 " " if there exists precedent non-whitespace char | |
241 " elseif last_line =~ ')*\s*;\s*' . sv_comment . '*$' && | |
242 " \ last_line !~ '^\s*)*\s*;\s*' . sv_comment . '*$' && | |
243 " \ last_line !~ '\(//\|/\*\).*\S)*\s*;\s*' . sv_comment . '*$' && | |
244 " \ ( last_line2 =~ sv_openstat . '\s*' . sv_comment . '*$' && | |
245 " \ last_line2 !~ ';\s*//.*$') && | |
246 " \ last_line2 !~ '^\s*' . sv_comment . '$' | |
247 " let ind = ind - offset | |
248 " if vverb | echom vverb_str "De-indent after a close statement." | endif | |
249 | |
250 " " De-indent after the end of multiple-line statement | |
251 " elseif curr_line =~ '^\s*)' && | |
252 " \ ( last_line =~ sv_openstat . '\s*' . sv_comment . '*$' || | |
253 " \ last_line !~ sv_openstat . '\s*' . sv_comment . '*$' && | |
254 " \ last_line2 =~ sv_openstat . '\s*' . sv_comment . '*$' ) | |
255 " let ind = ind - offset | |
256 " if vverb | |
257 " echom vverb_str "De-indent the end of a multiple statement." | |
258 " endif | |
259 | |
260 " De-indent `elsif or `else or `endif | |
261 elseif curr_line =~ '^\s*`\<\(elsif\|else\|endif\)\>' && indent_ifdef | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
262 let ind = ind - offset |
29659 | 263 if vverb | echom vverb_str "De-indent `elsif or `else or `endif statement." | endif |
264 if b:systemverilog_open_statement == 1 | |
265 let ind = ind - offset | |
266 let b:systemverilog_open_statement = 0 | |
267 if vverb | echom vverb_str "De-indent the open statement." | endif | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
268 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
269 endif |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
270 |
25773 | 271 " Return the indentation |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
272 return ind |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
273 endfunction |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
274 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
275 let &cpo = s:cpo_save |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
276 unlet s:cpo_save |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
277 |
23573 | 278 " vim:sw=2 |
29659 | 279 |