Reorganizing a bit
This commit is contained in:
@@ -1,20 +1,3 @@
|
||||
void ToggleFullscreen() {
|
||||
if (IsInFullscreen) {
|
||||
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
|
||||
SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY);
|
||||
} else {
|
||||
SDL_GetWindowSize(SDLWindow, &FullScreenSizeX, &FullScreenSizeY);
|
||||
SDL_GetWindowPosition(SDLWindow, &FullScreenPositionX, &FullScreenPositionY);
|
||||
|
||||
SDL_DisplayID display = SDL_GetDisplayForWindow(SDLWindow);
|
||||
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(display);
|
||||
SDL_SetWindowSize(SDLWindow, dm->w, dm->h);
|
||||
SDL_SetWindowPosition(SDLWindow, 0, 0);
|
||||
}
|
||||
|
||||
IsInFullscreen = !IsInFullscreen;
|
||||
}
|
||||
|
||||
void CheckpointBeforeGoto(Window *window, View *view) {
|
||||
Add(&window->goto_history, {view->id, view->carets[0]});
|
||||
window->goto_redo.len = 0;
|
||||
@@ -57,6 +40,27 @@ void GotoForward(Window *window) {
|
||||
UpdateScroll(window, true);
|
||||
}
|
||||
|
||||
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_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
set->buffer = GetBuffer(buffer_id);
|
||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
||||
}
|
||||
|
||||
void Command_EndJump(BSet set) {
|
||||
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
||||
set.view->carets[0] = MakeCaret(pos);
|
||||
UpdateScroll(set.window, true);
|
||||
}
|
||||
|
||||
Int ScreenSpaceToBufferPos(Window *window, View *view, Buffer *buffer, Vec2I mouse) {
|
||||
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
||||
double px = (double)mworld.x / (double)FontCharSpacing;
|
||||
@@ -119,6 +123,28 @@ void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string) {
|
||||
view->carets = carets;
|
||||
}
|
||||
|
||||
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 {
|
||||
bool good = EndsWith(it.filename, ".c") ||
|
||||
EndsWith(it.filename, ".h") ||
|
||||
EndsWith(it.filename, ".cpp") ||
|
||||
EndsWith(it.filename, ".hpp") ||
|
||||
EndsWith(it.filename, ".bat");
|
||||
if (!good) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(buffer, "%.*s\n", FmtString(it.absolute_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo: revamp interface since it scrolls ALL VIEWS??? or maybe not??
|
||||
void Command_Append(View *view, String16 string, bool scroll_to_end_if_cursor_on_last_line) {
|
||||
Scratch scratch;
|
||||
@@ -865,4 +891,256 @@ void Command_Reopen() {
|
||||
int Lua_Reopen(lua_State *L) {
|
||||
Command_Reopen();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Command_ToggleFullscreen() {
|
||||
if (IsInFullscreen) {
|
||||
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
|
||||
SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY);
|
||||
} else {
|
||||
SDL_GetWindowSize(SDLWindow, &FullScreenSizeX, &FullScreenSizeY);
|
||||
SDL_GetWindowPosition(SDLWindow, &FullScreenPositionX, &FullScreenPositionY);
|
||||
|
||||
SDL_DisplayID display = SDL_GetDisplayForWindow(SDLWindow);
|
||||
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(display);
|
||||
SDL_SetWindowSize(SDLWindow, dm->w, dm->h);
|
||||
SDL_SetWindowPosition(SDLWindow, 0, 0);
|
||||
}
|
||||
|
||||
IsInFullscreen = !IsInFullscreen;
|
||||
}
|
||||
int Lua_ToggleFullscreen(lua_State *L) {
|
||||
Command_ToggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Command_GetCFiles(void) {
|
||||
BSet main = GetActiveMainSet();
|
||||
|
||||
Scratch scratch;
|
||||
String buffer_name = GetUniqueBufferName(GetDir(main.buffer), "getcfiles");
|
||||
|
||||
Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4);
|
||||
ListFilesRecursive(buffer, Command_GetMainDir());
|
||||
WindowOpenBufferView(main.window, buffer_name);
|
||||
}
|
||||
int Lua_GetCFiles(lua_State *L) {
|
||||
Command_GetCFiles();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Command_ExecInNewBuffer(String cmd, String working_dir) {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
ActiveWindow = main.window->id;
|
||||
}
|
||||
int Lua_ExecInNewBuffer(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
String working_dir = Command_GetMainDir();
|
||||
Command_ExecInNewBuffer(string, working_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
|
||||
View *view = OpenBufferView(buffer_name);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
// buffer->garbage = true;
|
||||
Exec(view->id, true, cmd, working_dir);
|
||||
return view;
|
||||
}
|
||||
|
||||
BSet Command_Exec(String cmd, String working_dir) {
|
||||
BSet set = GetActiveMainSet();
|
||||
ActiveWindow = set.window->id;
|
||||
Command_JumpNew(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
return set;
|
||||
}
|
||||
int Lua_C(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Exec(string, Command_GetMainDir());
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSet Command_Open(String path) {
|
||||
Scratch scratch;
|
||||
|
||||
lua_getglobal(LuaState, "OnOpen");
|
||||
lua_pushlstring(LuaState, path.data, path.len);
|
||||
if (lua_pcall(LuaState, 1, 1, 0) != 0) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed the call to OnOpen! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
return {};
|
||||
}
|
||||
|
||||
BSet main = GetActiveMainSet();
|
||||
main.window->active_goto_list = main.view->id;
|
||||
if (FieldString(LuaState, "kind") == "text") {
|
||||
String file_path = FieldString(LuaState, "file_path");
|
||||
String line_string = FieldString(LuaState, "line");
|
||||
Int line = strtoll(line_string.data, NULL, 10);
|
||||
String col_string = FieldString(LuaState, "col");
|
||||
Int col = strtoll(col_string.data, NULL, 10);
|
||||
|
||||
ActiveWindow = main.window->id;
|
||||
if (IsDir(file_path)) {
|
||||
Command_JumpNew(&main);
|
||||
main.buffer->name = GetUniqueBufferName(file_path, "temp");
|
||||
Command_Appendf(main.view, "..\n", FmtString(file_path));
|
||||
for (FileIter it = IterateFiles(scratch, file_path); IsValid(it); Advance(&it)) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it.filename));
|
||||
}
|
||||
} else {
|
||||
CheckpointBeforeGoto(main.window);
|
||||
View *view = WindowOpenBufferView(main.window, file_path);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
if (line != -1 && col != -1) {
|
||||
Int pos = XYToPos(buffer, {col - 1, line - 1});
|
||||
view->carets[0] = MakeCaret(pos);
|
||||
}
|
||||
}
|
||||
UpdateScroll(main.window, true);
|
||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
Command_Exec(cmd, Command_GetMainDir());
|
||||
} else if (FieldString(LuaState, "kind") == "exec_console") {
|
||||
// this shouldn't change the focus/window/view
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
Exec(NullViewID, true, cmd, working_dir);
|
||||
} else {
|
||||
ReportWarningf("Failed to match any of OnOpen results!");
|
||||
}
|
||||
|
||||
return main;
|
||||
}
|
||||
|
||||
BSet Command_Open(String16 path) {
|
||||
Scratch scratch;
|
||||
String string = ToString(scratch, path);
|
||||
return Command_Open(string);
|
||||
}
|
||||
|
||||
int Lua_Open(lua_State *L) {
|
||||
Scratch scratch;
|
||||
String path = luaL_checkstring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Open(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_Cmd(lua_State *L) {
|
||||
if (!lua_istable(L, -1)) luaL_error(L, "expected a table as argument");
|
||||
defer { lua_pop(L, 1); };
|
||||
|
||||
lua_getfield(L, -1, "working_dir");
|
||||
String working_dir = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (working_dir == "") {
|
||||
working_dir = Command_GetMainDir();
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, "cmd");
|
||||
if (!lua_isstring(L, -1)) luaL_error(L, "expected a string for cmd param");
|
||||
String cmd = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "kind");
|
||||
String kind = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
BSet main = GetActiveMainSet();
|
||||
if (kind == "console") {
|
||||
BSet set = GetConsoleSet();
|
||||
main.window->active_goto_list = set.view->id;
|
||||
main.window->goto_list_pos = set.buffer->len;
|
||||
Command_SelectRangeOneCursor(set.view, Rng(set.buffer->len));
|
||||
Command_BeginJump(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndJump(set);
|
||||
} else if (kind == "fuzzy") {
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
main.view->fuzzy_search = true;
|
||||
ActiveWindow = main.window->id;
|
||||
} else {
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
ActiveWindow = main.window->id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Command_ListBuffers() {
|
||||
BSet main = GetActiveMainSet();
|
||||
ActiveWindow = main.window->id;
|
||||
Command_JumpNew(&main);
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
|
||||
}
|
||||
}
|
||||
int Lua_ListBuffers(lua_State *L) {
|
||||
Command_ListBuffers();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Command_Eval(String string) {
|
||||
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Execution error! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
}
|
||||
void Command_Eval(String16 string) {
|
||||
Scratch scratch;
|
||||
Command_Eval(ToString(scratch, string));
|
||||
}
|
||||
int Lua_Eval(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Eval(string);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int Lua_SetProjectFile(lua_State *L) {
|
||||
BSet set = GetActiveMainSet();
|
||||
LuaProjectBuffer = set.buffer;
|
||||
LuaProjectBuffer->user_change_id = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_ListCommands(lua_State *L) {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_BeginJump(&main);
|
||||
for (int i = 0; LuaFunctions[i].name != NULL; i += 1) {
|
||||
Command_Appendf(main.view, "%20s() ", LuaFunctions[i].name);
|
||||
if (((i + 1) % 6) == 0) {
|
||||
Command_Appendf(main.view, "\n");
|
||||
}
|
||||
}
|
||||
Command_EndJump(main);
|
||||
ActiveWindow = main.window->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_GetBufferList(lua_State *L) {
|
||||
lua_createtable(L, 0, (int)BufferCount);
|
||||
|
||||
int i = 1;
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
lua_pushinteger(L, i++);
|
||||
lua_pushlstring(L, it->name.data, it->name.len);
|
||||
lua_settable(L, -3); /* 3rd element from the stack top */
|
||||
}
|
||||
/* We still have table left on top of the Lua stack. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -12,28 +12,6 @@ String16 GetSearchString(Window *window) {
|
||||
return string;
|
||||
}
|
||||
|
||||
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 {
|
||||
bool good = EndsWith(it.filename, ".c") ||
|
||||
EndsWith(it.filename, ".h") ||
|
||||
EndsWith(it.filename, ".cpp") ||
|
||||
EndsWith(it.filename, ".hpp") ||
|
||||
EndsWith(it.filename, ".bat");
|
||||
if (!good) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(buffer, "%.*s\n", FmtString(it.absolute_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String16 FetchLoadWord(void) {
|
||||
BSet active = GetActiveSet();
|
||||
Caret caret = active.view->carets[0];
|
||||
@@ -43,17 +21,6 @@ String16 FetchLoadWord(void) {
|
||||
return string;
|
||||
}
|
||||
|
||||
void Command_GetCFiles(void) {
|
||||
BSet main = GetActiveMainSet();
|
||||
|
||||
Scratch scratch;
|
||||
String buffer_name = GetUniqueBufferName(GetDir(main.buffer), "getcfiles");
|
||||
|
||||
Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4);
|
||||
ListFilesRecursive(buffer, Command_GetMainDir());
|
||||
WindowOpenBufferView(main.window, buffer_name);
|
||||
}
|
||||
|
||||
Window *GetRightWindow(WindowSplit *split, Window *window, bool *next_is_the_one) {
|
||||
if (split->kind == WindowSplitKind_Window) {
|
||||
if (*next_is_the_one) {
|
||||
@@ -431,7 +398,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (Press(SDLK_F11)) {
|
||||
ToggleFullscreen();
|
||||
Command_ToggleFullscreen();
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_GRAVE)) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
String16 SavedClipboardString;
|
||||
Array<String16> SavedClipboardCarets;
|
||||
|
||||
void MakeSureToUseSystemAllocator_SaveInClipboard(String16 string, Array<String16> caret_strings = {}) {
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
lua_State *LuaState = NULL;
|
||||
String16 LuaCommandResult = {};
|
||||
extern luaL_Reg LuaFunctions[];
|
||||
|
||||
|
||||
String FieldString(lua_State *L, String name) {
|
||||
String result = {};
|
||||
if (lua_istable(L, -1)) {
|
||||
@@ -16,201 +11,6 @@ String FieldString(lua_State *L, String name) {
|
||||
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) {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
ActiveWindow = set.window->id;
|
||||
}
|
||||
|
||||
View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
|
||||
View *view = OpenBufferView(buffer_name);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
// buffer->garbage = true;
|
||||
Exec(view->id, true, cmd, working_dir);
|
||||
return view;
|
||||
}
|
||||
|
||||
void Command_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
set->buffer = GetBuffer(buffer_id);
|
||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
||||
}
|
||||
|
||||
void Command_EndJump(BSet set) {
|
||||
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
||||
set.view->carets[0] = MakeCaret(pos);
|
||||
UpdateScroll(set.window, true);
|
||||
}
|
||||
|
||||
void Command_ListBuffers() {
|
||||
BSet main = GetActiveMainSet();
|
||||
ActiveWindow = main.window->id;
|
||||
Command_JumpNew(&main);
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
|
||||
}
|
||||
}
|
||||
|
||||
BSet Command_Exec(String cmd, String working_dir) {
|
||||
BSet set = GetActiveMainSet();
|
||||
ActiveWindow = set.window->id;
|
||||
Command_JumpNew(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
return set;
|
||||
}
|
||||
|
||||
BSet Command_Open(String path) {
|
||||
Scratch scratch;
|
||||
|
||||
lua_getglobal(LuaState, "OnOpen");
|
||||
lua_pushlstring(LuaState, path.data, path.len);
|
||||
if (lua_pcall(LuaState, 1, 1, 0) != 0) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed the call to OnOpen! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
return {};
|
||||
}
|
||||
|
||||
BSet main = GetActiveMainSet();
|
||||
main.window->active_goto_list = main.view->id;
|
||||
if (FieldString(LuaState, "kind") == "text") {
|
||||
String file_path = FieldString(LuaState, "file_path");
|
||||
String line_string = FieldString(LuaState, "line");
|
||||
Int line = strtoll(line_string.data, NULL, 10);
|
||||
String col_string = FieldString(LuaState, "col");
|
||||
Int col = strtoll(col_string.data, NULL, 10);
|
||||
|
||||
ActiveWindow = main.window->id;
|
||||
if (IsDir(file_path)) {
|
||||
Command_JumpNew(&main);
|
||||
main.buffer->name = GetUniqueBufferName(file_path, "temp");
|
||||
Command_Appendf(main.view, "..\n", FmtString(file_path));
|
||||
for (FileIter it = IterateFiles(scratch, file_path); IsValid(it); Advance(&it)) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it.filename));
|
||||
}
|
||||
} else {
|
||||
CheckpointBeforeGoto(main.window);
|
||||
View *view = WindowOpenBufferView(main.window, file_path);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
if (line != -1 && col != -1) {
|
||||
Int pos = XYToPos(buffer, {col - 1, line - 1});
|
||||
view->carets[0] = MakeCaret(pos);
|
||||
}
|
||||
}
|
||||
UpdateScroll(main.window, true);
|
||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
Command_Exec(cmd, Command_GetMainDir());
|
||||
} else if (FieldString(LuaState, "kind") == "exec_console") {
|
||||
// this shouldn't change the focus/window/view
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
Exec(NullViewID, true, cmd, working_dir);
|
||||
} else {
|
||||
ReportWarningf("Failed to match any of OnOpen results!");
|
||||
}
|
||||
|
||||
return main;
|
||||
}
|
||||
|
||||
BSet Command_Open(String16 path) {
|
||||
Scratch scratch;
|
||||
String string = ToString(scratch, path);
|
||||
return Command_Open(string);
|
||||
}
|
||||
|
||||
int Lua_C(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Exec(string, Command_GetMainDir());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Command_Eval(String string) {
|
||||
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Execution error! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Command_Eval(String16 string) {
|
||||
Scratch scratch;
|
||||
Command_Eval(ToString(scratch, string));
|
||||
}
|
||||
|
||||
int Lua_Eval(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Eval(string);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_NewBufferCMD(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
String working_dir = Command_GetMainDir();
|
||||
BSet set = GetActiveMainSet();
|
||||
Command_ExecInNewBuffer(set, string, working_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_Cmd(lua_State *L) {
|
||||
if (!lua_istable(L, -1)) luaL_error(L, "expected a table as argument");
|
||||
defer { lua_pop(L, 1); };
|
||||
|
||||
lua_getfield(L, -1, "working_dir");
|
||||
String working_dir = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (working_dir == "") {
|
||||
working_dir = Command_GetMainDir();
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, "cmd");
|
||||
if (!lua_isstring(L, -1)) luaL_error(L, "expected a string for cmd param");
|
||||
String cmd = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "kind");
|
||||
String kind = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
BSet main = GetActiveMainSet();
|
||||
if (kind == "console") {
|
||||
BSet set = GetConsoleSet();
|
||||
main.window->active_goto_list = set.view->id;
|
||||
main.window->goto_list_pos = set.buffer->len;
|
||||
Command_SelectRangeOneCursor(set.view, Rng(set.buffer->len));
|
||||
Command_BeginJump(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndJump(set);
|
||||
} else if (kind == "fuzzy") {
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
main.view->fuzzy_search = true;
|
||||
ActiveWindow = main.window->id;
|
||||
} else {
|
||||
Command_JumpNew(&main);
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
ActiveWindow = main.window->id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_Print(lua_State *L) {
|
||||
Scratch scratch;
|
||||
int nargs = lua_gettop(L);
|
||||
@@ -258,58 +58,6 @@ int Lua_New(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_Open(lua_State *L) {
|
||||
Scratch scratch;
|
||||
String path = luaL_checkstring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
Command_Open(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_SetProjectFile(lua_State *L) {
|
||||
BSet set = GetActiveMainSet();
|
||||
LuaProjectBuffer = set.buffer;
|
||||
LuaProjectBuffer->user_change_id = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_ListCommands(lua_State *L) {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_BeginJump(&main);
|
||||
for (int i = 0; LuaFunctions[i].name != NULL; i += 1) {
|
||||
Command_Appendf(main.view, "%20s() ", LuaFunctions[i].name);
|
||||
if (((i + 1) % 6) == 0) {
|
||||
Command_Appendf(main.view, "\n");
|
||||
}
|
||||
}
|
||||
Command_EndJump(main);
|
||||
ActiveWindow = main.window->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_ToggleFullscreen(lua_State *L) {
|
||||
ToggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_ListBuffers(lua_State *L) {
|
||||
Command_ListBuffers();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_GetBufferList(lua_State *L) {
|
||||
lua_createtable(L, 0, (int)BufferCount);
|
||||
|
||||
int i = 1;
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
lua_pushinteger(L, i++);
|
||||
lua_pushlstring(L, it->name.data, it->name.len);
|
||||
lua_settable(L, -3); /* 3rd element from the stack top */
|
||||
}
|
||||
/* We still have table left on top of the Lua stack. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_BufferExists(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
@@ -318,17 +66,6 @@ int Lua_BufferExists(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_GetCFiles(lua_State *L) {
|
||||
Command_GetCFiles();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_Rename(lua_State *L) {
|
||||
String string = lua_tostring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_GetSelection(lua_State *L) {
|
||||
Scratch scratch;
|
||||
BSet main = GetActiveMainSet();
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
luaL_Reg LuaFunctions[] = {
|
||||
{"C", Lua_C},
|
||||
{"Eval", Lua_Eval},
|
||||
{"NewBufferCMD", Lua_NewBufferCMD},
|
||||
{"Cmd", Lua_Cmd},
|
||||
{"Print", Lua_Print},
|
||||
{"Kill", Lua_Kill},
|
||||
{"GetLoadWord", Lua_GetLoadWord},
|
||||
{"New", Lua_New},
|
||||
{"Open", Lua_Open},
|
||||
{"SetProjectFile", Lua_SetProjectFile},
|
||||
{"ListCommands", Lua_ListCommands},
|
||||
{"ToggleFullscreen", Lua_ToggleFullscreen},
|
||||
{"ListBuffers", Lua_ListBuffers},
|
||||
{"GetBufferList", Lua_GetBufferList},
|
||||
{"BufferExists", Lua_BufferExists},
|
||||
{"GetCFiles", Lua_GetCFiles},
|
||||
{"Rename", Lua_Rename},
|
||||
{"GetSelection", Lua_GetSelection},
|
||||
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
||||
{"GetClipboard", Lua_GetClipboard},
|
||||
@@ -27,5 +15,16 @@ luaL_Reg LuaFunctions[] = {
|
||||
{"SplitSize", Lua_SplitSize},
|
||||
{"Play", Lua_Play},
|
||||
{"Reopen", Lua_Reopen},
|
||||
{"ToggleFullscreen", Lua_ToggleFullscreen},
|
||||
{"GetCFiles", Lua_GetCFiles},
|
||||
{"ExecInNewBuffer", Lua_ExecInNewBuffer},
|
||||
{"C", Lua_C},
|
||||
{"Open", Lua_Open},
|
||||
{"Cmd", Lua_Cmd},
|
||||
{"ListBuffers", Lua_ListBuffers},
|
||||
{"Eval", Lua_Eval},
|
||||
{"SetProjectFile", Lua_SetProjectFile},
|
||||
{"ListCommands", Lua_ListCommands},
|
||||
{"GetBufferList", Lua_GetBufferList},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -14,11 +14,13 @@ Buffer *FirstBuffer;
|
||||
Buffer *LastBuffer;
|
||||
Int BufferCount;
|
||||
|
||||
BufferID NullBufferID; // +buffer
|
||||
// console
|
||||
BufferID NullBufferID;
|
||||
ViewID NullViewID;
|
||||
WindowID NullWindowID;
|
||||
|
||||
WindowID DebugWindowID; // +debug
|
||||
// hidden floating window
|
||||
WindowID DebugWindowID;
|
||||
BufferID DebugBufferID;
|
||||
|
||||
WindowSplit WindowSplits;
|
||||
@@ -35,6 +37,17 @@ Buffer *EventBuffer;
|
||||
Buffer *ScratchBuffer;
|
||||
|
||||
RandomSeed UniqueBufferNameSeed = {};
|
||||
|
||||
// lua
|
||||
lua_State *LuaState = NULL;
|
||||
String16 LuaCommandResult = {};
|
||||
extern luaL_Reg LuaFunctions[];
|
||||
|
||||
// clipboard
|
||||
String16 SavedClipboardString;
|
||||
Array<String16> SavedClipboardCarets;
|
||||
|
||||
|
||||
String GetUniqueBufferName(String working_dir, String prepend_name) {
|
||||
if (UniqueBufferNameSeed.a == 0) {
|
||||
double value = get_time_in_micros();
|
||||
|
||||
@@ -38,12 +38,14 @@ int FullScreenPositionX, FullScreenPositionY;
|
||||
#include "process.cpp"
|
||||
#include "serializer.cpp"
|
||||
#include "event.cpp"
|
||||
|
||||
|
||||
#include "lua_api.cpp"
|
||||
#include "commands.cpp"
|
||||
#include "commands_clipboard.cpp"
|
||||
#include "commands_bindings.cpp"
|
||||
#include "title_bar.cpp"
|
||||
|
||||
#include "lua_api.cpp"
|
||||
#include "lua_api_generated.cpp"
|
||||
#include "generated.cpp"
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
!!As little lua code as possible, but lua code should be powerful just in case of quick edits
|
||||
- maybe we could allow user to change window titles which would make them special in some way. A:/text_editor/+test_buffer:1:1:ADE |
|
||||
- Changing window properties by changing the window name?
|
||||
- Scroll the console properly
|
||||
- commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
|
||||
- organize commands and lua bindings somehow, it's kinda confusing right now, maybe group command->luacommand, the command name implies it also doubles as lua command?
|
||||
@@ -59,3 +58,8 @@ buffer = make_buffer()
|
||||
buffer.append(list_files("src/basic"))
|
||||
activate_buffer
|
||||
--------------
|
||||
|
||||
|
||||
|
||||
|
||||
!!As little lua code as possible, but lua code should be powerful just in case of quick edits
|
||||
|
||||
Reference in New Issue
Block a user