Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question re: brace terminators (C/C++) #37

Open
Falkgaard opened this issue Mar 27, 2021 · 2 comments · May be fixed by #43
Open

Question re: brace terminators (C/C++) #37

Falkgaard opened this issue Mar 27, 2021 · 2 comments · May be fixed by #43

Comments

@Falkgaard
Copy link

Falkgaard commented Mar 27, 2021

Is it possible to configure it so that the line with the terminating brace } and/or blank lines gets included in the fold?

If I have:

void f() {
   std::puts("foo");
}

void g() {
   std::puts("bar");
}

struct baz {
  int x;
  int y;
};

I'd like it to fold into:

void f() { ---------------------------------- 4 lines
void g() { ---------------------------------- 4 lines
struct baz { -------------------------------- 5 lines

instead of:

void f() { ---------------------------------- 2 lines
}

void g() { ---------------------------------- 2 lines
}

struct baz { -------------------------------- 3 lines
};

EDIT 1:

It seems like putting the opening brace on its own line might accomplish what I want, I'll report back here after further testing.


EDIT 2:

Never mind that... same results regardless, but in some cases it seems to fold as I want, and in others it doesn't. Not quite sure yet what's causing the difference in behaviour for me.

But one issues seems to be when the brace ends with a semi-colon such as in the case of struct, class, union, enum, or brace initialization. But then again, in some cases it works... for example:

In one file I have these (white space annotated for clarity):

// ...
<blank line>
// using aliases:
<tab> using U8  = uint8_t;
<tab> using U16 = uint16_t;
<tab> using U32 = uint32_t;
<tab> using U64 = uint64_t;
<tab> using I8  = int8_t;
<tab> using I16 = int16_t;
<tab> using I32 = int32_t;
<tab> using I64 = int64_t;
<tab> using F32 = float;
<tab> using F64 = double;
<blank line>
struct FG { // foreground color
<tab> U8 code = 255;
};
<blank line>
[[nodiscard]] inline auto to_string( FG const fg ) -> std::string {
<tab> return std::string("38;5;") + std::to_string(fg.code);
}
<blank line>
struct BG { // background color
<tab> U8 code = 238;
};
<blank line>
// ...

and I can fold all the using aliases into the comment, the function and BG properly, but not FG.

If I do try to fold them all it becomes:

// ...
// using aliases:                                                      12 lines
struct FG { // foreground color                                         2 lines
};
<blank line>
[[nodiscard]] inline auto to_string( FG const fg ) -> std::string {     4 lines
struct BG { // background color                                         4 lines
// ...

So in the above case all but FG work as desired. Super weird.

@Falkgaard
Copy link
Author

Falkgaard commented Mar 30, 2021

I've found a hacky workaround that generally seems to give the result I'm looking for:

I insert a space between every }; so it becomes } ;, and I appent a space and comment after every free-standing } (i.e. } //) that I want to to terminate and foldーwhich generally are functions.

tejasvi added a commit to tejasvi/vim-anyfold that referenced this issue Jan 20, 2022
@tejasvi tejasvi linked a pull request Jan 20, 2022 that will close this issue
@tejasvi
Copy link

tejasvi commented Jan 20, 2022

You can use Plug tejasvi/vim-anyfold meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants