WorkDir concept
This commit is contained in:
@@ -1235,10 +1235,26 @@ int Lua_Eval(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetProjectFile(Buffer *buffer) {
|
||||
WorkDir = ChopLastSlash(buffer->name);
|
||||
LuaProjectBuffer = buffer;
|
||||
LuaProjectBuffer->user_change_id = -1;
|
||||
}
|
||||
|
||||
int Lua_SetProjectFile(lua_State *L) {
|
||||
BSet set = GetActiveMainSet();
|
||||
LuaProjectBuffer = set.buffer;
|
||||
LuaProjectBuffer->user_change_id = -1;
|
||||
SetProjectFile(set.buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_SetWorkDir(lua_State *L) {
|
||||
String dir = lua_tostring(L, -1);
|
||||
if (dir.len == 0) {
|
||||
BSet set = GetActiveMainSet();
|
||||
WorkDir = ChopLastSlash(set.buffer->name);
|
||||
} else {
|
||||
WorkDir = dir;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1305,3 +1321,26 @@ Window *SwitchWindow(int direction) {
|
||||
Window *result = GetOverlappingWindow(p, window);
|
||||
return result;
|
||||
}
|
||||
|
||||
String16 GetSearchString(Window *window) {
|
||||
if (!window->is_search_bar) {
|
||||
if (window->search_bar_window.id == 0) {
|
||||
return {};
|
||||
}
|
||||
window = GetWindow(window->search_bar_window);
|
||||
}
|
||||
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
String16 string = GetString(buffer);
|
||||
return string;
|
||||
}
|
||||
|
||||
String16 FetchLoadWord(void) {
|
||||
BSet active = GetActiveSet();
|
||||
Caret caret = active.view->carets[0];
|
||||
Range range = caret.range;
|
||||
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||
String16 string = GetString(active.buffer, range);
|
||||
return string;
|
||||
}
|
||||
@@ -1,26 +1,3 @@
|
||||
String16 GetSearchString(Window *window) {
|
||||
if (!window->is_search_bar) {
|
||||
if (window->search_bar_window.id == 0) {
|
||||
return {};
|
||||
}
|
||||
window = GetWindow(window->search_bar_window);
|
||||
}
|
||||
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
String16 string = GetString(buffer);
|
||||
return string;
|
||||
}
|
||||
|
||||
String16 FetchLoadWord(void) {
|
||||
BSet active = GetActiveSet();
|
||||
Caret caret = active.view->carets[0];
|
||||
Range range = caret.range;
|
||||
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||
String16 string = GetString(active.buffer, range);
|
||||
return string;
|
||||
}
|
||||
|
||||
void UpdateScroll(Window *window, bool update_caret_scrolling) {
|
||||
ProfileFunction();
|
||||
BSet set = GetBSet(window);
|
||||
|
||||
@@ -308,7 +308,7 @@ function MatchExec(s, meta)
|
||||
return nil
|
||||
end
|
||||
|
||||
if s:match(".exe$") then
|
||||
if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then
|
||||
return {kind = "exec_console", cmd = s, working_dir = GetMainDir()}
|
||||
end
|
||||
|
||||
@@ -353,7 +353,7 @@ table.insert(OnCommandCallbacks, function (e)
|
||||
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
|
||||
C("git grep -n "..GetLoadWord().." :/") end
|
||||
if e.key == SDLK_B and e.ctrl == 1 then
|
||||
Cmd { working_dir = GetProjectDir(), kind = "console", cmd = "build.bat" } end
|
||||
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = "build.bat" } end
|
||||
end)
|
||||
|
||||
function OnUpdate(e)
|
||||
|
||||
@@ -70,16 +70,6 @@ int Lua_GetFilename(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_GetProjectDir(lua_State *L) {
|
||||
if (LuaProjectBuffer) {
|
||||
String path = ChopLastSlash(LuaProjectBuffer->name);
|
||||
lua_pushlstring(L, path.data, path.len);
|
||||
} else {
|
||||
lua_pushlstring(L, "no config", 9);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_FileExists(lua_State *L) {
|
||||
String path = luaL_checkstring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
@@ -88,9 +78,8 @@ int Lua_FileExists(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_GetBaseDir(lua_State *L) {
|
||||
String name = Command_GetBaseDir();
|
||||
lua_pushlstring(L, name.data, name.len);
|
||||
int Lua_GetWorkDir(lua_State *L) {
|
||||
lua_pushlstring(L, WorkDir.data, WorkDir.len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ luaL_Reg LuaFunctions[] = {
|
||||
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
||||
{"GetClipboard", Lua_GetClipboard},
|
||||
{"GetFilename", Lua_GetFilename},
|
||||
{"GetProjectDir", Lua_GetProjectDir},
|
||||
{"FileExists", Lua_FileExists},
|
||||
{"GetBaseDir", Lua_GetBaseDir},
|
||||
{"GetWorkDir", Lua_GetWorkDir},
|
||||
{"GetMainDir", Lua_GetMainDir},
|
||||
{"SplitSize", Lua_SplitSize},
|
||||
{"Play", Lua_Play},
|
||||
@@ -29,6 +28,7 @@ luaL_Reg LuaFunctions[] = {
|
||||
{"ListBuffers", Lua_ListBuffers},
|
||||
{"Eval", Lua_Eval},
|
||||
{"SetProjectFile", Lua_SetProjectFile},
|
||||
{"SetWorkDir", Lua_SetWorkDir},
|
||||
{"ListCommands", Lua_ListCommands},
|
||||
{"GetBufferList", Lua_GetBufferList},
|
||||
{NULL, NULL},
|
||||
|
||||
@@ -38,6 +38,7 @@ Buffer *GCInfoBuffer;
|
||||
Buffer *EventBuffer;
|
||||
Buffer *ScratchBuffer;
|
||||
|
||||
String WorkDir;
|
||||
RandomSeed UniqueBufferNameSeed = {};
|
||||
|
||||
// lua
|
||||
@@ -72,9 +73,9 @@ void InitScratchBuffer() {
|
||||
View *null_view = CreateView(null_buffer->id);
|
||||
Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID);
|
||||
|
||||
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(Command_GetBaseDir(), "gc"));
|
||||
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(Command_GetBaseDir(), "events"));
|
||||
ScratchBuffer = BufferOpenFile(GetUniqueBufferName(Command_GetBaseDir(), "scratch"));
|
||||
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "gc"));
|
||||
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "events"));
|
||||
ScratchBuffer = BufferOpenFile(GetUniqueBufferName(WorkDir, "scratch"));
|
||||
|
||||
EventBuffer->no_history = true;
|
||||
GCInfoBuffer->no_history = true;
|
||||
@@ -328,11 +329,6 @@ String Command_GetMainDir() {
|
||||
return name;
|
||||
}
|
||||
|
||||
String Command_GetBaseDir() {
|
||||
Buffer *buffer = GetBuffer(NullBufferID);
|
||||
return ChopLastSlash(buffer->name);
|
||||
}
|
||||
|
||||
Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap) {
|
||||
if (string.len == 0) {
|
||||
return 0;
|
||||
|
||||
@@ -285,7 +285,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
|
||||
View *view = NULL;
|
||||
{
|
||||
Scratch scratch;
|
||||
String working_dir = Command_GetBaseDir();
|
||||
String working_dir = WorkDir;
|
||||
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
|
||||
String cmd = Format(scratch, "\"%.*s\" && set", FmtString(StyleVCVarsall));
|
||||
view = Command_ExecHidden(buffer_name, cmd, working_dir);
|
||||
@@ -325,6 +325,7 @@ int main(int argc, char **argv)
|
||||
InitArena(&Perm);
|
||||
// Prototype();
|
||||
|
||||
WorkDir = GetWorkingDir(Perm);
|
||||
{
|
||||
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
|
||||
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
|
||||
@@ -410,8 +411,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (EndsWith(it, ".project.lua")) {
|
||||
if (!LuaProjectBuffer) {
|
||||
LuaProjectBuffer = BufferOpenFile(it);
|
||||
LuaProjectBuffer->user_change_id = -1;
|
||||
SetProjectFile(BufferOpenFile(it));
|
||||
}
|
||||
} else {
|
||||
Window *window = GetWindow({0});
|
||||
|
||||
@@ -120,7 +120,6 @@ Array<Edit> Command_ReplaceEx(Allocator scratch, View *view, String16 string);
|
||||
void Command_Eval(String string);
|
||||
void Command_Eval(String16 string);
|
||||
String Command_GetMainDir();
|
||||
String Command_GetBaseDir();
|
||||
|
||||
void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string);
|
||||
void Command_Copy(View *view);
|
||||
|
||||
@@ -14,7 +14,7 @@ Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
|
||||
static int BarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%.*s/searchbar%d", FmtString(Command_GetBaseDir()), ++BarCount);
|
||||
String name = Format(sys_allocator, "%.*s/searchbar%d", FmtString(WorkDir), ++BarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
@@ -37,7 +37,7 @@ Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
|
||||
static int TitlebarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%.*s/titlebar%d", FmtString(Command_GetBaseDir()), ++TitlebarCount);
|
||||
String name = Format(sys_allocator, "%.*s/titlebar%d", FmtString(WorkDir), ++TitlebarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
@@ -99,7 +99,6 @@ void SplitWindow(WindowSplitKind kind) {
|
||||
Window *active_window = GetActiveWindow();
|
||||
SplitWindowEx(NULL, &WindowSplits, active_window, window, kind);
|
||||
ActiveWindow = window->id;
|
||||
|
||||
}
|
||||
|
||||
void SetVisibility(WindowID window_id, bool v) {
|
||||
@@ -205,7 +204,7 @@ void InitWindows() {
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(Command_GetBaseDir(), "debug"));
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
DebugBufferID = buffer->id;
|
||||
buffer->no_history = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user