FKey function, fix goto build, GetLine, remedybg

This commit is contained in:
Krzosa Karol
2025-05-13 09:04:52 +02:00
parent 7eec390752
commit f7f2aafc56
9 changed files with 43 additions and 14 deletions

View File

@@ -309,7 +309,9 @@ function KeybindsFKeys(e)
for i = #FKey,1,-1 do for i = #FKey,1,-1 do
if FKey[i] ~= "" then if FKey[i] ~= "" then
if e.key == FKeySDLK[i] then if e.key == FKeySDLK[i] then
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = FKey[i] } local cmdline = FKey[i]
if type(cmdline) == "function" then cmdline = FKey[i]() end
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = cmdline }
return true return true
end end
end end

View File

@@ -1,4 +1,3 @@
CmdParser MakeCmdParser(MA_Arena *arena, int argc, char **argv, const char *custom_help) { CmdParser MakeCmdParser(MA_Arena *arena, int argc, char **argv, const char *custom_help) {
CmdParser result = {argc, argv, arena, custom_help}; CmdParser result = {argc, argv, arena, custom_help};
return result; return result;

View File

@@ -1214,11 +1214,27 @@ void Command_ListBuffers() {
Command_Appendf(main.view, "%.*s\n", FmtString(it->name)); Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
} }
} }
int Lua_ListBuffers(lua_State *L) { int Lua_ListBuffers(lua_State *L) {
Command_ListBuffers(); Command_ListBuffers();
return 0; return 0;
} }
void Command_ListViews() {
BSet main = GetActiveMainSet();
ActiveWindow = main.window->id;
JumpGarbageBuffer(&main);
for (View *it = FirstView; it; it = it->next) {
Buffer *buffer = GetBuffer(it->active_buffer);
Command_Appendf(main.view, "%d %.*s\n", (int)it->id.id, FmtString(buffer->name));
}
}
int Lua_ListViews(lua_State *L) {
Command_ListViews();
return 0;
}
void Command_Eval(String string) { void Command_Eval(String string) {
if (luaL_dostring(LuaState, string.data) != LUA_OK) { if (luaL_dostring(LuaState, string.data) != LUA_OK) {
const char *error_message = lua_tostring(LuaState, -1); const char *error_message = lua_tostring(LuaState, -1);
@@ -1226,10 +1242,12 @@ void Command_Eval(String string) {
lua_pop(LuaState, 1); lua_pop(LuaState, 1);
} }
} }
void Command_Eval(String16 string) { void Command_Eval(String16 string) {
Scratch scratch; Scratch scratch;
Command_Eval(ToString(scratch, string)); Command_Eval(ToString(scratch, string));
} }
int Lua_Eval(lua_State *L) { int Lua_Eval(lua_State *L) {
String string = lua_tostring(L, 1); String string = lua_tostring(L, 1);
lua_pop(L, 1); lua_pop(L, 1);

View File

@@ -284,10 +284,10 @@ void OnCommand(Event event) {
} }
if (CtrlPress(SDLK_P)) { if (CtrlAltPress(SDLK_P)) {
Command_ListCode();
} else if (CtrlAltPress(SDLK_P)) {
Command_ListBuffers(); Command_ListBuffers();
} else if (CtrlPress(SDLK_P)) {
Command_ListCode();
} }
if (CtrlShiftPress(SDLK_BACKSLASH)) { if (CtrlShiftPress(SDLK_BACKSLASH)) {
@@ -528,9 +528,9 @@ void OnCommand(Event event) {
} }
if (CtrlPress(SDLK_E)) { if (CtrlPress(SDLK_E)) {
Command_GotoNextInList(active.window, -1);
} else if (AltPress(SDLK_E)) {
Command_GotoNextInList(active.window, 1); Command_GotoNextInList(active.window, 1);
} else if (AltPress(SDLK_E)) {
Command_GotoNextInList(active.window, -1);
} }
if (CtrlPress(SDLK_F)) { if (CtrlPress(SDLK_F)) {

View File

@@ -379,7 +379,10 @@ function KeybindsFKeys(e)
for i = #FKey,1,-1 do for i = #FKey,1,-1 do
if FKey[i] ~= "" then if FKey[i] ~= "" then
if e.key == FKeySDLK[i] then if e.key == FKeySDLK[i] then
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = FKey[i] } local cmdline = FKey[i]
if type(cmdline) == "function" then cmdline = FKey[i]() end
Print(cmdline)
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = cmdline }
return true return true
end end
end end

View File

@@ -70,6 +70,15 @@ int Lua_GetFilename(lua_State *L) {
return 1; return 1;
} }
int Lua_GetLine(lua_State *L) {
BSet main = GetActiveMainSet();
Caret caret = main.view->carets[0];
Int front = GetFront(caret);
Int line = PosToLine(main.buffer, front);
lua_pushinteger(L, line + 1);
return 1;
}
int Lua_FileExists(lua_State *L) { int Lua_FileExists(lua_State *L) {
String path = luaL_checkstring(L, 1); String path = luaL_checkstring(L, 1);
lua_pop(L, 1); lua_pop(L, 1);

View File

@@ -7,6 +7,7 @@ luaL_Reg LuaFunctions[] = {
{"GetEntireBuffer", Lua_GetEntireBuffer}, {"GetEntireBuffer", Lua_GetEntireBuffer},
{"GetClipboard", Lua_GetClipboard}, {"GetClipboard", Lua_GetClipboard},
{"GetFilename", Lua_GetFilename}, {"GetFilename", Lua_GetFilename},
{"GetLine", Lua_GetLine},
{"FileExists", Lua_FileExists}, {"FileExists", Lua_FileExists},
{"GetWorkDir", Lua_GetWorkDir}, {"GetWorkDir", Lua_GetWorkDir},
{"GetMainDir", Lua_GetMainDir}, {"GetMainDir", Lua_GetMainDir},
@@ -26,6 +27,7 @@ luaL_Reg LuaFunctions[] = {
{"Open", Lua_Open}, {"Open", Lua_Open},
{"Cmd", Lua_Cmd}, {"Cmd", Lua_Cmd},
{"ListBuffers", Lua_ListBuffers}, {"ListBuffers", Lua_ListBuffers},
{"ListViews", Lua_ListViews},
{"Eval", Lua_Eval}, {"Eval", Lua_Eval},
{"SetProjectFile", Lua_SetProjectFile}, {"SetProjectFile", Lua_SetProjectFile},
{"SetWorkDir", Lua_SetWorkDir}, {"SetWorkDir", Lua_SetWorkDir},

View File

@@ -486,4 +486,4 @@ end_of_editor_loop:;
EndProfiler(); EndProfiler();
return 0; return 0;
} }

View File

@@ -5,8 +5,8 @@
- Delete directory/file on disk command - Delete directory/file on disk command
- Check. Convert more commands to taking buffer instead of view - Check. Convert more commands to taking buffer instead of view
- Check. Rewrite more commands to use already implemented commands? - Check. Rewrite more commands to use already implemented commands?
- Lua OnCommand should be able to comunicate that we don't want C handling and do only the Lua handling
- Lua namespaces for different kinds of commands (by ids, using main_set, using active_set)? - Lua namespaces for different kinds of commands (by ids, using main_set, using active_set)?
- Some decl/function indexing in fuzzy format
- Set window layout using project file - Set window layout using project file
- Split command - Split command
@@ -15,10 +15,6 @@
- Open buffer using id - Open buffer using id
- Set active window using id - Set active window using id
- Fix jump scroll, the query ends up the last line on screen, kind of wacky - Fix jump scroll, the query ends up the last line on screen, kind of wacky
- Use project file as working dir instead of scratch buffer path, separate project dir and project file
- Remedybg integration
- GetLine()
- in lua start debugging, jump to line, start debugger on file
- save all relevant buffers and build - save all relevant buffers and build
- maybe most of the bindings should be in lua, but actual code in C - maybe most of the bindings should be in lua, but actual code in C