mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
REPL: Outdent when the user types '}'.
Swift SVN r3975
This commit is contained in:
@@ -218,6 +218,7 @@ struct EditLineWrapper {
|
|||||||
bool NeedPromptContinuation;
|
bool NeedPromptContinuation;
|
||||||
bool ShowColors;
|
bool ShowColors;
|
||||||
bool PromptedForLine;
|
bool PromptedForLine;
|
||||||
|
bool Outdented;
|
||||||
|
|
||||||
llvm::SmallString<80> PromptString;
|
llvm::SmallString<80> PromptString;
|
||||||
|
|
||||||
@@ -234,6 +235,9 @@ struct EditLineWrapper {
|
|||||||
el_set(e, EL_CLIENTDATA, (void*)this);
|
el_set(e, EL_CLIENTDATA, (void*)this);
|
||||||
el_set(e, EL_HIST, history, h);
|
el_set(e, EL_HIST, history, h);
|
||||||
el_set(e, EL_SIGNAL, 1);
|
el_set(e, EL_SIGNAL, 1);
|
||||||
|
el_set(e, EL_ADDFN, "swift-close-brace", "Reduce {} indentation level",
|
||||||
|
CloseBraceFn);
|
||||||
|
el_set(e, EL_BIND, "}", "swift-close-brace", NULL);
|
||||||
HistEvent ev;
|
HistEvent ev;
|
||||||
history(h, &ev, H_SETSIZE, 800);
|
history(h, &ev, H_SETSIZE, 800);
|
||||||
}
|
}
|
||||||
@@ -270,6 +274,26 @@ struct EditLineWrapper {
|
|||||||
PromptedForLine = true;
|
PromptedForLine = true;
|
||||||
return PromptString.c_str();
|
return PromptString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned char CloseBraceFn(EditLine *e, int ch) {
|
||||||
|
void *clientdata;
|
||||||
|
el_get(e, EL_CLIENTDATA, &clientdata);
|
||||||
|
return ((EditLineWrapper*)clientdata)->onCloseBrace(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char onCloseBrace(int ch) {
|
||||||
|
// Add the character to the string.
|
||||||
|
char s[2] = {(char)ch, 0};
|
||||||
|
el_insertstr(e, s);
|
||||||
|
|
||||||
|
// If we didn't already outdent, do so.
|
||||||
|
if (!Outdented) {
|
||||||
|
if (PromptContinuationLevel > 0)
|
||||||
|
--PromptContinuationLevel;
|
||||||
|
Outdented = true;
|
||||||
|
}
|
||||||
|
return CC_REFRESH;
|
||||||
|
}
|
||||||
|
|
||||||
~EditLineWrapper() {
|
~EditLineWrapper() {
|
||||||
el_end(e);
|
el_end(e);
|
||||||
@@ -363,6 +387,7 @@ void swift::REPL(ASTContext &Context) {
|
|||||||
e.PromptContinuationLevel = BraceCount;
|
e.PromptContinuationLevel = BraceCount;
|
||||||
e.NeedPromptContinuation = BraceCount != 0 || HadLineContinuation;
|
e.NeedPromptContinuation = BraceCount != 0 || HadLineContinuation;
|
||||||
e.PromptedForLine = false;
|
e.PromptedForLine = false;
|
||||||
|
e.Outdented = false;
|
||||||
int LineCount;
|
int LineCount;
|
||||||
const char* Line = el_gets(e, &LineCount);
|
const char* Line = el_gets(e, &LineCount);
|
||||||
if (!Line) {
|
if (!Line) {
|
||||||
|
|||||||
Reference in New Issue
Block a user