Improved git pathing

This commit is contained in:
Krzosa Karol
2024-08-09 15:01:15 +02:00
parent 00c1f405c6
commit d98086d869
7 changed files with 130 additions and 277 deletions

View File

@@ -225,68 +225,54 @@ function SkipLineAndColumn(s)
return line, col, s
end
function ChopLineAndColumn(s)
local line = 1
local col = 1
local function SkipSlashes(s)
found_slash = false
while s:sub(1,1) == '/' or s:sub(1,1) == '\\' do
s = s:sub(2)
found_slash = true
end
return s, found_slash
end
-- filename:line:column
local lci, lcj = s:find(":%d+:%d+$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -1)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find(":%d+$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -1)
s = s:sub(1, li - 1)
return line, col, s
end
local function SkipDrive(s)
local i, j = s:find("^%a:")
if not i then return s, nil, true end
local drive = s:sub(i, j)
local new_s = s:sub(j + 1)
new_s, found_slash = SkipSlashes(new_s)
if not found_slash then return s, drive, false end
return new_s, drive, true
end
local function SkipPathCell(s)
local i, j = s:find("^[%w_%.-% +]+")
if not i then return s, nil, false end
local word = s:sub(i, j)
local new_s = s:sub(j + 1)
local new_s, found_slash = SkipSlashes(new_s)
return new_s, word, found_slash
end
local function SkipPath(s)
local input_s = s
local s, drive, ok = SkipDrive(s)
if not ok then return s end
local cells = {}
while true do
s, word, slash_eaten = SkipPathCell(s)
if word then cells[#cells + 1] = word end
if not slash_eaten then break end
end
-- filename(line,col):
local lci, lcj = s:find("%(%d+,%d+%):$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -3)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find("%(%d+%):$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -3)
s = s:sub(1, li - 1)
return line, col, s
end
end
-- filename(line,col)
local lci, lcj = s:find("%(%d+,%d+%)$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -2)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find("%(%d+%)$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -2)
s = s:sub(1, li - 1)
return line, col, s
end
end
return 1, 1, s
local skip_size = input_s:len() - s:len()
local path = input_s:sub(1, skip_size)
return s, path, drive, cells
end
function BufferNameExists(name)
@@ -300,76 +286,16 @@ function BufferNameExists(name)
return false
end
function ChopColon(s)
if s:sub(-1) == ':' then
s = s:sub(1, -2)
function MatchWindowsPath(_s)
local s, file_path, drive = SkipPath(_s)
if not drive then
local d = GetCurrentBufferDir()
file_path = d..'/'..file_path
end
return s
end
local line, col, s = SkipLineAndColumn(s)
function GenericTextFileRule(_s)
function match_path(s)
-- ./something
-- add working directory
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
if working_dir_j then
result = s:sub(3)
result = GetCurrentBufferDir().."/"..result
return result
end
-- C:/something
local abs_i, abs_j = string.find(s, "^%a:/.+")
if abs_i then
return s
end
-- C:\something
local abs_i, abs_j = s:find("^%a:\\.+")
if abs_i then
s = s:gsub("\\", "/")
return s
end
-- /mnt/something
local abs_i, abs_j = s:find("^/.*")
if abs_i then
return s
end
if BufferNameExists(s) then
return s
end
-- other_random_filename
buffer_dir = GetCurrentBufferDir()
if buffer_dir:len() == 0 then
return s
else
return buffer_dir..'/'..s
end
end
_s = ChopColon(_s)
line, col, _s = ChopLineAndColumn(_s)
file_path = match_path(_s)
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchAgainstIncludes(s)
line, col, s = ChopLineAndColumn(s)
include_paths = {
"C:/Work/text_editor/src",
"C:/Work/text_editor/src/text_editor",
}
for i = 1,#include_paths do
file_path = include_paths[i] .. '/' .. s
if FileExists(file_path) then
return {kind = "text", file_path = file_path, line = line, col = col}
end
end
return nil
print("OPEN :: INPUT = ".._s.." KIND = ".."text".." ".."FILE_PATH = "..file_path.."["..line..","..col.."]")
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchGitCommit(s)
@@ -383,8 +309,7 @@ function MatchGitCommit(s)
end
Rules = {
GenericTextFileRule,
MatchAgainstIncludes,
MatchWindowsPath,
MatchGitCommit,
}
@@ -399,6 +324,7 @@ function ApplyRules(s)
return nil
end
)==";
void GenerateConfig() {

View File

@@ -114,68 +114,54 @@ function SkipLineAndColumn(s)
return line, col, s
end
function ChopLineAndColumn(s)
local line = 1
local col = 1
local function SkipSlashes(s)
found_slash = false
while s:sub(1,1) == '/' or s:sub(1,1) == '\\' do
s = s:sub(2)
found_slash = true
end
return s, found_slash
end
-- filename:line:column
local lci, lcj = s:find(":%d+:%d+$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -1)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find(":%d+$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -1)
s = s:sub(1, li - 1)
return line, col, s
end
local function SkipDrive(s)
local i, j = s:find("^%a:")
if not i then return s, nil, true end
local drive = s:sub(i, j)
local new_s = s:sub(j + 1)
new_s, found_slash = SkipSlashes(new_s)
if not found_slash then return s, drive, false end
return new_s, drive, true
end
local function SkipPathCell(s)
local i, j = s:find("^[%w_%.-% +]+")
if not i then return s, nil, false end
local word = s:sub(i, j)
local new_s = s:sub(j + 1)
local new_s, found_slash = SkipSlashes(new_s)
return new_s, word, found_slash
end
local function SkipPath(s)
local input_s = s
local s, drive, ok = SkipDrive(s)
if not ok then return s end
local cells = {}
while true do
s, word, slash_eaten = SkipPathCell(s)
if word then cells[#cells + 1] = word end
if not slash_eaten then break end
end
-- filename(line,col):
local lci, lcj = s:find("%(%d+,%d+%):$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -3)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find("%(%d+%):$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -3)
s = s:sub(1, li - 1)
return line, col, s
end
end
-- filename(line,col)
local lci, lcj = s:find("%(%d+,%d+%)$")
if lci then
local line_and_col = s:sub(lci, lcj)
local i, j = line_and_col:find("%d+")
line = line_and_col:sub(i, j)
col = line_and_col:sub(j + 2, -2)
s = s:sub(1, lci - 1)
return line, col, s
else
local li, lj = s:find("%(%d+%)$")
if li then
local line_string = s:sub(li, lj)
line = line_string:sub(2, -2)
s = s:sub(1, li - 1)
return line, col, s
end
end
return 1, 1, s
local skip_size = input_s:len() - s:len()
local path = input_s:sub(1, skip_size)
return s, path, drive, cells
end
function BufferNameExists(name)
@@ -189,76 +175,16 @@ function BufferNameExists(name)
return false
end
function ChopColon(s)
if s:sub(-1) == ':' then
s = s:sub(1, -2)
function MatchWindowsPath(_s)
local s, file_path, drive = SkipPath(_s)
if not drive then
local d = GetCurrentBufferDir()
file_path = d..'/'..file_path
end
return s
end
local line, col, s = SkipLineAndColumn(s)
function GenericTextFileRule(_s)
function match_path(s)
-- ./something
-- add working directory
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
if working_dir_j then
result = s:sub(3)
result = GetCurrentBufferDir().."/"..result
return result
end
-- C:/something
local abs_i, abs_j = string.find(s, "^%a:/.+")
if abs_i then
return s
end
-- C:\something
local abs_i, abs_j = s:find("^%a:\\.+")
if abs_i then
s = s:gsub("\\", "/")
return s
end
-- /mnt/something
local abs_i, abs_j = s:find("^/.*")
if abs_i then
return s
end
if BufferNameExists(s) then
return s
end
-- other_random_filename
buffer_dir = GetCurrentBufferDir()
if buffer_dir:len() == 0 then
return s
else
return buffer_dir..'/'..s
end
end
_s = ChopColon(_s)
line, col, _s = ChopLineAndColumn(_s)
file_path = match_path(_s)
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchAgainstIncludes(s)
line, col, s = ChopLineAndColumn(s)
include_paths = {
"C:/Work/text_editor/src",
"C:/Work/text_editor/src/text_editor",
}
for i = 1,#include_paths do
file_path = include_paths[i] .. '/' .. s
if FileExists(file_path) then
return {kind = "text", file_path = file_path, line = line, col = col}
end
end
return nil
print("OPEN :: INPUT = ".._s.." KIND = ".."text".." ".."FILE_PATH = "..file_path.."["..line..","..col.."]")
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchGitCommit(s)
@@ -272,8 +198,7 @@ function MatchGitCommit(s)
end
Rules = {
GenericTextFileRule,
MatchAgainstIncludes,
MatchWindowsPath,
MatchGitCommit,
}
@@ -289,6 +214,7 @@ function ApplyRules(s)
end
)==";
void ReloadStyle() {
ColorText = GetColor("Text", ColorText);

View File

@@ -138,7 +138,7 @@ int LuaListBuffers(lua_State *L) {
Scratch scratch;
Array<String> strings = {scratch};
For(Buffers) {
if (StartsWith(it.name, "*infobar")) continue;
if (StartsWith(it.name, "+Titlebar")) continue;
String string = Format(scratch, "%.*s", FmtString(it.name));
Add(&strings, string);
}
@@ -159,7 +159,7 @@ int LuaGetBufferList(lua_State *L) {
int i = 1;
For(Buffers) {
if (StartsWith(it.name, "*infobar")) continue;
if (StartsWith(it.name, "+Titlebar")) continue;
lua_pushinteger(L, i++);
lua_pushlstring(L, it.name.data, it.name.len);
lua_settable(L, -3); /* 3rd element from the stack top */

View File

@@ -10,7 +10,6 @@ WindowID NullWindowID;
BufferID NullBufferID;
ViewID NullViewID;
WindowID CommandWindowID;
WindowID InfoBarWindowID;
WindowID SearchWindowID;
WindowID PopupWindowID;
WindowID DebugWindowID;

View File

@@ -4,7 +4,7 @@ backwards slash C:\
go back ../notes
current dir ./notes
file without slash notes
allows spaces C:\thing and
allows spaces C:\Program Files/
multiple slashes C:\\\\\\\\\\\\\\\\\\\\\\\\\thing
you can combine the slashes C:\/Work
disallowed characters for names * \ / ? > < | : "

View File

@@ -1,4 +1,3 @@
- jump history forward
- Remove pointers and use ViewIDs (enable array debug while doing this)
- try using git grep for search for now, combine with fuzzy search buffer
- lua maybe try heuristic matching paths from left?
@@ -8,6 +7,10 @@
- some split selection commands
- assign commands or lua functions to F1-F8 keys
- Cycle up and down through a list of filenames and jump to every filename listed
- A lister which is going to show project without the full path and sorted by recency
- Fix fuzzy search look
- word complete
- Search all buffers in 10X style, incrementally searched results popping up on every key press (maybe we need coroutine library in C so this is easier?)
- Search and replace
@@ -31,7 +34,6 @@
- combine glyph and selection rendering
Windows
- better teminology then 'active' 'last active' 'current'
- switch to previous view (ctrl + tab)

View File

@@ -45,9 +45,9 @@ Window *CreateTitlebar(WindowID parent_window_id) {
window->deactivate_on_escape = true;
window->is_title_bar = true;
static int InfobarCount;
static int TitlebarCount;
Allocator sys_allocator = GetSystemAllocator();
String name = Format(sys_allocator, "*infobar%d", ++InfobarCount);
String name = Format(sys_allocator, "+Titlebar%d", ++TitlebarCount);
Buffer *b = CreateBuffer(sys_allocator, name);
View *v = CreateView(b->id);
@@ -73,7 +73,7 @@ Int GetTitleBarSize(Window *window) {
void AddColumnWindow() {
Window *window = CreateWindow();
window->is_column = true;
View *view = OpenBufferView("*scratch*");
View *view = OpenBufferView("+Scratch");
window->active_view = view->id;
CreateTitlebar(window->id);
}
@@ -82,7 +82,7 @@ void AddRowWindow() {
Window *window = CreateWindow();
WindowID window_id = window->id;
View *view = OpenBufferView("*scratch*");
View *view = OpenBufferView("+Scratch");
window->active_view = view->id;
CreateTitlebar(window->id);
@@ -121,7 +121,7 @@ String BuffCWD(String string) {
void InitScratchBuffer() {
Allocator sys_allocator = GetSystemAllocator();
Buffer *null_buffer = CreateBuffer(sys_allocator, BuffCWD("*scratch*"));
Buffer *null_buffer = CreateBuffer(sys_allocator, BuffCWD("+Scratch"));
View *null_view = CreateView(null_buffer->id);
}
@@ -138,7 +138,7 @@ void InitWindows() {
WindowID window_id = window->id;
window->is_column = true;
// window->draw_line_numbers = false;
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("*load_text_a*"));
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+TestBuffer"));
View *view = CreateView(buffer->id);
// LoadTextA(buffer);
LoadUnicode(buffer);
@@ -157,7 +157,7 @@ void InitWindows() {
window->absolute_position = true;
window->dont_save_in_active_window_history = true;
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("*console*"));
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+Console"));
// buffer->no_history = true;
View *view = CreateView(buffer->id);
@@ -180,7 +180,7 @@ void InitWindows() {
window->visible = false;
window->z = 2;
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("*debug*"));
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+Debug"));
DebugBufferID = buffer->id;
buffer->no_history = true;
@@ -203,7 +203,7 @@ void InitWindows() {
w->absolute_position = true;
w->dont_save_in_active_window_history = true;
w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("*commands*"));
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("+Commands"));
View *v = CreateView(b->id);
v->fuzzy_search = true;
@@ -227,7 +227,7 @@ void InitWindows() {
w->dont_save_in_active_window_history = true;
w->invisible_when_inactive = true;
w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("*search*"));
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("+Search"));
View *v = CreateView(b->id);
w->active_view = v->id;
@@ -250,13 +250,13 @@ void InitWindows() {
w->absolute_position = true;
w->deactivate_on_escape = true;
w->z = 2;
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("*popup*"));
Buffer *b = CreateBuffer(sys_allocator, BuffCWD("+Popup"));
b->no_history = true;
View *v = CreateView(b->id);
w->active_view = v->id;
Window *infobar = CreateTitlebar(window_id);
infobar->z = 2;
Window *titlebar = CreateTitlebar(window_id);
titlebar->z = 2;
SetVisibility(window_id, false);
}