EvalCommandsLineByLine
This commit is contained in:
@@ -474,6 +474,16 @@ String16 SkipIdent(String16 *string) {
|
|||||||
return begin;
|
return begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MatchIdent(String16 *string, String16 expect) {
|
||||||
|
String16 copy = *string;
|
||||||
|
String16 ident = SkipIdent(©);
|
||||||
|
if (ident == expect) {
|
||||||
|
*string = copy;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
API bool Chop(String16 *string, String16 ending) {
|
API bool Chop(String16 *string, String16 ending) {
|
||||||
if (EndsWith(*string, ending)) {
|
if (EndsWith(*string, ending)) {
|
||||||
*string = Chop(*string, ending.len);
|
*string = Chop(*string, ending.len);
|
||||||
|
|||||||
@@ -1245,15 +1245,20 @@ void Command_ClearCarets() {
|
|||||||
}
|
}
|
||||||
} RegisterCommand(Command_ClearCarets, "escape");
|
} RegisterCommand(Command_ClearCarets, "escape");
|
||||||
|
|
||||||
void Command_Set() {
|
void Set(String16 string) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet set = GetBSet(ActiveWindowID);
|
|
||||||
Range range = set.view->carets[0].range;
|
SkipWhitespace(&string);
|
||||||
if (GetSize(range) == 0) {
|
if (At(string, 0) != u':') {
|
||||||
range = EncloseLoadWord(set.buffer, range.min);
|
ReportErrorf("Expected :Set");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string = Skip(string, 1);
|
||||||
|
|
||||||
|
if (!MatchIdent(&string, u"Set")) {
|
||||||
|
ReportErrorf("Expected :Set");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
Int line_end = GetLineEnd(set.buffer, range.min);
|
|
||||||
String16 string = GetString(set.buffer, {range.max, line_end});
|
|
||||||
|
|
||||||
SkipWhitespace(&string);
|
SkipWhitespace(&string);
|
||||||
String16 name = SkipIdent(&string);
|
String16 name = SkipIdent(&string);
|
||||||
@@ -1346,6 +1351,29 @@ void Command_Set() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReportErrorf("Failed to :Set, no such variable found: %S", name8);
|
ReportErrorf("Failed to :Set, no such variable found: %S", name8);
|
||||||
} RegisterCommand(Command_Set, "");
|
}
|
||||||
|
|
||||||
|
void Command_Set() {
|
||||||
|
BSet set = GetBSet(ActiveWindowID);
|
||||||
|
Range range = set.view->carets[0].range;
|
||||||
|
if (GetSize(range) == 0) {
|
||||||
|
range = EncloseLoadWord(set.buffer, range.min);
|
||||||
|
}
|
||||||
|
Int line_end = GetLineEnd(set.buffer, range.min);
|
||||||
|
|
||||||
|
String16 string = GetString(set.buffer, {range.min, line_end});
|
||||||
|
Set(string);
|
||||||
|
} RegisterCommand(Command_Set, "");
|
||||||
|
|
||||||
|
void EvalCommandsLineByLine(Buffer *buffer) {
|
||||||
|
for (Int i = 0; i < buffer->line_starts.len; i += 1) {
|
||||||
|
String16 istr = GetLineString(buffer, i);
|
||||||
|
EvalCommand(istr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_EvalCommandsLineByLine() {
|
||||||
|
BSet set = GetBSet(LastActiveLayoutWindowID);
|
||||||
|
EvalCommandsLineByLine(set.buffer);
|
||||||
|
} RegisterCommand(Command_EvalCommandsLineByLine, "");
|
||||||
Reference in New Issue
Block a user