Add metadata to Command_Open and move the logic that denies the NextGotoBuild to lua
This commit is contained in:
@@ -54,6 +54,15 @@ SDLK_X = 0x00000078
|
||||
SDLK_Y = 0x00000079
|
||||
SDLK_Z = 0x0000007a
|
||||
|
||||
function IsAlpha(a)
|
||||
if a == nil then
|
||||
return false
|
||||
end
|
||||
local x = string.byte(a)
|
||||
local result = (x >= string.byte('a') and x <= string.byte('z')) or (x >= string.byte('A') and x <= string.byte('Z'))
|
||||
return result
|
||||
end
|
||||
|
||||
function SkipLineAndColumn(s)
|
||||
local line, col = "1", "1"
|
||||
|
||||
@@ -163,7 +172,7 @@ function SkipPath(s)
|
||||
return s, path, drive, cells
|
||||
end
|
||||
|
||||
function MatchWindowsPath(_s)
|
||||
function MatchWindowsPath(_s, meta)
|
||||
local s, file_path, drive = SkipPath(_s)
|
||||
|
||||
if not file_path and FileExists(drive) then
|
||||
@@ -186,7 +195,7 @@ function MatchWindowsPath(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchGitCommit(s)
|
||||
function MatchGitCommit(s, meta)
|
||||
local i, j = string.find(s, "^commit ([a-zA-Z0-9]+)")
|
||||
if i then
|
||||
s = s:sub(8)
|
||||
@@ -196,7 +205,7 @@ function MatchGitCommit(s)
|
||||
return nil
|
||||
end
|
||||
|
||||
function MatchURL(s)
|
||||
function MatchURL(s, meta)
|
||||
local i, j = string.find(s, "^https://")
|
||||
if i then
|
||||
return {kind = "exec_console", cmd = '"'..INTERNET_BROWSER..'" '..s, working_dir = GetMainDir()}
|
||||
@@ -204,16 +213,34 @@ function MatchURL(s)
|
||||
return nil
|
||||
end
|
||||
|
||||
Rules = {
|
||||
function MatchGotoBuild(s, meta)
|
||||
if meta ~= "goto_build" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local windows_path = IsAlpha(s:sub(1,1)) and s:sub(2,2) == ':'
|
||||
local windows_rela = s:sub(1,1) == '.' and s:sub(2,2) == '\\'
|
||||
local unix_path = s:sub(1,1) == '/'
|
||||
local unix_rela = s:sub(1,1) == '.' and s:sub(2,2) == '/'
|
||||
|
||||
if not windows_path and not windows_rela and not unix_path and not windows_rela then
|
||||
return {kind = "skip"}
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
OnOpenMatchers = {
|
||||
MatchWindowsPath,
|
||||
MatchGitCommit,
|
||||
MatchURL,
|
||||
MatchGotoBuild,
|
||||
}
|
||||
|
||||
function OnOpen(s)
|
||||
for i = #Rules,1,-1 do
|
||||
rule = Rules[i]
|
||||
result = rule(s)
|
||||
function OnOpen(path, meta)
|
||||
for i = #OnOpenMatchers,1,-1 do
|
||||
rule = OnOpenMatchers[i]
|
||||
result = rule(path, meta)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -832,14 +832,7 @@ void Command_GotoNextInList(Window *window, Int line_offset = 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool windows_path = IsAlphabetic(line.data[0]) && line.data[1] == ':';
|
||||
bool unix_path = line.data[0] == '/';
|
||||
if (!windows_path && !unix_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CheckpointBeforeGoto(window, active_view);
|
||||
BSet set = Command_Open(line);
|
||||
BSet set = Command_Open(line, "goto_build");
|
||||
if (set.window == NULL) {
|
||||
continue;
|
||||
}
|
||||
@@ -966,12 +959,13 @@ int Lua_C(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSet Command_Open(String path) {
|
||||
BSet Command_Open(String path, String meta) {
|
||||
Scratch scratch;
|
||||
|
||||
lua_getglobal(LuaState, "OnOpen");
|
||||
lua_pushlstring(LuaState, path.data, path.len);
|
||||
if (lua_pcall(LuaState, 1, 1, 0) != 0) {
|
||||
lua_pushlstring(LuaState, meta.data, meta.len);
|
||||
if (lua_pcall(LuaState, 2, 1, 0) != 0) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed the call to OnOpen! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
@@ -979,8 +973,8 @@ BSet Command_Open(String path) {
|
||||
}
|
||||
|
||||
BSet main = GetActiveMainSet();
|
||||
main.window->active_goto_list = main.view->id;
|
||||
if (FieldString(LuaState, "kind") == "text") {
|
||||
String kind = FieldString(LuaState, "kind");
|
||||
if (kind == "text") {
|
||||
String file_path = FieldString(LuaState, "file_path");
|
||||
String line_string = FieldString(LuaState, "line");
|
||||
Int line = strtoll(line_string.data, NULL, 10);
|
||||
@@ -1005,15 +999,17 @@ BSet Command_Open(String path) {
|
||||
}
|
||||
}
|
||||
UpdateScroll(main.window, true);
|
||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||
} else if (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") {
|
||||
} else if (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 if (kind == "skip") {
|
||||
return {};
|
||||
} else {
|
||||
ReportWarningf("Failed to match any of OnOpen results!");
|
||||
}
|
||||
@@ -1021,10 +1017,10 @@ BSet Command_Open(String path) {
|
||||
return main;
|
||||
}
|
||||
|
||||
BSet Command_Open(String16 path) {
|
||||
BSet Command_Open(String16 path, String meta) {
|
||||
Scratch scratch;
|
||||
String string = ToString(scratch, path);
|
||||
return Command_Open(string);
|
||||
return Command_Open(string, meta);
|
||||
}
|
||||
|
||||
int Lua_Open(lua_State *L) {
|
||||
@@ -1110,7 +1106,6 @@ int Lua_Eval(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int Lua_SetProjectFile(lua_State *L) {
|
||||
BSet set = GetActiveMainSet();
|
||||
LuaProjectBuffer = set.buffer;
|
||||
|
||||
@@ -126,6 +126,15 @@ SDLK_X = 0x00000078
|
||||
SDLK_Y = 0x00000079
|
||||
SDLK_Z = 0x0000007a
|
||||
|
||||
function IsAlpha(a)
|
||||
if a == nil then
|
||||
return false
|
||||
end
|
||||
local x = string.byte(a)
|
||||
local result = (x >= string.byte('a') and x <= string.byte('z')) or (x >= string.byte('A') and x <= string.byte('Z'))
|
||||
return result
|
||||
end
|
||||
|
||||
function SkipLineAndColumn(s)
|
||||
local line, col = "1", "1"
|
||||
|
||||
@@ -235,7 +244,7 @@ function SkipPath(s)
|
||||
return s, path, drive, cells
|
||||
end
|
||||
|
||||
function MatchWindowsPath(_s)
|
||||
function MatchWindowsPath(_s, meta)
|
||||
local s, file_path, drive = SkipPath(_s)
|
||||
|
||||
if not file_path and FileExists(drive) then
|
||||
@@ -258,7 +267,7 @@ function MatchWindowsPath(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchGitCommit(s)
|
||||
function MatchGitCommit(s, meta)
|
||||
local i, j = string.find(s, "^commit ([a-zA-Z0-9]+)")
|
||||
if i then
|
||||
s = s:sub(8)
|
||||
@@ -268,7 +277,7 @@ function MatchGitCommit(s)
|
||||
return nil
|
||||
end
|
||||
|
||||
function MatchURL(s)
|
||||
function MatchURL(s, meta)
|
||||
local i, j = string.find(s, "^https://")
|
||||
if i then
|
||||
return {kind = "exec_console", cmd = '"'..INTERNET_BROWSER..'" '..s, working_dir = GetMainDir()}
|
||||
@@ -276,16 +285,34 @@ function MatchURL(s)
|
||||
return nil
|
||||
end
|
||||
|
||||
Rules = {
|
||||
function MatchGotoBuild(s, meta)
|
||||
if meta ~= "goto_build" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local windows_path = IsAlpha(s:sub(1,1)) and s:sub(2,2) == ':'
|
||||
local windows_rela = s:sub(1,1) == '.' and s:sub(2,2) == '\\'
|
||||
local unix_path = s:sub(1,1) == '/'
|
||||
local unix_rela = s:sub(1,1) == '.' and s:sub(2,2) == '/'
|
||||
|
||||
if not windows_path and not windows_rela and not unix_path and not windows_rela then
|
||||
return {kind = "skip"}
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
OnOpenMatchers = {
|
||||
MatchWindowsPath,
|
||||
MatchGitCommit,
|
||||
MatchURL,
|
||||
MatchGotoBuild,
|
||||
}
|
||||
|
||||
function OnOpen(s)
|
||||
for i = #Rules,1,-1 do
|
||||
rule = Rules[i]
|
||||
result = rule(s)
|
||||
function OnOpen(path, meta)
|
||||
for i = #OnOpenMatchers,1,-1 do
|
||||
rule = OnOpenMatchers[i]
|
||||
result = rule(path, meta)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -111,8 +111,8 @@ float DPIScale = 1.0f;
|
||||
Rect2I GetVisibleCells(Window *window);
|
||||
void AfterEdit(View *view, Array<Edit> edits);
|
||||
Scroller ComputeScrollerRect(Window *window);
|
||||
BSet Command_Open(String path);
|
||||
BSet Command_Open(String16 path);
|
||||
BSet Command_Open(String path, String meta = "");
|
||||
BSet Command_Open(String16 path, String meta = "");
|
||||
void UpdateScroll(Window *window, bool update_caret_scrolling);
|
||||
|
||||
void Command_SelectEntireBuffer(View *view);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
- Delete directory/file on disk command
|
||||
- Create directory command (probably should enter it automatically
|
||||
- Convert more commands to taking buffer instead of view
|
||||
- Add Command_Open that takes window/view as param
|
||||
|
||||
- save all relevant buffers and build
|
||||
- shift down on last line should move the cursor to end of line!!! same for up
|
||||
|
||||
Reference in New Issue
Block a user