Fix some corner cases in c-family indentation

This commit is contained in:
Maxime Coste 2023-10-25 12:51:16 +11:00
parent d50048d0b4
commit b020922e6f
5 changed files with 51 additions and 7 deletions

View File

@ -126,8 +126,8 @@ define-command -hidden c-family-indent-on-closing-curly-brace %[
# check if alone on the line and select to opening curly brace
execute-keys <a-h><a-:><a-k>^\h+\}$<ret>hm
try %[
# in case open curly brace follows a closing paren, extend to opening paren
execute-keys -draft <a-f>) <a-k> \A\)\h+\{\z <ret>
# in case open curly brace follows a closing paren possibly with qualifiers, extend to opening paren
execute-keys -draft <a-f>) <a-k> \A\)(\h+\w+)*\h*\{\z <ret>
execute-keys <a-F>)M
]
# align to selection start
@ -137,7 +137,10 @@ 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 hmxBx <a-K>\A[^\n]+\)\h*(\{|$)<ret> <a-k>\A\h*(class|struct|union|enum)<ret> '<a-;>;i;<esc>' ]
evaluate-commands -itersel -draft -verbatim try %[
execute-keys -draft hmh <a-?>\b(class|struct|union|enum)\b<ret> <a-K>\{<ret> <a-K>\)(\s+\w+)*\s*\z<ret>
execute-keys -draft ';i;<esc>'
]
]
define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[

View File

@ -1,6 +1,14 @@
struct A
template<typename T> struct A : B
{
int i%(;)
struct C
{
void foo() {
bar()%(;)
}%(;)
struct D {
void baz() %({)
int qux%(;)
if (true) {
if (true) {

View File

@ -1,6 +1,17 @@
struct A
template<typename T> struct A : B
{
int i;
struct C
{
void foo() {
bar();
}
};
};
struct D {
void baz() {
}
int qux;
};
if (true) {

View File

@ -6,3 +6,13 @@ void f(int i,
void g(int i,
struct S s) {
%( )
struct T {
void h(int i,
struct S s) const {
%( )
void i(int i,
struct S s) const final {
%( )
};

View File

@ -8,3 +8,15 @@ void g(int i,
struct S s) {
}
struct T {
void h(int i,
struct S s) const {
}
void i(int i,
struct S s) const final {
}
};