Compare commits

...

2 Commits

Author SHA1 Message Date
Krzosa Karol
e4f2401633 FormatUsingClangFormatWhenCCode and TrimTrailingWhitespace 2026-01-01 14:44:11 +01:00
Krzosa Karol
65a6c372e0 FormatUsingClangFormatWhenCCode and TrimTrailingWhitespace 2026-01-01 14:41:37 +01:00
6 changed files with 23 additions and 7 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,8 +1514,21 @@ 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);
String string = AllocCharString(scratch, buffer);
bool success = WriteFile(buffer->name, string);
if (success) {

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

@@ -57,7 +57,7 @@ void DrawVisibleText(Window *window, Color tint) {
p.x += text_offset_x;
Rect2 rect = Rect2FromSize(p + g->offset, g->size);
if (codepoint != '\n' && codepoint != '\r' && codepoint != ' ') {
if (codepoint != '\n' && codepoint != '\r' && codepoint != ' ' && codepoint != '\t') {
PushQuad2D(RenderArena, &Vertices, rect, g->atlas_bounding_box, tint);
}

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);