diff --git a/rc/filetype/vhdl.kak b/rc/filetype/vhdl.kak index 289a4875..05a2e933 100644 --- a/rc/filetype/vhdl.kak +++ b/rc/filetype/vhdl.kak @@ -9,9 +9,9 @@ hook global BufCreate .*[.](vhd[l]?) %[ hook global WinSetOption filetype=vhdl %[ require-module vhdl 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 \) vhdl-indent-on-closing-parenthesis - hook -group vhdl-insert window InsertChar \n vhdl-insert-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-insert window InsertChar \n vhdl-insert-on-new-line # Cleanup trailing whitespaces on current line insert end. hook -group vhdl-trim-indent window ModeChange pop:insert:.* %[ try %[ execute-keys -draft x s ^\h+$ d ] ] hook -once -always window WinSetOption filetype=.* %[ remove-hooks window vhdl-.+ ] @@ -182,7 +182,7 @@ define-command -hidden vhdl-insert-on-new-line %[ evaluate-commands %[ try %[ # Validate previous line and that it is not closed yet. - execute-keys -draft kx ^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$) }ix ^x(?i)end\b + execute-keys -draft kx ^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$) j}ijx ^x(?i)(elsif|else|end)\b # Don't add for "if ... generate", it requires "end generate;". execute-keys -draft kx (?i)\bgenerate\b execute-keys -draft oxendif @@ -191,94 +191,95 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add "end generate;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i).*\bgenerate$ }ix ^x(?i)(begin|end) + execute-keys -draft kx ^\h*(?i).*\bgenerate$ j}ijx ^x(?i)(begin|elsif|else|end)\b # Don't add in case of comment line. execute-keys -draft kx ^\h*-- execute-keys -draft oxendgenerate ] ] - # Wisely add "end case;". + # Wisely add "when" and "end case;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(case|.*\h*:\h*case)\b }ix ^x(?i)end - execute-keys -draft oxendcase + # TODO: Case needs special handling. + execute-keys -draft kx ^\h*(?i)(case|.*\h*:\h*case)\b jwx ^x(?i)(end|when) + execute-keys -draft xoxendcasekAwhen ] ] # Wisely add "begin" and "end block;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)((block|.*:\h*block)\b) }ix ^x(?i)(begin|end) + execute-keys -draft kx ^\h*(?i)((block|.*:\h*block)\b) j}ijx ^x(?i)(begin|end)\b execute-keys -draft oxbeginxendblock ] ] # Wisely add "begin" and "end process;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(.*:\h*)?(postponed\h+)?process\b }ix ^x(?i)(begin|end) + execute-keys -draft kx ^\h*(?i)(.*:\h*)?(postponed\h+)?process\b j}ijx ^x(?i)(begin|end) execute-keys -draft oxbeginxendprocess ] ] # Wisely add "end loop;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$ }ix ^x(?i)(end) + execute-keys -draft kx ^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$ j}ijx ^x(?i)(end) execute-keys -draft oxendloop ] ] # Wisely add "end protected;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+protected)$ }ix ^x(?i)(end) + execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+protected)$ j}ijx ^x(?i)(end) execute-keys -draft oxendprotected ] ] # Wisely add "end protected body;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$) }ix ^x(?i)end\h+protected\h+body\b + execute-keys -draft kx ^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$) j}ijx ^x(?i)end\h+protected\h+body\b execute-keys -draft oxendprotectedbody ] ] # Wisely add "end record;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+record\h*)$ }ix ^x(?i)(end) + execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+record\h*)$ j}ijx ^x(?i)(end) execute-keys -draft oxendrecord ] ] # Wisely add ");" for "type ... is (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+\(\h*)$ }ix ^x(\)) + execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+\(\h*)$ j}ijx ^x(\)) execute-keys -draft ox) ] ] # Wisely add "end entity;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)\h*entity\b.*\bis$ }ix ^x(?i)(begin|end) + execute-keys -draft kx ^(?i)\h*entity\b.*\bis$ j}ijx ^x(?i)(begin|end)\b execute-keys -draft oxendentity ] ] # Wisely add "begin" and "end function;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)(\h*\)?\h*return\b.*\bis$) }ix ^x(?i)(begin|end) + execute-keys -draft kx ^(?i)(\h*\)?\h*return\b.*\bis$) j}ijx ^x(?i)(begin|end)\b execute-keys -draft oxbeginxendfunction ] try %[ - execute-keys -draft kx ^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$) }ix ^x(?i)(begin|end) + execute-keys -draft kx ^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$) j}ijx ^x(?i)(begin|end)\b execute-keys -draft oxbeginxendfunction ] ] # Wisely add "begin" and "end procedure;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)(\h*procedure\b.*\bis$) }ix ^x(?i)\b(begin|end)\b + execute-keys -draft kx ^(?i)(\h*procedure\b.*\bis$) j}ijx ^x(?i)\b(begin|end)\b execute-keys -draft oxbeginxendprocedure ] try %[ - execute-keys -draft kx ^(?i)\h*\)\h*\bis$ }ix ^x(?i)\b(begin|end)\b + execute-keys -draft kx ^(?i)\h*\)\h*\bis$ j}ijx ^x(?i)\b(begin|end)\b # Verify that line with opening parenthesis contains "procedure" keyword. execute-keys -draft kx s\) x (?i)\bprocedure\b execute-keys -draft oxbeginxendprocedure @@ -287,7 +288,7 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add "end package;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)(package\b) }ix ^x(?i)(end) + execute-keys -draft kx ^(?i)(package\b) j}ijx ^x(?i)(end)\b # Make sure it is not package body. execute-keys -draft kx(?i)\bbody\b execute-keys -draft oendpackage @@ -296,56 +297,56 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add "end package body;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)(package\h+body\b) }ix ^x(?i)(end) + execute-keys -draft kx ^(?i)(package\h+body\b) j}ijx ^x(?i)(end)\b execute-keys -draft oendpackagebody ] ] # Wisely add "begin" and "end architecture;". evaluate-commands %[ try %[ - execute-keys -draft kx ^(?i)\h*architecture\b }ix ^x(?i)(begin|end) + execute-keys -draft kx ^(?i)\h*architecture\b j}ijx ^x(?i)(begin|end)\b execute-keys -draft oxbeginxendarchitecture ] ] # Wisely add ");" for "port (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)port\h*\($ }ix ^x(\)\;) + execute-keys -draft kx ^\h*(?i)port\h*\($ j}ijx ^x(\)\;) execute-keys -draft ox) ] ] # Wisely add ");" for "port map (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)port\h+map\h*\($ }ix ^x(\)\;) + execute-keys -draft kx ^\h*(?i)port\h+map\h*\($ j}ijx ^x(\)\;) execute-keys -draft ox) ] ] # Wisely add ");" for "generic (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)generic\h*\($ }ix ^x(\)\;) + execute-keys -draft kx ^\h*(?i)generic\h*\($ j}ijx ^x(\)\;) execute-keys -draft ox) ] ] # Wisely add ")" for "generic map (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)generic\h+map\h*\($ }ix ^x(\)) + execute-keys -draft kx ^\h*(?i)generic\h+map\h*\($ j}ijx ^x(\)) execute-keys -draft ox) ] ] # Wisely add ") return ;" for "[pure|impure] function ... (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($ }ix ^x(\)\h*return.*) + execute-keys -draft kx ^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($ j}ijx ^x(\)\h*return.*) execute-keys -draft ox)return ] ] # Wisely add ");" for "procedure ... (". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)procedure\b.*\h*\($ }ix ^x(\)\h*\;) + execute-keys -draft kx ^\h*(?i)procedure\b.*\h*\($ j}ijx ^x(\)\h*\;) execute-keys -draft ox) ] ] @@ -383,26 +384,17 @@ define-command -hidden vhdl-indent-on-new-line %{ # Increase indent after some keywords. try %[ execute-keys -draft kx (?i)\b(begin|block|body|else|for|generate|if|is|loop|process|protected|record|select|then)$ - # Does not indent if in comment line. + # Do not indent if in comment line. execute-keys -draft kx(?i)^\h*-- - # Handle case line in a bit different way. - execute-keys -draft kx(?i)^\h*case\b + # Do not indent for "case ... is". + execute-keys -draft kx^\h*(?i)(case|.*\h*:\h*case)\b execute-keys -draft ] - - # Add "when " and increase indent after "case ... is". - try %[ - execute-keys -draft kx (?i)\h*case\b.*\h+is$ - # Don't indent if in comment line. - execute-keys -draft kx(?i)^\h*-- - execute-keys -draft iwhen - ] - # Copy the indentation of the matching if. try %{ execute-keys -draft , k x ^\h*(elsif\b|else$) gh [c^\h*(\S*\h*:\h*)?if\b,\bend\sif\b x 1 , j K } # Increase indent after some operators. - try %[ execute-keys -draft , k x (\(|=>|<=|:=)$ j ] + try %[ execute-keys -draft k x (\(|=>|<=|:=)$ j ] } }