Exec word now tries to extend the lua function call syntax
This commit is contained in:
@@ -440,21 +440,50 @@ Range EncloseLoadWord(Buffer *buffer, Int pos) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Range EncloseExecWord(Buffer *buffer, Int pos) {
|
Int SkipSpaces(Buffer *buffer, Int seek) {
|
||||||
Range result = {GetExecWordStart(buffer, pos), GetExecWordEnd(buffer, pos)};
|
for (; seek < buffer->len; seek += 1) {
|
||||||
return result;
|
wchar_t c = GetChar(buffer, seek);
|
||||||
|
if (c != L' ') break;
|
||||||
|
}
|
||||||
|
return seek;
|
||||||
}
|
}
|
||||||
|
|
||||||
Range TrimButtonChars(Buffer *buffer, Range range) {
|
Int FindScopeEnd(Buffer *buffer, Int seek, Int max_seek, wchar_t open, wchar_t close) {
|
||||||
bool left0 = range.min < range.max && range.min + 1 < range.max;
|
wchar_t right = GetChar(buffer, seek);
|
||||||
bool left1 = GetChar(buffer, range.min) == L'|' && GetChar(buffer, range.min + 1) == L'>';
|
if (right == open) {
|
||||||
if (left0 && left1) range.min += 2;
|
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;
|
if (open == close && c == '\\') {
|
||||||
bool right1 = GetChar(buffer, range.max - 2) == L'<' && GetChar(buffer, range.max - 1) == L'|';
|
i += 1;
|
||||||
if (right0 && right1) range.max -= 2;
|
} 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) {
|
Range EncloseLine(Buffer *buffer, Int pos) {
|
||||||
|
|||||||
@@ -270,7 +270,6 @@ bool GlobalCommand(Event event) {
|
|||||||
if (InBounds(view->carets[0].range, p)) {
|
if (InBounds(view->carets[0].range, p)) {
|
||||||
enclose = view->carets[0].range;
|
enclose = view->carets[0].range;
|
||||||
}
|
}
|
||||||
enclose = TrimButtonChars(buffer, enclose);
|
|
||||||
String16 string = GetString(*buffer, enclose);
|
String16 string = GetString(*buffer, enclose);
|
||||||
Command_EvalLua(view, string);
|
Command_EvalLua(view, string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -900,7 +900,6 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) {
|
if (GetSize(caret.range) == 0) {
|
||||||
range = EncloseExecWord(buffer, GetFront(caret));
|
range = EncloseExecWord(buffer, GetFront(caret));
|
||||||
range = TrimButtonChars(buffer, range);
|
|
||||||
}
|
}
|
||||||
String16 string = GetString(*buffer, range);
|
String16 string = GetString(*buffer, range);
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
- 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
|
||||||
|
|||||||
Reference in New Issue
Block a user