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"==(
|
||||
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 col = 1
|
||||
|
||||
@@ -237,7 +286,7 @@ function ExtractLineAndColumn(s)
|
||||
end
|
||||
end
|
||||
|
||||
return -1, -1, s
|
||||
return 1, 1, s
|
||||
end
|
||||
|
||||
function BufferNameExists(name)
|
||||
@@ -251,6 +300,13 @@ function BufferNameExists(name)
|
||||
return false
|
||||
end
|
||||
|
||||
function ChopColon(s)
|
||||
if s:sub(-1) == ':' then
|
||||
s = s:sub(1, -2)
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
function GenericTextFileRule(_s)
|
||||
function match_path(s)
|
||||
-- ./something
|
||||
@@ -258,7 +314,7 @@ function GenericTextFileRule(_s)
|
||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||
if working_dir_j then
|
||||
result = s:sub(3)
|
||||
result = GetWorkingDir().."/"..result
|
||||
result = GetCurrentBufferDir().."/"..result
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -294,13 +350,14 @@ function GenericTextFileRule(_s)
|
||||
end
|
||||
end
|
||||
|
||||
line, col, _s = ExtractLineAndColumn(_s)
|
||||
line, col, _s = ChopLineAndColumn(_s)
|
||||
_s = ChopColon(_s)
|
||||
file_path = match_path(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchAgainstIncludes(s)
|
||||
line, col, s = ExtractLineAndColumn(s)
|
||||
line, col, s = ChopLineAndColumn(s)
|
||||
include_paths = {
|
||||
"C:/Work/text_editor/src",
|
||||
"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));
|
||||
String16 string = GetString(*buffer, range);
|
||||
|
||||
if (GetChar(string, 0) == L'!') {
|
||||
string = Skip(string, 1);
|
||||
Exec(ConsoleViewID, true, string, GetCurrentBufferDir());
|
||||
} else {
|
||||
Command_EvalLua(view, string);
|
||||
}
|
||||
|
||||
// Exec(string, GetCurrentBufferDir());
|
||||
Command_EvalLua(view, string);
|
||||
}
|
||||
|
||||
if (Ctrl(SDLK_W)) {
|
||||
|
||||
@@ -63,7 +63,56 @@ Style.FontSize = 12
|
||||
Style.FontFilter = 0
|
||||
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 col = 1
|
||||
|
||||
@@ -124,7 +173,7 @@ function ExtractLineAndColumn(s)
|
||||
end
|
||||
end
|
||||
|
||||
return -1, -1, s
|
||||
return 1, 1, s
|
||||
end
|
||||
|
||||
function BufferNameExists(name)
|
||||
@@ -138,6 +187,13 @@ function BufferNameExists(name)
|
||||
return false
|
||||
end
|
||||
|
||||
function ChopColon(s)
|
||||
if s:sub(-1) == ':' then
|
||||
s = s:sub(1, -2)
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
function GenericTextFileRule(_s)
|
||||
function match_path(s)
|
||||
-- ./something
|
||||
@@ -145,7 +201,7 @@ function GenericTextFileRule(_s)
|
||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||
if working_dir_j then
|
||||
result = s:sub(3)
|
||||
result = GetWorkingDir().."/"..result
|
||||
result = GetCurrentBufferDir().."/"..result
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -181,13 +237,14 @@ function GenericTextFileRule(_s)
|
||||
end
|
||||
end
|
||||
|
||||
line, col, _s = ExtractLineAndColumn(_s)
|
||||
line, col, _s = ChopLineAndColumn(_s)
|
||||
_s = ChopColon(_s)
|
||||
file_path = match_path(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchAgainstIncludes(s)
|
||||
line, col, s = ExtractLineAndColumn(s)
|
||||
line, col, s = ChopLineAndColumn(s)
|
||||
include_paths = {
|
||||
"C:/Work/text_editor/src",
|
||||
"C:/Work/text_editor/src/text_editor",
|
||||
|
||||
@@ -35,6 +35,18 @@ String GetUniqueBufferName(Allocator allocator, String working_dir, String p
|
||||
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) {
|
||||
Scratch scratch;
|
||||
|
||||
@@ -67,15 +79,7 @@ void Open(String path) {
|
||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
String buffer_name = GetUniqueBufferName(scratch, working_dir, "+CMD");
|
||||
|
||||
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);
|
||||
ExecInNewBuffer(cmd, working_dir);
|
||||
} else {
|
||||
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||
}
|
||||
@@ -87,6 +91,15 @@ void Open(String16 path) {
|
||||
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) {
|
||||
Window *window = GetCurrentWindow();
|
||||
KillProcess(window->active_view);
|
||||
@@ -182,6 +195,7 @@ luaL_Reg LuaFunctions[] = {
|
||||
{ "print", LuaPrint},
|
||||
{ "Print", LuaPrint},
|
||||
{ "Kill", LuaKill},
|
||||
{ "c", LuaExec},
|
||||
{ NULL, NULL},
|
||||
};
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ Buffer *BufferOpenFile(String path) {
|
||||
buffer->is_directory = true;
|
||||
|
||||
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 {
|
||||
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];
|
||||
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);
|
||||
Range replace_range = {0, buffer->len};
|
||||
if (!Seek(buffer_string, L" |", &replace_range.max)) {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
||||
- try using git grep for search for now, combine with fuzzy search buffer
|
||||
- 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 backwards
|
||||
|
||||
Reference in New Issue
Block a user