Exec word now tries to extend the lua function call syntax

This commit is contained in:
Krzosa Karol
2024-08-09 07:24:29 +02:00
parent 4c179e3965
commit a7dc343fd6
4 changed files with 41 additions and 13 deletions

View File

@@ -440,21 +440,50 @@ Range EncloseLoadWord(Buffer *buffer, Int pos) {
return result;
}
Range EncloseExecWord(Buffer *buffer, Int pos) {
Range result = {GetExecWordStart(buffer, pos), GetExecWordEnd(buffer, pos)};
return result;
Int SkipSpaces(Buffer *buffer, Int seek) {
for (; seek < buffer->len; seek += 1) {
wchar_t c = GetChar(buffer, seek);
if (c != L' ') break;
}
return seek;
}
Range TrimButtonChars(Buffer *buffer, Range range) {
bool left0 = range.min < range.max && range.min + 1 < range.max;
bool left1 = GetChar(buffer, range.min) == L'|' && GetChar(buffer, range.min + 1) == L'>';
if (left0 && left1) range.min += 2;
Int FindScopeEnd(Buffer *buffer, Int seek, Int max_seek, wchar_t open, wchar_t close) {
wchar_t right = GetChar(buffer, seek);
if (right == open) {
int scope = 1;
Int i = seek + 1;
for (; i < seek + max_seek && i < buffer->len; i += 1) {
wchar_t c = GetChar(buffer, i);
bool right0 = range.max - 2 >= range.min && range.max - 1 >= range.min;
bool right1 = GetChar(buffer, range.max - 2) == L'<' && GetChar(buffer, range.max - 1) == L'|';
if (right0 && right1) range.max -= 2;
if (open == close && c == '\\') {
i += 1;
} else if (open == close && c == open) {
scope -= 1;
} else if (c == open) {
scope += 1;
} else if (c == close) {
scope -= 1;
}
return range;
if (c == L'\n' || scope == 0) break;
}
if (scope == 0) seek = i;
}
return seek;
}
Range EncloseExecWord(Buffer *buffer, Int pos) {
Range result = {GetWordStart(buffer, pos), GetWordEnd(buffer, pos)};
Int seek = SkipSpaces(buffer, result.max);
Int scope_end = FindScopeEnd(buffer, seek, 1024, L'(', L')');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'{', L'}');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'\'', L'\'');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'\"', L'\"');
if (seek != scope_end) result.max = scope_end + 1;
return result;
}
Range EncloseLine(Buffer *buffer, Int pos) {

View File

@@ -270,7 +270,6 @@ bool GlobalCommand(Event event) {
if (InBounds(view->carets[0].range, p)) {
enclose = view->carets[0].range;
}
enclose = TrimButtonChars(buffer, enclose);
String16 string = GetString(*buffer, enclose);
Command_EvalLua(view, string);
}

View File

@@ -900,7 +900,6 @@ void WindowCommand(Event event, Window *window, View *view) {
Range range = caret.range;
if (GetSize(caret.range) == 0) {
range = EncloseExecWord(buffer, GetFront(caret));
range = TrimButtonChars(buffer, range);
}
String16 string = GetString(*buffer, range);

View File

@@ -1,3 +1,4 @@
- Exec word should try to match lua function calls (first match word, then expand selection right)
- 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