FormatUsingClangFormatWhenCCode and TrimTrailingWhitespace

This commit is contained in:
Krzosa Karol
2026-01-01 14:41:37 +01:00
parent bbab59fa0a
commit 65a6c372e0
5 changed files with 22 additions and 6 deletions

View File

@@ -2,9 +2,8 @@
! From a user (novice) point of view, how does it look like?
- Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep)
- OpenCode :Set CodeExcludePatterns ".git/|mk
- ClangFormatOnCCode variable
- CleanTrailingWhitespace
- Add Bool variable
- Not rendering U+0009 TAB properly
- Initialize all keybindings at the start and refer using global variables?
- RegisterCommand should_appear_in_listing variable

View File

@@ -1514,6 +1514,19 @@ void ReopenBuffer(Buffer *buffer) {
}
void SaveBuffer(Buffer *buffer) {
bool formatted = false;
if (FormatUsingClangFormatWhenCCode) {
bool c = EndsWith(buffer->name, ".c") || EndsWith(buffer->name, ".cpp") || EndsWith(buffer->name, ".h") || EndsWith(buffer->name, ".hpp");
if (c) {
ApplyClangFormat(buffer);
formatted = true;
}
}
if (TrimTrailingWhitespace && formatted == false) {
TrimWhitespace(buffer);
}
Scratch scratch;
String string = AllocCharString(scratch, buffer);
bool success = WriteFile(buffer->name, string);

View File

@@ -247,7 +247,7 @@ void MoveCursorByPageSize(Window *window, int direction, bool shift = false) {
}
}
void TrimTrailingWhitespace(Buffer *buffer, bool trim_lines_with_caret = false) {
void TrimWhitespace(Buffer *buffer, bool trim_lines_with_caret) {
Scratch scratch;
bool is_active_view = false;

View File

@@ -161,3 +161,5 @@ RegisterVariable(Float, UndoMergeTime, 0.3);
RegisterVariable(Float, JumpHistoryMergeTime, 0.3);
RegisterVariable(String, InternetBrowser, "firefox");
RegisterVariable(String, NonCodePatterns_EndsWith, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall");
RegisterVariable(Int, TrimTrailingWhitespace, 1);
RegisterVariable(Int, FormatUsingClangFormatWhenCCode, 0);

View File

@@ -195,3 +195,5 @@ struct ResolvedOpen {
};
ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta);
void CenterView(WindowID window);
void TrimWhitespace(Buffer *buffer, bool trim_lines_with_caret = false);
void ApplyClangFormat(Buffer *buffer);