From 0f3aaa0ecd281cc932bbb3faed137e8150d0ed79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Mon, 15 Aug 2022 10:39:13 +0200 Subject: [PATCH 1/4] VHDL filetype: Don't increase indent after when in case statement. --- rc/filetype/vhdl.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/vhdl.kak b/rc/filetype/vhdl.kak index 289a4875..afe0e6b7 100644 --- a/rc/filetype/vhdl.kak +++ b/rc/filetype/vhdl.kak @@ -390,12 +390,12 @@ define-command -hidden vhdl-indent-on-new-line %{ execute-keys -draft ] - # Add "when " and increase indent after "case ... is". + # Add "when " 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 + execute-keys -draft iwhen ] # Copy the indentation of the matching if. From ed7078230fdd6222e1d860760b7d91203f53c454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Mon, 15 Aug 2022 12:45:32 +0200 Subject: [PATCH 2/4] VHDL filetype: Fix adding closing tags. --- rc/filetype/vhdl.kak | 56 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/rc/filetype/vhdl.kak b/rc/filetype/vhdl.kak index afe0e6b7..78d00389 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)end\b # Don't add for "if ... generate", it requires "end generate;". execute-keys -draft kx (?i)\bgenerate\b execute-keys -draft oxendif @@ -191,7 +191,7 @@ 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|end|else)\b # Don't add in case of comment line. execute-keys -draft kx ^\h*-- execute-keys -draft oxendgenerate @@ -200,85 +200,87 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add "end case;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i)(case|.*\h*:\h*case)\b }ix ^x(?i)end + # TODO: Case needs special handling. + execute-keys -draft kx ^\h*(?i)(case|.*\h*:\h*case)\b }ix ^x(?i)(end|when) execute-keys -draft oxendcase ] ] # 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(\)) + # FIXME: There is some problem. + 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 +289,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 +298,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) ] ] From f3a05d41cb022fff42711cb81362ec5313cc87a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Mon, 15 Aug 2022 13:36:38 +0200 Subject: [PATCH 3/4] VHDL filetype: Fix behavior for case statement. --- rc/filetype/vhdl.kak | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/rc/filetype/vhdl.kak b/rc/filetype/vhdl.kak index 78d00389..bceab2f2 100644 --- a/rc/filetype/vhdl.kak +++ b/rc/filetype/vhdl.kak @@ -197,12 +197,12 @@ define-command -hidden vhdl-insert-on-new-line %[ execute-keys -draft oxendgenerate ] ] - # Wisely add "end case;". + # Wisely add "when" and "end case;". evaluate-commands %[ try %[ # TODO: Case needs special handling. - execute-keys -draft kx ^\h*(?i)(case|.*\h*:\h*case)\b }ix ^x(?i)(end|when) - execute-keys -draft oxendcase + 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;". @@ -250,7 +250,6 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add ");" for "type ... is (". evaluate-commands %[ try %[ - # FIXME: There is some problem. execute-keys -draft kx ^\h*(?i)(type\b.*\bis\h+\(\h*)$ j}ijx ^x(\)) execute-keys -draft ox) ] @@ -385,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 " 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 ] } } From ce18ac991820922f49f755d368e4616b30cbb6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Mon, 15 Aug 2022 13:41:07 +0200 Subject: [PATCH 4/4] VHDL filetype: Fix if statement behavior. --- rc/filetype/vhdl.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/vhdl.kak b/rc/filetype/vhdl.kak index bceab2f2..05a2e933 100644 --- a/rc/filetype/vhdl.kak +++ b/rc/filetype/vhdl.kak @@ -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)$) j}ijx ^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,7 +191,7 @@ define-command -hidden vhdl-insert-on-new-line %[ # Wisely add "end generate;". evaluate-commands %[ try %[ - execute-keys -draft kx ^\h*(?i).*\bgenerate$ j}ijx ^x(?i)(begin|end|else)\b + 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