diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 929e46b..1bd8e0d 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -1,20 +1,6 @@ lua_State *LuaState = NULL; String16 LuaCommandResult = {}; -String ListFiles(String path) { - Scratch scratch; - Array strings = {scratch}; - Add(&strings, String{"Open \"..\""}); - for (FileIter iter = IterateFiles(scratch, path); IsValid(iter); Advance(&iter)) { - String string = Format(scratch, "Open \"%.*s\"", FmtString(iter.absolute_path)); - Add(&strings, string); - } - Add(&strings, Format(scratch, "working dir = %.*s", FmtString(WorkingDir))); - - String result = Merge(scratch, strings, "\n"); - return result; -} - String FieldString(lua_State *L, String name) { String result = {}; if (lua_istable(L, -1)) { @@ -183,13 +169,28 @@ int Lua_GetActiveMainWindowBufferDir(lua_State *L) { return 1; } -int Lua_OpenFilesHere(lua_State *L) { +void ListFilesRecursive(Buffer *buffer, String filename) { + Scratch scratch(buffer->line_starts.allocator); + for (FileIter it = IterateFiles(scratch, filename); IsValid(it); Advance(&it)) { + if (it.filename == ".git") continue; + if (it.is_directory) { + ListFilesRecursive(buffer, it.absolute_path); + } else { + IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.absolute_path)); + } + } +} + +int Lua_Ls(lua_State *L) { BSet main = GetActiveMainSet(); Scratch scratch; - for (FileIter it = IterateFiles(scratch, GetActiveMainWindowBufferDir()); IsValid(it); Advance(&it)) { - WindowOpenBufferView(main.window, it.absolute_path); - } + String buffer_name = GetUniqueBufferName(scratch, GetDir(main.buffer), "+ls-"); + + Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4); + ListFilesRecursive(buffer, GetActiveMainWindowBufferDir()); + WindowOpenBufferView(main.window, buffer_name); + return 0; } diff --git a/src/text_editor/lua_api_generated.cpp b/src/text_editor/lua_api_generated.cpp index 98c28af..b2ceff1 100644 --- a/src/text_editor/lua_api_generated.cpp +++ b/src/text_editor/lua_api_generated.cpp @@ -11,7 +11,7 @@ luaL_Reg LuaFunctions[] = { {"GetWorkingDir", Lua_GetWorkingDir}, {"GetActiveMainWindowBufferName", Lua_GetActiveMainWindowBufferName}, {"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir}, - {"OpenFilesHere", Lua_OpenFilesHere}, + {"Ls", Lua_Ls}, {"Search", Lua_Search}, {"SearchB", Lua_SearchB}, {"Rename", Lua_Rename}, diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index 588d933..a380504 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -82,7 +82,7 @@ inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); } void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) { buffer->id = AllocBufferID(buffer); - buffer->name = name; + buffer->name = Intern(&GlobalInternTable, name); buffer->cap = size; buffer->data = AllocArray(allocator, U16, buffer->cap); buffer->line_starts.allocator = allocator; @@ -294,10 +294,8 @@ Buffer *BufferOpenFile(String path) { } if (!FileExists(path)) { - path = Intern(&GlobalInternTable, path); buffer = CreateBuffer(sys_allocator, path); } else if (IsDir(path)) { - path = Intern(&GlobalInternTable, path); buffer = CreateBuffer(sys_allocator, path, 4096 * 2); buffer->is_directory = true; @@ -305,7 +303,6 @@ Buffer *BufferOpenFile(String path) { IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.filename)); } } else { - path = Intern(&GlobalInternTable, path); String string = ReadFile(scratch, path); buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096); buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);