Autoindent always uses row above, even when it's empty

Hi, is there some reasonably easy way to make autoindentation use the previous non-empty line when calculating what indentation to use, instead of always using the previous line?

For example:

int main() {
    printf("hello, world");
    // Some empty lines follow:


}

When the cursor is on the last line, with the closing brace }, and I press O to insert above that line, I would want the code to be indented as the comment above, not using the 0-space indentation of the empty lines.

It seems like Kakoune uses file-type specific hooks to handle auto-indentation, so I guess it would be a lot of work to change this for all file types?