VHDL filetype: Fix adding closing tags.

This commit is contained in:
Michał Kruszewski 2022-08-15 12:45:32 +02:00
parent 0f3aaa0ecd
commit ed7078230f

View File

@ -9,9 +9,9 @@ hook global BufCreate .*[.](vhd[l]?) %[
hook global WinSetOption filetype=vhdl %[ hook global WinSetOption filetype=vhdl %[
require-module vhdl require-module vhdl
set-option window static_words %opt{vhdl_static_words} set-option window static_words %opt{vhdl_static_words}
hook -group vhdl-indent window InsertChar \n vhdl-indent-on-new-line hook -group vhdl-indent window InsertChar \n vhdl-indent-on-new-line
hook -group vhdl-indent window InsertChar \) vhdl-indent-on-closing-parenthesis hook -group vhdl-indent window InsertChar \) vhdl-indent-on-closing-parenthesis
hook -group vhdl-insert window InsertChar \n vhdl-insert-on-new-line hook -group vhdl-insert window InsertChar \n vhdl-insert-on-new-line
# Cleanup trailing whitespaces on current line insert end. # Cleanup trailing whitespaces on current line insert end.
hook -group vhdl-trim-indent window ModeChange pop:insert:.* %[ try %[ execute-keys -draft <semicolon> x s ^\h+$ <ret> d ] ] hook -group vhdl-trim-indent window ModeChange pop:insert:.* %[ try %[ execute-keys -draft <semicolon> x s ^\h+$ <ret> d ] ]
hook -once -always window WinSetOption filetype=.* %[ remove-hooks window vhdl-.+ ] hook -once -always window WinSetOption filetype=.* %[ remove-hooks window vhdl-.+ ]
@ -182,7 +182,7 @@ define-command -hidden vhdl-insert-on-new-line %[
evaluate-commands %[ evaluate-commands %[
try %[ try %[
# Validate previous line and that it is not closed yet. # Validate previous line and that it is not closed yet.
execute-keys -draft kx <a-k>^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$)<ret> }ix <a-K>^<c-r>x(?i)end\b<ret> execute-keys -draft kx <a-k>^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$)<ret> j}ijx <a-K>^<c-r>x(?i)end\b<ret>
# Don't add for "if ... generate", it requires "end generate;". # Don't add for "if ... generate", it requires "end generate;".
execute-keys -draft kx <a-K>(?i)\bgenerate\b<ret> execute-keys -draft kx <a-K>(?i)\bgenerate\b<ret>
execute-keys -draft o<c-r>xend<space>if<semicolon><esc> execute-keys -draft o<c-r>xend<space>if<semicolon><esc>
@ -191,7 +191,7 @@ define-command -hidden vhdl-insert-on-new-line %[
# Wisely add "end generate;". # Wisely add "end generate;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i).*\bgenerate$<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^\h*(?i).*\bgenerate$<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end|else)\b<ret>
# Don't add in case of comment line. # Don't add in case of comment line.
execute-keys -draft kx <a-K>^\h*--<ret> execute-keys -draft kx <a-K>^\h*--<ret>
execute-keys -draft o<c-r>xend<space>generate<semicolon><esc> execute-keys -draft o<c-r>xend<space>generate<semicolon><esc>
@ -200,85 +200,87 @@ define-command -hidden vhdl-insert-on-new-line %[
# Wisely add "end case;". # Wisely add "end case;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(case|.*\h*:\h*case)\b<ret> }ix <a-K>^<c-r>x(?i)end<ret> # TODO: Case needs special handling.
execute-keys -draft kx <a-k>^\h*(?i)(case|.*\h*:\h*case)\b<ret> }ix <a-K>^<c-r>x(?i)(end|when)<ret>
execute-keys -draft o<c-r>xend<space>case<semicolon><esc> execute-keys -draft o<c-r>xend<space>case<semicolon><esc>
] ]
] ]
# Wisely add "begin" and "end block;". # Wisely add "begin" and "end block;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)((block|.*:\h*block)\b)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^\h*(?i)((block|.*:\h*block)\b)<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>block<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>block<semicolon><esc>
] ]
] ]
# Wisely add "begin" and "end process;". # Wisely add "begin" and "end process;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(.*:\h*)?(postponed\h+)?process\b<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^\h*(?i)(.*:\h*)?(postponed\h+)?process\b<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>process<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>process<semicolon><esc>
] ]
] ]
# Wisely add "end loop;". # Wisely add "end loop;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret> execute-keys -draft kx <a-k>^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$<ret> j}ijx <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>loop<semicolon><esc> execute-keys -draft o<c-r>xend<space>loop<semicolon><esc>
] ]
] ]
# Wisely add "end protected;". # Wisely add "end protected;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+protected)$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret> execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+protected)$<ret> j}ijx <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>protected<semicolon><esc> execute-keys -draft o<c-r>xend<space>protected<semicolon><esc>
] ]
] ]
# Wisely add "end protected body;". # Wisely add "end protected body;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$)<ret> }ix <a-K>^<c-r>x(?i)end\h+protected\h+body\b<ret> execute-keys -draft kx <a-k>^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$)<ret> j}ijx <a-K>^<c-r>x(?i)end\h+protected\h+body\b<ret>
execute-keys -draft o<c-r>xend<space>protected<space>body<semicolon><esc> execute-keys -draft o<c-r>xend<space>protected<space>body<semicolon><esc>
] ]
] ]
# Wisely add "end record;". # Wisely add "end record;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+record\h*)$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret> execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+record\h*)$<ret> j}ijx <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>record<semicolon><esc> execute-keys -draft o<c-r>xend<space>record<semicolon><esc>
] ]
] ]
# Wisely add ");" for "type ... is (". # Wisely add ");" for "type ... is (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+\(\h*)$<ret> }ix <a-K>^<c-r>x(\))<ret> # FIXME: There is some problem.
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+\(\h*)$<ret> j}ijx <a-K>^<c-r>x(\))<ret>
execute-keys -draft o<c-r>x)<semicolon><esc> execute-keys -draft o<c-r>x)<semicolon><esc>
] ]
] ]
# Wisely add "end entity;". # Wisely add "end entity;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)\h*entity\b.*\bis$<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^(?i)\h*entity\b.*\bis$<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)\b<ret>
execute-keys -draft o<c-r>xend<space>entity<semicolon><esc> execute-keys -draft o<c-r>xend<space>entity<semicolon><esc>
] ]
] ]
# Wisely add "begin" and "end function;". # Wisely add "begin" and "end function;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(\h*\)?\h*return\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^(?i)(\h*\)?\h*return\b.*\bis$)<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc>
] ]
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$)<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc>
] ]
] ]
# Wisely add "begin" and "end procedure;". # Wisely add "begin" and "end procedure;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(\h*procedure\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)\b(begin|end)\b<ret> execute-keys -draft kx <a-k>^(?i)(\h*procedure\b.*\bis$)<ret> j}ijx <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc>
] ]
try %[ try %[
execute-keys -draft kx <a-k>^(?i)\h*\)\h*\bis$<ret> }ix <a-K>^<c-r>x(?i)\b(begin|end)\b<ret> execute-keys -draft kx <a-k>^(?i)\h*\)\h*\bis$<ret> j}ijx <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
# Verify that line with opening parenthesis contains "procedure" keyword. # Verify that line with opening parenthesis contains "procedure" keyword.
execute-keys -draft kx s\)<ret> <a-m><semicolon> x<a-k> (?i)\bprocedure\b<ret> execute-keys -draft kx s\)<ret> <a-m><semicolon> x<a-k> (?i)\bprocedure\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc>
@ -287,7 +289,7 @@ define-command -hidden vhdl-insert-on-new-line %[
# Wisely add "end package;". # Wisely add "end package;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(package\b)<ret> }ix <a-K>^<c-r>x(?i)(end)<ret> execute-keys -draft kx <a-k>^(?i)(package\b)<ret> j}ijx <a-K>^<c-r>x(?i)(end)\b<ret>
# Make sure it is not package body. # Make sure it is not package body.
execute-keys -draft kx<a-K>(?i)\bbody\b<ret> execute-keys -draft kx<a-K>(?i)\bbody\b<ret>
execute-keys -draft oend<space>package<semicolon><esc> execute-keys -draft oend<space>package<semicolon><esc>
@ -296,56 +298,56 @@ define-command -hidden vhdl-insert-on-new-line %[
# Wisely add "end package body;". # Wisely add "end package body;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)(package\h+body\b)<ret> }ix <a-K>^<c-r>x(?i)(end)<ret> execute-keys -draft kx <a-k>^(?i)(package\h+body\b)<ret> j}ijx <a-K>^<c-r>x(?i)(end)\b<ret>
execute-keys -draft oend<space>package<space>body<semicolon><esc> execute-keys -draft oend<space>package<space>body<semicolon><esc>
] ]
] ]
# Wisely add "begin" and "end architecture;". # Wisely add "begin" and "end architecture;".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^(?i)\h*architecture\b<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret> execute-keys -draft kx <a-k>^(?i)\h*architecture\b<ret> j}ijx <a-K>^<c-r>x(?i)(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>architecture<semicolon><esc> execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>architecture<semicolon><esc>
] ]
] ]
# Wisely add ");" for "port (". # Wisely add ");" for "port (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)port\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret> execute-keys -draft kx <a-k>^\h*(?i)port\h*\($<ret> j}ijx <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc> execute-keys -draft o<c-r>x)<semicolon><esc>
] ]
] ]
# Wisely add ");" for "port map (". # Wisely add ");" for "port map (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)port\h+map\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret> execute-keys -draft kx <a-k>^\h*(?i)port\h+map\h*\($<ret> j}ijx <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc> execute-keys -draft o<c-r>x)<semicolon><esc>
] ]
] ]
# Wisely add ");" for "generic (". # Wisely add ");" for "generic (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)generic\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret> execute-keys -draft kx <a-k>^\h*(?i)generic\h*\($<ret> j}ijx <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc> execute-keys -draft o<c-r>x)<semicolon><esc>
] ]
] ]
# Wisely add ")" for "generic map (". # Wisely add ")" for "generic map (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)generic\h+map\h*\($<ret> }ix <a-K>^<c-r>x(\))<ret> execute-keys -draft kx <a-k>^\h*(?i)generic\h+map\h*\($<ret> j}ijx <a-K>^<c-r>x(\))<ret>
execute-keys -draft o<c-r>x)<esc> execute-keys -draft o<c-r>x)<esc>
] ]
] ]
# Wisely add ") return ;" for "[pure|impure] function ... (". # Wisely add ") return ;" for "[pure|impure] function ... (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($<ret> }ix <a-K>^<c-r>x(\)\h*return.*)<ret> execute-keys -draft kx <a-k>^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($<ret> j}ijx <a-K>^<c-r>x(\)\h*return.*)<ret>
execute-keys -draft o<c-r>x)<space>return<space><semicolon><esc> execute-keys -draft o<c-r>x)<space>return<space><semicolon><esc>
] ]
] ]
# Wisely add ");" for "procedure ... (". # Wisely add ");" for "procedure ... (".
evaluate-commands %[ evaluate-commands %[
try %[ try %[
execute-keys -draft kx <a-k>^\h*(?i)procedure\b.*\h*\($<ret> }ix <a-K>^<c-r>x(\)\h*\;)<ret> execute-keys -draft kx <a-k>^\h*(?i)procedure\b.*\h*\($<ret> j}ijx <a-K>^<c-r>x(\)\h*\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc> execute-keys -draft o<c-r>x)<semicolon><esc>
] ]
] ]