From 5696ed02e49cb9ba076a9a8ce908597720e7df1c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 8 Apr 2021 20:11:09 +1000 Subject: [PATCH] Fix invalid insertion of ; after } closing some functions Function taking a parameter with a struct tag on the last line before the opening { were wrongly treated as structs. Add some additional regex logic to try to catch those cases. Fixes #4136 --- rc/filetype/c-family.kak | 2 +- .../c-family/close-function-with-struct-param/cmd | 1 + .../c-family/close-function-with-struct-param/in | 8 ++++++++ .../c-family/close-function-with-struct-param/out | 10 ++++++++++ .../c-family/close-function-with-struct-param/rc | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/indent/c-family/close-function-with-struct-param/cmd create mode 100644 test/indent/c-family/close-function-with-struct-param/in create mode 100644 test/indent/c-family/close-function-with-struct-param/out create mode 100644 test/indent/c-family/close-function-with-struct-param/rc diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak index 9cc02b6d..6a5b3723 100644 --- a/rc/filetype/c-family.kak +++ b/rc/filetype/c-family.kak @@ -134,7 +134,7 @@ define-command -hidden c-family-indent-on-closing-curly-brace %[ define-command -hidden c-family-insert-on-closing-curly-brace %[ # add a semicolon after a closing brace if part of a class, union or struct definition - try %[ execute-keys -itersel -draft hmB\A\h*(class|struct|union|enum) ';i;' ] + try %[ execute-keys -itersel -draft hmB \A[^\n]+\)\h*(\{|$) \A\h*(class|struct|union|enum) ';i;' ] ] define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[ diff --git a/test/indent/c-family/close-function-with-struct-param/cmd b/test/indent/c-family/close-function-with-struct-param/cmd new file mode 100644 index 00000000..262bd1f0 --- /dev/null +++ b/test/indent/c-family/close-function-with-struct-param/cmd @@ -0,0 +1 @@ +c} diff --git a/test/indent/c-family/close-function-with-struct-param/in b/test/indent/c-family/close-function-with-struct-param/in new file mode 100644 index 00000000..c0a2e31c --- /dev/null +++ b/test/indent/c-family/close-function-with-struct-param/in @@ -0,0 +1,8 @@ +void f(int i, + struct S s) +{ +%( ) + +void g(int i, + struct S s) { +%( ) diff --git a/test/indent/c-family/close-function-with-struct-param/out b/test/indent/c-family/close-function-with-struct-param/out new file mode 100644 index 00000000..053db0aa --- /dev/null +++ b/test/indent/c-family/close-function-with-struct-param/out @@ -0,0 +1,10 @@ +void f(int i, + struct S s) +{ + +} + +void g(int i, + struct S s) { + +} diff --git a/test/indent/c-family/close-function-with-struct-param/rc b/test/indent/c-family/close-function-with-struct-param/rc new file mode 100644 index 00000000..2c2a7247 --- /dev/null +++ b/test/indent/c-family/close-function-with-struct-param/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/c-family.kak" +set buffer filetype cpp