Bring back GC and new files for commands
This commit is contained in:
@@ -178,6 +178,14 @@ void Dealloc(Allocator alo, T **p) {
|
|||||||
alo.proc(alo.object, AllocatorKind_Deallocate, *p, 0);
|
alo.proc(alo.object, AllocatorKind_Deallocate, *p, 0);
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
}
|
}
|
||||||
|
#define DeallocEx(alo, p) (alo).proc((alo).object, AllocatorKind_Deallocate, (p), 0);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void Dealloc2(Allocator alo, T *p) {
|
||||||
|
if (*p == NULL) return;
|
||||||
|
alo.proc(alo.object, AllocatorKind_Deallocate, *p, 0);
|
||||||
|
*p = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Allocator GetSystemAllocator();
|
Allocator GetSystemAllocator();
|
||||||
#define MemoryZero(x, size) memset(x, 0, size)
|
#define MemoryZero(x, size) memset(x, 0, size)
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ struct Buffer {
|
|||||||
int no_history : 1;
|
int no_history : 1;
|
||||||
int no_line_starts : 1;
|
int no_line_starts : 1;
|
||||||
int dirty : 1;
|
int dirty : 1;
|
||||||
int gc : 1;
|
|
||||||
int changed_on_disk : 1;
|
int changed_on_disk : 1;
|
||||||
|
int garbage : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -598,7 +598,7 @@ void SaveBuffer(View *view) {
|
|||||||
if (success) {
|
if (success) {
|
||||||
buffer->file_mod_time = GetFileModTime(buffer->name);
|
buffer->file_mod_time = GetFileModTime(buffer->name);
|
||||||
buffer->dirty = false;
|
buffer->dirty = false;
|
||||||
buffer->gc = false;
|
buffer->garbage = false;
|
||||||
} else {
|
} else {
|
||||||
ReportWarningf("Failed to save file with name: %.*s", FmtString(buffer->name));
|
ReportWarningf("Failed to save file with name: %.*s", FmtString(buffer->name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,26 +16,26 @@ String FieldString(lua_State *L, String name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Command_JumpNew(BSet *set) {
|
||||||
|
CheckpointBeforeGoto(set->window);
|
||||||
|
String current_dir = ChopLastSlash(set->buffer->name);
|
||||||
|
String buffer_name = GetUniqueBufferName(current_dir, "temp");
|
||||||
|
set->view = WindowOpenBufferView(set->window, buffer_name);
|
||||||
|
set->buffer = GetBuffer(set->view->active_buffer);
|
||||||
|
set->buffer->garbage = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Command_ExecInNewBuffer(BSet set, String cmd, String working_dir) {
|
void Command_ExecInNewBuffer(BSet set, String cmd, String working_dir) {
|
||||||
CheckpointBeforeGoto(set.window);
|
BSet main = GetActiveMainSet();
|
||||||
|
Command_JumpNew(&main);
|
||||||
Scratch scratch;
|
Exec(main.view->id, true, cmd, working_dir);
|
||||||
String buffer_name = GetUniqueBufferName(working_dir, "shell_command");
|
|
||||||
|
|
||||||
View *view = WindowOpenBufferView(set.window, buffer_name);
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
buffer->gc = true;
|
|
||||||
Command_SelectRangeOneCursor(view, Rng(0));
|
|
||||||
|
|
||||||
Exec(view->id, true, cmd, working_dir);
|
|
||||||
ActiveWindow = set.window->id;
|
ActiveWindow = set.window->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
|
View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
|
||||||
View *view = OpenBufferView(buffer_name);
|
View *view = OpenBufferView(buffer_name);
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
buffer->gc = true;
|
// buffer->garbage = true;
|
||||||
Command_SelectRangeOneCursor(view, Rng(0));
|
|
||||||
Exec(view->id, true, cmd, working_dir);
|
Exec(view->id, true, cmd, working_dir);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -46,14 +46,6 @@ void Command_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
|||||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_BeginJumpCommandBuffer(BSet *set) {
|
|
||||||
String current_dir = Command_GetDir();
|
|
||||||
Command_BeginJump(set, set->window->command_buffer);
|
|
||||||
set->buffer->name = GetUniqueBufferName(current_dir, WindowBufferName);
|
|
||||||
Command_SelectEntireBuffer(set->view);
|
|
||||||
Command_Replace(set->view, u"");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Command_EndJump(BSet set) {
|
void Command_EndJump(BSet set) {
|
||||||
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
||||||
set.view->carets[0] = MakeCaret(pos);
|
set.view->carets[0] = MakeCaret(pos);
|
||||||
@@ -62,20 +54,18 @@ void Command_EndJump(BSet set) {
|
|||||||
|
|
||||||
void Command_ListBuffers() {
|
void Command_ListBuffers() {
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
Command_BeginJumpCommandBuffer(&main);
|
ActiveWindow = main.window->id;
|
||||||
|
Command_JumpNew(&main);
|
||||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||||
Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
|
Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
|
||||||
}
|
}
|
||||||
Command_EndJump(main);
|
|
||||||
ActiveWindow = main.window->id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BSet Command_Exec(String cmd, String working_dir) {
|
BSet Command_Exec(String cmd, String working_dir) {
|
||||||
BSet set = GetActiveMainSet();
|
BSet set = GetActiveMainSet();
|
||||||
Command_BeginJumpCommandBuffer(&set);
|
|
||||||
Exec(set.view->id, true, cmd, working_dir);
|
|
||||||
Command_EndJump(set);
|
|
||||||
ActiveWindow = set.window->id;
|
ActiveWindow = set.window->id;
|
||||||
|
Command_JumpNew(&set);
|
||||||
|
Exec(set.view->id, true, cmd, working_dir);
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,14 +90,13 @@ BSet Command_Open(String path) {
|
|||||||
String col_string = FieldString(LuaState, "col");
|
String col_string = FieldString(LuaState, "col");
|
||||||
Int col = strtoll(col_string.data, NULL, 10);
|
Int col = strtoll(col_string.data, NULL, 10);
|
||||||
|
|
||||||
|
ActiveWindow = main.window->id;
|
||||||
if (IsDir(file_path)) {
|
if (IsDir(file_path)) {
|
||||||
Command_BeginJumpCommandBuffer(&main);
|
Command_JumpNew(&main);
|
||||||
Command_Appendf(main.view, "%.*s/..\n", FmtString(file_path));
|
Command_Appendf(main.view, "%.*s/..\n", FmtString(file_path));
|
||||||
for (FileIter it = IterateFiles(scratch, file_path); IsValid(it); Advance(&it)) {
|
for (FileIter it = IterateFiles(scratch, file_path); IsValid(it); Advance(&it)) {
|
||||||
Command_Appendf(main.view, "%.*s\n", FmtString(it.absolute_path));
|
Command_Appendf(main.view, "%.*s\n", FmtString(it.absolute_path));
|
||||||
}
|
}
|
||||||
Command_EndJump(main);
|
|
||||||
ActiveWindow = main.window->id;
|
|
||||||
} else {
|
} else {
|
||||||
CheckpointBeforeGoto(main.window);
|
CheckpointBeforeGoto(main.window);
|
||||||
View *view = WindowOpenBufferView(main.window, file_path);
|
View *view = WindowOpenBufferView(main.window, file_path);
|
||||||
@@ -118,7 +107,6 @@ BSet Command_Open(String path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateScroll(main.window, true);
|
UpdateScroll(main.window, true);
|
||||||
ActiveWindow = main.window->id;
|
|
||||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||||
String cmd = FieldString(LuaState, "cmd");
|
String cmd = FieldString(LuaState, "cmd");
|
||||||
String working_dir = FieldString(LuaState, "working_dir");
|
String working_dir = FieldString(LuaState, "working_dir");
|
||||||
@@ -169,7 +157,7 @@ int Lua_Eval(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Lua_NewWindowCMD(lua_State *L) {
|
int Lua_NewBufferCMD(lua_State *L) {
|
||||||
String string = lua_tostring(L, 1);
|
String string = lua_tostring(L, 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
@@ -204,9 +192,8 @@ int Lua_Cmd(lua_State *L) {
|
|||||||
Command_EndJump(set);
|
Command_EndJump(set);
|
||||||
} else {
|
} else {
|
||||||
BSet set = GetActiveMainSet();
|
BSet set = GetActiveMainSet();
|
||||||
Command_BeginJumpCommandBuffer(&set);
|
Command_JumpNew(&set);
|
||||||
Exec(set.view->id, true, cmd, working_dir);
|
Exec(set.view->id, true, cmd, working_dir);
|
||||||
Command_EndJump(set);
|
|
||||||
ActiveWindow = set.window->id;
|
ActiveWindow = set.window->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
luaL_Reg LuaFunctions[] = {
|
luaL_Reg LuaFunctions[] = {
|
||||||
{"C", Lua_C},
|
{"C", Lua_C},
|
||||||
{"Eval", Lua_Eval},
|
{"Eval", Lua_Eval},
|
||||||
{"NewWindowCMD", Lua_NewWindowCMD},
|
{"NewBufferCMD", Lua_NewBufferCMD},
|
||||||
{"Cmd", Lua_Cmd},
|
{"Cmd", Lua_Cmd},
|
||||||
{"Print", Lua_Print},
|
{"Print", Lua_Print},
|
||||||
{"Kill", Lua_Kill},
|
{"Kill", Lua_Kill},
|
||||||
|
|||||||
@@ -130,6 +130,14 @@ void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 409
|
|||||||
if (!buffer->no_line_starts) Add(&buffer->line_starts, (Int)0);
|
if (!buffer->no_line_starts) Add(&buffer->line_starts, (Int)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeallocBuffer(Buffer *buffer) {
|
||||||
|
Dealloc(&buffer->line_starts);
|
||||||
|
DeallocHistoryArray(&buffer->undo_stack);
|
||||||
|
DeallocHistoryArray(&buffer->redo_stack);
|
||||||
|
DeallocEx(buffer->line_starts.allocator, buffer->data);
|
||||||
|
DeallocEx(buffer->line_starts.allocator, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer *CreateBuffer(Allocator allocator, String name, Int size) {
|
Buffer *CreateBuffer(Allocator allocator, String name, Int size) {
|
||||||
Buffer *result = AllocType(allocator, Buffer);
|
Buffer *result = AllocType(allocator, Buffer);
|
||||||
InitBuffer(allocator, result, name, size);
|
InitBuffer(allocator, result, name, size);
|
||||||
@@ -153,9 +161,6 @@ Window *CreateWindow(bool create_command_buffer = true) {
|
|||||||
w->draw_scrollbar = StyleDrawScrollbar;
|
w->draw_scrollbar = StyleDrawScrollbar;
|
||||||
w->draw_line_numbers = StyleDrawLineNumbers;
|
w->draw_line_numbers = StyleDrawLineNumbers;
|
||||||
w->id = AllocWindowID(w);
|
w->id = AllocWindowID(w);
|
||||||
if (create_command_buffer) {
|
|
||||||
w->command_buffer = CreateBuffer(GetSystemAllocator(), GetUniqueBufferName(WorkingDir, WindowBufferName), 4096*2)->id;
|
|
||||||
}
|
|
||||||
DLL_QUEUE_ADD(FirstWindow, LastWindow, w);
|
DLL_QUEUE_ADD(FirstWindow, LastWindow, w);
|
||||||
WindowCount += 1;
|
WindowCount += 1;
|
||||||
return w;
|
return w;
|
||||||
@@ -428,47 +433,46 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window *ViewIsReferenced(ViewID view) {
|
bool ViewIsReferenced(ViewID view) {
|
||||||
|
if (view == NullViewID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (Window *it = FirstWindow; it; it = it->next) {
|
for (Window *it = FirstWindow; it; it = it->next) {
|
||||||
if (it->active_view == view || it->active_goto_list == view) return it;
|
if (it->active_view == view || it->active_goto_list == view) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
View *BufferIsReferenced(BufferID buffer_id) {
|
bool BufferIsCrumb(BufferID buffer_id) {
|
||||||
return FindView(buffer_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Window *BufferIsCrumb(BufferID buffer_id) {
|
|
||||||
for (Window *window = FirstWindow; window; window = window->next) {
|
for (Window *window = FirstWindow; window; window = window->next) {
|
||||||
For(window->goto_history) if (it.buffer_id == buffer_id) return window;
|
For(window->goto_history) if (it.buffer_id == buffer_id) return true;
|
||||||
For(window->goto_redo) if (it.buffer_id == buffer_id) return window;
|
For(window->goto_redo) if (it.buffer_id == buffer_id) return true;
|
||||||
}
|
}
|
||||||
return NULL;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BufferIsReferenced(BufferID buffer_id) {
|
||||||
|
if (buffer_id == NullBufferID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
View *view = FindView(buffer_id);
|
||||||
|
if (view) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BufferIsCrumb(buffer_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarbageCollect() {
|
void GarbageCollect() {
|
||||||
Allocator sys_allocator = GetSystemAllocator();
|
Allocator sys_allocator = GetSystemAllocator();
|
||||||
// IterRemove(Views) {
|
|
||||||
// IterRemovePrepare(Views);
|
|
||||||
// View *view = it.o;
|
|
||||||
// Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
// bool gc = buffer->gc;
|
|
||||||
// if (buffer->is_directory) {
|
|
||||||
// Window *ref = BufferIsCrumb(buffer->id);
|
|
||||||
// if (!ref) gc = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Window *ref = ViewIsReferenced(view->id);
|
|
||||||
// if (gc && !ref) {
|
|
||||||
// Dealloc(&view->carets);
|
|
||||||
// remove_item = true;
|
|
||||||
|
|
||||||
// RawAppendf(GCInfoBuffer, "view %.*s\n", FmtString(buffer->name));
|
|
||||||
// Dealloc(sys_allocator, &view);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||||
if (it->file_mod_time) {
|
if (it->file_mod_time) {
|
||||||
int64_t new_file_mod_time = GetFileModTime(it->name);
|
int64_t new_file_mod_time = GetFileModTime(it->name);
|
||||||
@@ -477,26 +481,38 @@ void GarbageCollect() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// IterRemove(Buffers) {
|
|
||||||
// IterRemovePrepare(Buffers);
|
|
||||||
// Buffer *buffer = it.o;
|
|
||||||
// bool gc = buffer->gc;
|
|
||||||
|
|
||||||
// View *ref = BufferIsReferenced(buffer->id);
|
for (View *it = FirstView, *next = NULL; it; it = next) {
|
||||||
// if (gc && !ref) {
|
next = it->next;
|
||||||
// Dealloc(&buffer->line_starts);
|
|
||||||
// DeallocHistoryArray(&buffer->undo_stack);
|
|
||||||
// DeallocHistoryArray(&buffer->redo_stack);
|
|
||||||
// Dealloc(buffer->line_starts.allocator, &buffer->data);
|
|
||||||
// remove_item = true;
|
|
||||||
|
|
||||||
// RawAppendf(GCInfoBuffer, "buffer %.*s\n", FmtString(buffer->name));
|
Buffer *buffer = GetBuffer(it->active_buffer);
|
||||||
// Dealloc(sys_allocator, &buffer);
|
if (!buffer->garbage) {
|
||||||
// } else if (buffer->file_mod_time) {
|
continue;
|
||||||
// int64_t new_file_mod_time = GetFileModTime(buffer->name);
|
}
|
||||||
// if (buffer->file_mod_time != new_file_mod_time) {
|
|
||||||
// buffer->changed_on_disk = true;
|
bool ref = ViewIsReferenced(it->id);
|
||||||
// }
|
if (ref) {
|
||||||
// }
|
continue;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
Dealloc(&it->carets);
|
||||||
|
DeallocEx(sys_allocator, it);
|
||||||
|
DLL_QUEUE_REMOVE(FirstView, LastView, it);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Buffer *it = FirstBuffer, *next = NULL; it; it = next) {
|
||||||
|
next = it->next;
|
||||||
|
|
||||||
|
if (!it->garbage) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ref = BufferIsReferenced(it->id);
|
||||||
|
if (ref) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeallocBuffer(it);
|
||||||
|
DLL_QUEUE_REMOVE(FirstBuffer, LastBuffer, it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
|
|||||||
{
|
{
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String working_dir = Command_GetDir();
|
String working_dir = Command_GetDir();
|
||||||
String buffer_name = GetUniqueBufferName(working_dir, "+cmd-");
|
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
|
||||||
String cmd = Format(scratch, "\"%.*s\" && set", FmtString(StyleVCVarsall));
|
String cmd = Format(scratch, "\"%.*s\" && set", FmtString(StyleVCVarsall));
|
||||||
view = Command_ExecHidden(buffer_name, cmd, working_dir);
|
view = Command_ExecHidden(buffer_name, cmd, working_dir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ struct Window {
|
|||||||
Array<GotoCrumb> goto_redo;
|
Array<GotoCrumb> goto_redo;
|
||||||
|
|
||||||
ViewID active_goto_list;
|
ViewID active_goto_list;
|
||||||
BufferID command_buffer;
|
|
||||||
|
|
||||||
double mouse_scroller_offset;
|
double mouse_scroller_offset;
|
||||||
int z;
|
int z;
|
||||||
|
|||||||
Reference in New Issue
Block a user