Toying with windows paths, ExecInNewBuffer, c'', Fix caret loss in title bar
This commit is contained in:
@@ -176,7 +176,56 @@ char *C(const char *value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
S8_String LuaScript = R"==(
|
S8_String LuaScript = R"==(
|
||||||
function ExtractLineAndColumn(s)
|
function SkipLineAndColumn(s)
|
||||||
|
local line, col = "1", "1"
|
||||||
|
|
||||||
|
function parse_line_and_column(line_and_col, delimiter)
|
||||||
|
ic, jc = line_and_col:find(delimiter)
|
||||||
|
line = line_and_col:sub(1, ic - 1)
|
||||||
|
col = line_and_col:sub(ic + 1)
|
||||||
|
return line, col
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- :line:column
|
||||||
|
local i, j = s:find("^:%d+:%d+")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line, col = parse_line_and_column(s:sub(2, j), ":")
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- :line
|
||||||
|
local i, j = s:find("^:%d+")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line = s:sub(2, j)
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- (line,column)
|
||||||
|
local i, j = s:find("^%(%d+,%d+%)")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line, col = parse_line_and_column(s:sub(2, j - 1), ",")
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- (line)
|
||||||
|
local i, j = s:find("^%(%d+%)")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line = s:sub(2, j - 1)
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return line, col, s
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChopLineAndColumn(s)
|
||||||
local line = 1
|
local line = 1
|
||||||
local col = 1
|
local col = 1
|
||||||
|
|
||||||
@@ -237,7 +286,7 @@ function ExtractLineAndColumn(s)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return -1, -1, s
|
return 1, 1, s
|
||||||
end
|
end
|
||||||
|
|
||||||
function BufferNameExists(name)
|
function BufferNameExists(name)
|
||||||
@@ -251,6 +300,13 @@ function BufferNameExists(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ChopColon(s)
|
||||||
|
if s:sub(-1) == ':' then
|
||||||
|
s = s:sub(1, -2)
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
function GenericTextFileRule(_s)
|
function GenericTextFileRule(_s)
|
||||||
function match_path(s)
|
function match_path(s)
|
||||||
-- ./something
|
-- ./something
|
||||||
@@ -258,7 +314,7 @@ function GenericTextFileRule(_s)
|
|||||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||||
if working_dir_j then
|
if working_dir_j then
|
||||||
result = s:sub(3)
|
result = s:sub(3)
|
||||||
result = GetWorkingDir().."/"..result
|
result = GetCurrentBufferDir().."/"..result
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -294,13 +350,14 @@ function GenericTextFileRule(_s)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
line, col, _s = ExtractLineAndColumn(_s)
|
line, col, _s = ChopLineAndColumn(_s)
|
||||||
|
_s = ChopColon(_s)
|
||||||
file_path = match_path(_s)
|
file_path = match_path(_s)
|
||||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||||
end
|
end
|
||||||
|
|
||||||
function MatchAgainstIncludes(s)
|
function MatchAgainstIncludes(s)
|
||||||
line, col, s = ExtractLineAndColumn(s)
|
line, col, s = ChopLineAndColumn(s)
|
||||||
include_paths = {
|
include_paths = {
|
||||||
"C:/Work/text_editor/src",
|
"C:/Work/text_editor/src",
|
||||||
"C:/Work/text_editor/src/text_editor",
|
"C:/Work/text_editor/src/text_editor",
|
||||||
|
|||||||
@@ -892,14 +892,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
if (GetSize(caret.range) == 0) range = EncloseExecWord(buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseExecWord(buffer, GetFront(caret));
|
||||||
String16 string = GetString(*buffer, range);
|
String16 string = GetString(*buffer, range);
|
||||||
|
|
||||||
if (GetChar(string, 0) == L'!') {
|
Command_EvalLua(view, string);
|
||||||
string = Skip(string, 1);
|
|
||||||
Exec(ConsoleViewID, true, string, GetCurrentBufferDir());
|
|
||||||
} else {
|
|
||||||
Command_EvalLua(view, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec(string, GetCurrentBufferDir());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_W)) {
|
if (Ctrl(SDLK_W)) {
|
||||||
|
|||||||
@@ -63,7 +63,56 @@ Style.FontSize = 12
|
|||||||
Style.FontFilter = 0
|
Style.FontFilter = 0
|
||||||
Style.Font = "C:/Windows/Fonts/consola.ttf"
|
Style.Font = "C:/Windows/Fonts/consola.ttf"
|
||||||
|
|
||||||
function ExtractLineAndColumn(s)
|
function SkipLineAndColumn(s)
|
||||||
|
local line, col = "1", "1"
|
||||||
|
|
||||||
|
function parse_line_and_column(line_and_col, delimiter)
|
||||||
|
ic, jc = line_and_col:find(delimiter)
|
||||||
|
line = line_and_col:sub(1, ic - 1)
|
||||||
|
col = line_and_col:sub(ic + 1)
|
||||||
|
return line, col
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- :line:column
|
||||||
|
local i, j = s:find("^:%d+:%d+")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line, col = parse_line_and_column(s:sub(2, j), ":")
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- :line
|
||||||
|
local i, j = s:find("^:%d+")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line = s:sub(2, j)
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- (line,column)
|
||||||
|
local i, j = s:find("^%(%d+,%d+%)")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line, col = parse_line_and_column(s:sub(2, j - 1), ",")
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do -- (line)
|
||||||
|
local i, j = s:find("^%(%d+%)")
|
||||||
|
if i then
|
||||||
|
skip_pattern = s:sub(j + 1)
|
||||||
|
line = s:sub(2, j - 1)
|
||||||
|
return line, col, skip_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return line, col, s
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChopLineAndColumn(s)
|
||||||
local line = 1
|
local line = 1
|
||||||
local col = 1
|
local col = 1
|
||||||
|
|
||||||
@@ -124,7 +173,7 @@ function ExtractLineAndColumn(s)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return -1, -1, s
|
return 1, 1, s
|
||||||
end
|
end
|
||||||
|
|
||||||
function BufferNameExists(name)
|
function BufferNameExists(name)
|
||||||
@@ -138,6 +187,13 @@ function BufferNameExists(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ChopColon(s)
|
||||||
|
if s:sub(-1) == ':' then
|
||||||
|
s = s:sub(1, -2)
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
function GenericTextFileRule(_s)
|
function GenericTextFileRule(_s)
|
||||||
function match_path(s)
|
function match_path(s)
|
||||||
-- ./something
|
-- ./something
|
||||||
@@ -145,7 +201,7 @@ function GenericTextFileRule(_s)
|
|||||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||||
if working_dir_j then
|
if working_dir_j then
|
||||||
result = s:sub(3)
|
result = s:sub(3)
|
||||||
result = GetWorkingDir().."/"..result
|
result = GetCurrentBufferDir().."/"..result
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -181,13 +237,14 @@ function GenericTextFileRule(_s)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
line, col, _s = ExtractLineAndColumn(_s)
|
line, col, _s = ChopLineAndColumn(_s)
|
||||||
|
_s = ChopColon(_s)
|
||||||
file_path = match_path(_s)
|
file_path = match_path(_s)
|
||||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||||
end
|
end
|
||||||
|
|
||||||
function MatchAgainstIncludes(s)
|
function MatchAgainstIncludes(s)
|
||||||
line, col, s = ExtractLineAndColumn(s)
|
line, col, s = ChopLineAndColumn(s)
|
||||||
include_paths = {
|
include_paths = {
|
||||||
"C:/Work/text_editor/src",
|
"C:/Work/text_editor/src",
|
||||||
"C:/Work/text_editor/src/text_editor",
|
"C:/Work/text_editor/src/text_editor",
|
||||||
|
|||||||
@@ -35,6 +35,18 @@ String GetUniqueBufferName(Allocator allocator, String working_dir, String p
|
|||||||
return buffer_name;
|
return buffer_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExecInNewBuffer(String cmd, String working_dir) {
|
||||||
|
Scratch scratch;
|
||||||
|
CheckpointBeforeGoto();
|
||||||
|
String buffer_name = GetUniqueBufferName(scratch, working_dir, "+CMD");
|
||||||
|
Window *window = GetWindow(GetLastActiveWindow());
|
||||||
|
View *view = WindowOpenBufferView(window, buffer_name);
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
view->carets[0] = MakeCaret({});
|
||||||
|
Exec(view->id, false, cmd, working_dir);
|
||||||
|
SetActiveWindow(window->id);
|
||||||
|
}
|
||||||
|
|
||||||
void Open(String path) {
|
void Open(String path) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
|
|
||||||
@@ -67,15 +79,7 @@ void Open(String path) {
|
|||||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||||
String cmd = FieldString(LuaState, "cmd");
|
String cmd = FieldString(LuaState, "cmd");
|
||||||
String working_dir = FieldString(LuaState, "working_dir");
|
String working_dir = FieldString(LuaState, "working_dir");
|
||||||
String buffer_name = GetUniqueBufferName(scratch, working_dir, "+CMD");
|
ExecInNewBuffer(cmd, working_dir);
|
||||||
|
|
||||||
CheckpointBeforeGoto();
|
|
||||||
Window *window = GetWindow(GetLastActiveWindow());
|
|
||||||
View *view = WindowOpenBufferView(window, buffer_name);
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
view->carets[0] = MakeCaret({});
|
|
||||||
Exec(view->id, false, cmd, working_dir);
|
|
||||||
SetActiveWindow(window->id);
|
|
||||||
} else {
|
} else {
|
||||||
ReportWarningf("Failed to match any of ApplyRules results!");
|
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||||
}
|
}
|
||||||
@@ -87,6 +91,15 @@ void Open(String16 path) {
|
|||||||
Open(string);
|
Open(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaExec(lua_State *L) {
|
||||||
|
String string = lua_tostring(L, 1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
String working_dir = GetCurrentBufferDir();
|
||||||
|
ExecInNewBuffer(string, working_dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaKill(lua_State *L) {
|
int LuaKill(lua_State *L) {
|
||||||
Window *window = GetCurrentWindow();
|
Window *window = GetCurrentWindow();
|
||||||
KillProcess(window->active_view);
|
KillProcess(window->active_view);
|
||||||
@@ -182,6 +195,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{ "print", LuaPrint},
|
{ "print", LuaPrint},
|
||||||
{ "Print", LuaPrint},
|
{ "Print", LuaPrint},
|
||||||
{ "Kill", LuaKill},
|
{ "Kill", LuaKill},
|
||||||
|
{ "c", LuaExec},
|
||||||
{ NULL, NULL},
|
{ NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
buffer->is_directory = true;
|
buffer->is_directory = true;
|
||||||
|
|
||||||
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
|
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
|
||||||
IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename));
|
IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.filename));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
path = GetAbsolutePath(scratch, path);
|
path = GetAbsolutePath(scratch, path);
|
||||||
|
|||||||
12
src/text_editor/notes_windows_paths
Normal file
12
src/text_editor/notes_windows_paths
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
absolute path C:/notes
|
||||||
|
lower case c:/notes
|
||||||
|
backwards slash C:\
|
||||||
|
go back ../notes
|
||||||
|
current dir ./notes
|
||||||
|
file without slash notes
|
||||||
|
allows spaces C:\thing and
|
||||||
|
multiple slashes C:\\\\\\\\\\\\\\\\\\\\\\\\\thing
|
||||||
|
you can combine the slashes C:\/Work
|
||||||
|
disallowed characters for names * \ / ? > < | : "
|
||||||
|
|
||||||
|
There is literally no way to consistently skip the windows path, you always have to relay on heuristics
|
||||||
@@ -111,6 +111,12 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
Caret caret = last_view->carets[0];
|
Caret caret = last_view->carets[0];
|
||||||
XY xy = PosToXY(*last_buffer, GetFront(caret));
|
XY xy = PosToXY(*last_buffer, GetFront(caret));
|
||||||
|
|
||||||
|
Array<Caret> caret_copy = Copy(GetSystemAllocator(), view->carets);
|
||||||
|
defer {
|
||||||
|
Dealloc(&view->carets);
|
||||||
|
view->carets = caret_copy;
|
||||||
|
};
|
||||||
|
|
||||||
String16 buffer_string = GetString(*buffer);
|
String16 buffer_string = GetString(*buffer);
|
||||||
Range replace_range = {0, buffer->len};
|
Range replace_range = {0, buffer->len};
|
||||||
if (!Seek(buffer_string, L" |", &replace_range.max)) {
|
if (!Seek(buffer_string, L" |", &replace_range.max)) {
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
||||||
- try using git grep for search for now, combine with fuzzy search buffer
|
- try using git grep for search for now, combine with fuzzy search buffer
|
||||||
- need to rewrite the path matching in lua
|
- need to rewrite the path matching in lua
|
||||||
|
- I think clipboard adds \r\n, let's execute the conversion on that
|
||||||
|
- prevent lua from infinite looping
|
||||||
|
- Append to console and change console directory
|
||||||
|
- c'git grep'
|
||||||
|
- EncloseExecWord should enclose the string also (add limitation)
|
||||||
|
- hotkey to select window title
|
||||||
|
- change colors of underline for caret or cursor
|
||||||
|
|
||||||
- search as a command to execute which is going to be in the title bar
|
- search as a command to execute which is going to be in the title bar
|
||||||
- search backwards
|
- search backwards
|
||||||
|
|||||||
Reference in New Issue
Block a user