Naming and fix CloseAll

This commit is contained in:
krzosa
2025-12-29 10:48:06 +01:00
parent 0f03f248c7
commit ccf55d6d74
7 changed files with 27 additions and 27 deletions

View File

@@ -1188,7 +1188,7 @@ API void DeallocBuffer(Buffer *buffer) {
Dealloc(buffer->line_starts.allocator, buffer);
}
API Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) {
API Buffer *CreateScratchBuffer(Allocator allocator, Int size = 4096) {
Buffer *result = AllocType(allocator, Buffer);
result->no_history = true;
result->no_line_starts = true;
@@ -1519,7 +1519,7 @@ Buffer *BufferOpenFile(String path) {
} else if (IsDir(path)) {
buffer = CreateBuffer(sys_allocator, path);
buffer->is_dir = true;
buffer->garbage = true;
buffer->temp = true;
} else {
String string = ReadFile(scratch, path);
buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096);
@@ -1565,7 +1565,7 @@ void SaveBuffer(Buffer *buffer) {
if (success) {
buffer->file_mod_time = GetFileModTime(buffer->name);
buffer->dirty = false;
buffer->garbage = false;
buffer->temp = false;
} else {
ReportWarningf("Failed to save file with name: %S", buffer->name);
}

View File

@@ -39,7 +39,7 @@ struct Buffer {
unsigned no_line_starts : 1;
unsigned dirty : 1;
unsigned changed_on_disk : 1;
unsigned garbage : 1;
unsigned temp : 1;
unsigned dont_try_to_save_in_bulk_ops : 1;
unsigned close : 1;
unsigned special : 1;

View File

@@ -32,13 +32,13 @@ String GetMainDir() {
return GetDir(main.buffer);
}
void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
void JumpTempBuffer(BSet *set, String buffer_name = "") {
if (buffer_name.len == 0) {
buffer_name = GetUniqueBufferName(GetDir(set->buffer), "temp");
}
set->view = WindowOpenBufferView(set->window, buffer_name);
set->buffer = GetBuffer(set->view->active_buffer);
set->buffer->garbage = true;
set->buffer->temp = true;
}
void MouseLoadWord(Event event, String meta = "") {
@@ -162,7 +162,7 @@ void UIMessagef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
BSet main = GetBSet(LastActiveLayoutWindowID);
JumpGarbageBuffer(&main);
JumpTempBuffer(&main);
NextActiveWindowID = main.window->id;
RawAppendf(main.buffer, "\n %S\n", string);
}
@@ -387,7 +387,7 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) {
if (set_active) {
NextActiveWindowID = main.window->id;
}
JumpGarbageBuffer(&main);
JumpTempBuffer(&main);
Exec(main.view->id, true, cmd, working_dir);
return main;
}
@@ -576,7 +576,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
if (set_active) {
NextActiveWindowID = set.window->id;
}
JumpGarbageBuffer(&set);
JumpTempBuffer(&set);
Exec(set.view->id, true, o.path, GetMainDir());
} else if (o.kind == OpenKind_BackgroundExec) {
// this shouldn't change the focus/window/view
@@ -707,7 +707,7 @@ void AddHook(Array<CommandData> *arr, String name, String binding, Function *fun
// @todo: rename to temp buffer? but there is already a thing like that...
String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
JumpGarbageBuffer(&main);
JumpTempBuffer(&main);
NextActiveWindowID = main.window->id;
RawAppendf(main.buffer, R"==(
@@ -722,7 +722,7 @@ String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
AddHook(&main.view->hooks, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
String result = "Cancel";
for (;;) {
if (main.window->active_view != main.view->id || main.window->close) {
if (main.window->active_view != main.view->id || (main.window->id != LastActiveLayoutWindowID && main.window->id != ActiveWindowID) || main.window->close) {
break;
}
@@ -739,7 +739,7 @@ String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
void Coro_Close(mco_coro *co) {
BSet main = GetBSet(LastActiveLayoutWindowID);
if (main.buffer->special || main.buffer->garbage) {
if (main.buffer->special || main.buffer->temp) {
Close(main.view->id);
return;
}
@@ -790,11 +790,11 @@ String Coro_CloseAllEx(mco_coro *co) {
Array<BufferID> buffers = {CoCurr->arena};
For (Buffers) Add(&buffers, it->id);
ForItem (id, buffers) {
Buffer *it = GetBuffer(id);
if (it->special || !it->dirty) {
Buffer *it = GetBuffer(id, NULL);
if (it == NULL || it->special || !it->dirty) {
continue;
}
if (it->garbage || it->dont_try_to_save_in_bulk_ops) {
if (it->temp || it->dont_try_to_save_in_bulk_ops) {
continue;
}

View File

@@ -39,14 +39,14 @@ void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) {
Buffer *ExecAndWait(Allocator allocator, String cmd, String working_dir, String stdin_string = {}) {
ReportDebugf("ExecAndWait cmd = %S working_dir = %S stdin_string = %S", cmd, working_dir, stdin_string);
Buffer *temp_buffer = CreateTempBuffer(allocator, 4096 * 4);
Buffer *scratch_buff = CreateScratchBuffer(allocator, 4096 * 4);
for (Process process = SpawnProcess(cmd, working_dir, stdin_string, ProcessEnviroment); IsValid(&process);) {
Scratch scratch(allocator);
String poll = PollStdout(scratch, &process, true);
if (poll.len) RawAppend(temp_buffer, poll);
if (poll.len) RawAppend(scratch_buff, poll);
}
return temp_buffer;
return scratch_buff;
}
void KillProcess(View *view) {

View File

@@ -481,7 +481,7 @@ void GarbageCollect() {
}
if (!it->close) {
if (!buffer->garbage) {
if (!buffer->temp) {
continue;
}
@@ -504,7 +504,7 @@ void GarbageCollect() {
}
if (!it->close) {
if (!it->garbage) {
if (!it->temp) {
continue;
}

View File

@@ -90,19 +90,19 @@ void CommandWindowUpdate() {
active.view->prev_search_line = line_string;
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, active.buffer, 1, active.buffer->line_starts.len, line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, active.buffer->cap);
RawAppend(temp_buffer, line_string);
Buffer *scratch_buff = CreateScratchBuffer(scratch, active.buffer->cap);
RawAppend(scratch_buff, line_string);
For(IterateInReverse(&ratings)) {
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
if (s.len == 0) continue;
RawAppend(temp_buffer, u"\n");
RawAppend(temp_buffer, s);
RawAppend(scratch_buff, u"\n");
RawAppend(scratch_buff, s);
}
Caret caret = active.view->carets[0];
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
SelectEntireBuffer(active.view);
Replace(active.view, GetString(temp_buffer));
Replace(active.view, GetString(scratch_buff));
active.view->carets[0] = caret;
}
}
@@ -160,7 +160,7 @@ void Command_ShowBufferList() {
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
if (it->special || it->garbage) {
if (it->special || it->temp) {
continue;
}
RawAppendf(command_bar.buffer, "\n%S", it->name);

View File

@@ -76,7 +76,7 @@ void DebugWindowUpdate() {
RawAppendf(set.buffer, "int no_line_starts = %d\n", main.buffer->no_line_starts);
RawAppendf(set.buffer, "int dirty = %d\n", main.buffer->dirty);
RawAppendf(set.buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk);
RawAppendf(set.buffer, "int garbage = %d\n", main.buffer->garbage);
RawAppendf(set.buffer, "int temp = %d\n", main.buffer->temp);
}
void Command_ToggleDebug() {