Use AlignAfterOpenBracket BlockIndent for clang-format #19632

Open
opened 2026-01-31 06:49:16 +00:00 by claunia · 0 comments
Owner

Originally created by @lhecker on GitHub (Apr 4, 2023).

This makes you wonder if you scared your code, because it's trying to flee from your screen:

bool ControlCore::SendMouseEvent(const til::point viewportPos,
                                 const unsigned int uiButton,
                                 const ControlKeyStates states,
                                 const short wheelDelta,
                                 const TerminalInput::MouseButtonState state)
{
    return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
}

This on the other hand is the one true way, no exceptions (sample size = 1, myself):

bool ControlCore::SendMouseEvent(
    const til::point viewportPos,
    const unsigned int uiButton,
    const ControlKeyStates states,
    const short wheelDelta,
    const TerminalInput::MouseButtonState state
) {
    return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
}

We can get this behavior by setting AlignAfterOpenBracket: BlockIndent in .clang-format. The problems:

  • Code like the former example, will not be formatted like the latter example even if we set that option, because the former isn't actually block indented to begin with! It's just line breaks after the first argument and so clang-format turns it into:
    bool ControlCore::SendMouseEvent(const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state)
    {
        return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
    }
    
    Most of our code looks like that unfortunately. This would be correct from the POV of clang-format:
    bool ControlCore::SendMouseEvent(
        const til::point viewportPos,
        const unsigned int uiButton,
        const ControlKeyStates states,
        const short wheelDelta,
        const TerminalInput::MouseButtonState state)
    {
        return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
    }
    
    This can be mostly fixed with this regex replacement: ((?!\s|::)\w+\()([^{}()]+,$) -> $1\n$2
  • Oww:
    523 files changed, 15819 insertions(+), 13065 deletions(-)
    
Originally created by @lhecker on GitHub (Apr 4, 2023). This makes you wonder if you scared your code, because it's trying to flee from your screen: ```cpp bool ControlCore::SendMouseEvent(const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state) { return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state); } ``` This on the other hand is the one true way, no exceptions (sample size = 1, myself): ```cpp bool ControlCore::SendMouseEvent( const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state ) { return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state); } ``` We can get this behavior by setting `AlignAfterOpenBracket: BlockIndent` in `.clang-format`. The problems: * Code like the former example, will not be formatted like the latter example even if we set that option, because the former isn't actually block indented to begin with! It's just line breaks after the first argument and so clang-format turns it into: ```cpp bool ControlCore::SendMouseEvent(const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state) { return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state); } ``` Most of our code looks like that unfortunately. This would be correct from the POV of clang-format: ```cpp bool ControlCore::SendMouseEvent( const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state) { return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state); } ``` This can be mostly fixed with this regex replacement: `((?!\s|::)\w+\()([^{}()]+,$)` -> `$1\n$2` * Oww: ``` 523 files changed, 15819 insertions(+), 13065 deletions(-) ```
claunia added the Issue-TaskProduct-TerminalArea-CodeHealth labels 2026-01-31 06:49:16 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19632