Compare commits

..

7 Commits

Author SHA1 Message Date
Krzosa Karol
59081eb4bd ReloadFont when variables change 2025-12-31 15:25:00 +01:00
Krzosa Karol
a40797abb2 Config files 2025-12-31 13:47:15 +01:00
Krzosa Karol
6c0a4d0633 Command_ to CMD_ 2025-12-31 12:46:52 +01:00
Krzosa Karol
edafe05b5b EvalCommandsLineByLine 2025-12-31 12:45:28 +01:00
Krzosa Karol
b40873d54c :Set command 2025-12-31 11:50:21 +01:00
Krzosa Karol
0921054b6e Fix view centering 2025-12-31 10:34:11 +01:00
Krzosa Karol
f8f9e33032 Directory fuzzy search and fix C: not opening 2025-12-31 08:27:22 +01:00
23 changed files with 561 additions and 316 deletions

View File

@@ -21,9 +21,5 @@ set flags=/EHsc- /MD /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column
set libs=%sdllib%/SDL3-static.lib %sdllib%/SDL_uclibc.lib kernel32.lib gdi32.lib user32.lib Imm32.lib ole32.lib Shell32.lib OleAut32.lib Cfgmgr32.lib Setupapi.lib Advapi32.lib version.lib winmm.lib set libs=%sdllib%/SDL3-static.lib %sdllib%/SDL_uclibc.lib kernel32.lib gdi32.lib user32.lib Imm32.lib ole32.lib Shell32.lib OleAut32.lib Cfgmgr32.lib Setupapi.lib Advapi32.lib version.lib winmm.lib
cl %flags% ../src/text_editor/text_editor.cpp -Fe:te.exe -I%sdl%/include -I../src/external/glad -I../src/ %libs% -link /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:MSVCRTD cl %flags% ../src/text_editor/text_editor.cpp -Fe:te.exe -I%sdl%/include -I../src/external/glad -I../src/ %libs% -link /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:MSVCRTD
copy te.exe ..\data\te.exe
copy te.pdb ..\data\te.pdb
echo written ..\data\te.exe
popd popd
rem /fsanitize=address rem /fsanitize=address

View File

@@ -9,6 +9,5 @@ FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=ad
I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad" I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad"
clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace
cp te ../data/te
# -v -Wl,--verbose # -v -Wl,--verbose

View File

@@ -1,42 +0,0 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
<title>Emscripten-Generated Code</title>
<style>
body { margin: 0; background-color: black }
.game {
position: absolute;
top: 0px;
left: 0px;
margin: 0px;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
display: block;
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: crisp-edges;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
</style>
</head>
<body>
<canvas class="game" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type='text/javascript'>
var Module = {
preRun: [],
print: (...args) => console.log('[stdout]: ' + args.join(' ')),
printErr: (...args) => console.log('[stderr]: ' + args.join(' ')),
};
window.onerror = (event) => console.log('[onerror]: ' + event.message);
</script>
{{{ SCRIPT }}}
</body>
</html>

View File

@@ -1,10 +1,14 @@
! What precise workflow do I need for me to be viable to use this? ! What precise workflow do I need for me to be viable to use this?
! From a user (novice) point of view, how does it look like? ! From a user (novice) point of view, how does it look like?
- Make all the keybinding / hook parsing initialize at the start to reduce runtime problems
- RegisterCommand should_appear_in_listing variable
- Maybe one list for all variables including the commands etc?
- make variables nicer named
- Problem generating configs don't know which quotation marks would be good ....
Use session 3: Use session 3:
- Maybe status view, commit changes (like to buffer name or line) on enter? - Maybe status view, commit changes (like to buffer name or line) on enter?
- Search over buffer directory, close search, quick enter buffer? Not sure if line, more general purpose
How to go about search/replace, opening code and other considerations How to go about search/replace, opening code and other considerations
- We can use sed + find to search and replace, the automatic reopen should do the job - We can use sed + find to search and replace, the automatic reopen should do the job
@@ -16,7 +20,6 @@ How to go about search/replace, opening code and other considerations
Use session 2 Use session 2
- Need configs I can't change browser or vcvarsall currently, maybe syntax like :Set InternetBrowser "firefox" - Need configs I can't change browser or vcvarsall currently, maybe syntax like :Set InternetBrowser "firefox"
- Tutorial - Tutorial
- When jumping should center the view!!!
Debug session: Debug session:
- Report errorf - use coroutine dialogs - Report errorf - use coroutine dialogs
@@ -48,9 +51,6 @@ Commands TODO:
- Special: non editable, hotkeys don't work etc. - Special: non editable, hotkeys don't work etc.
backlog backlog
FEATURE Search whole words, case sensitive etc.
FEATURE Select all searched occurences
FEATURE commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
FEATURE Some decl/function indexing in fuzzy format FEATURE Some decl/function indexing in fuzzy format
ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky
FEATURE dump text editor state to file, restore state FEATURE dump text editor state to file, restore state

View File

@@ -378,7 +378,7 @@ API bool Chop(String *string, String ending) {
return false; return false;
} }
API String SkipNumberEx(String *string) { API String SkipIntEx(String *string) {
String col = {string->data, 0}; String col = {string->data, 0};
for (int64_t i = 0; i < string->len; i += 1) { for (int64_t i = 0; i < string->len; i += 1) {
if (IsDigit(string->data[i])) { if (IsDigit(string->data[i])) {
@@ -391,8 +391,8 @@ API String SkipNumberEx(String *string) {
return col; return col;
} }
API Int SkipNumber(String *string) { API Int SkipInt(String *string) {
String col = SkipNumberEx(string); String col = SkipIntEx(string);
if (col.len == 0) return -1; if (col.len == 0) return -1;
Int result = strtoll(col.data, NULL, 10); Int result = strtoll(col.data, NULL, 10);
return result; return result;

View File

@@ -38,6 +38,11 @@ API bool IsDigit(char16_t a) {
return result; return result;
} }
API bool IsHexDigit(char16_t a) {
bool result = a >= u'0' && a <= u'9' || a == 'a' || a == 'b' || a == 'c' || a == 'd' || a == 'e' || a == 'f';
return result;
}
API bool IsAlphanumeric(char16_t a) { API bool IsAlphanumeric(char16_t a) {
bool result = IsDigit(a) || IsAlphabetic(a); bool result = IsDigit(a) || IsAlphabetic(a);
return result; return result;
@@ -384,8 +389,12 @@ API Int GetSize(Array<String16> array) {
return result; return result;
} }
API String16 SkipNumberEx(String16 *string) { API String16 SkipIntEx(String16 *string) {
String16 col = {string->data, 0}; String16 col = {string->data, 0};
if (At(*string, 0) == '-') {
col.len += 1;
*string = Skip(*string, 1);
}
for (int64_t i = 0; i < string->len; i += 1) { for (int64_t i = 0; i < string->len; i += 1) {
if (IsDigit(string->data[i])) { if (IsDigit(string->data[i])) {
col.len += 1; col.len += 1;
@@ -397,15 +406,41 @@ API String16 SkipNumberEx(String16 *string) {
return col; return col;
} }
API Int SkipNumber(String16 *string) { API Int SkipInt(String16 *string) {
String16 col = SkipNumberEx(string); String16 col = SkipIntEx(string);
if (col.len == 0) return -1; if (col.len == 0) return 0;
Scratch scratch; Scratch scratch;
String num_string = ToString(scratch, col); String num_string = ToString(scratch, col);
Int result = strtoll(num_string.data, NULL, 10); Int result = strtoll(num_string.data, NULL, 10);
return result; return result;
} }
API String16 SkipFloatEx(String16 *string) {
String16 col = {string->data, 0};
if (At(*string, 0) == '-') {
col.len += 1;
*string = Skip(*string, 1);
}
for (int64_t i = 0; i < string->len; i += 1) {
if (IsDigit(string->data[i]) || string->data[i] == u'.') {
col.len += 1;
} else {
break;
}
}
*string = Skip(*string, col.len);
return col;
}
API Float SkipFloat(String16 *string) {
String16 col = SkipFloatEx(string);
if (col.len == 0) return 0;
Scratch scratch;
String num_string = ToString(scratch, col);
Float result = strtod(num_string.data, NULL);
return result;
}
API String16 SkipUntil(String16 *string, String16 str) { API String16 SkipUntil(String16 *string, String16 str) {
String16 begin = *string; String16 begin = *string;
begin.len = 0; begin.len = 0;
@@ -419,14 +454,41 @@ API String16 SkipUntil(String16 *string, String16 str) {
API String16 SkipWhitespace(String16 *string) { API String16 SkipWhitespace(String16 *string) {
String16 begin = {string->data, 0}; String16 begin = {string->data, 0};
for (Int i = 0; i < string->len; i += 1) { for (;string->len;) {
if (!IsWhitespace(string->data[i])) break; if (!IsWhitespace(At(*string, 0))) {
break;
}
*string = Skip(*string, 1); *string = Skip(*string, 1);
begin.len += 1; begin.len += 1;
} }
return begin; return begin;
} }
String16 SkipIdent(String16 *string) {
String16 begin = {string->data, 0};
if (IsIdent(At(*string, 0))) {
for (;string->len;) {
char16_t c = At(*string, 0);
if (!IsIdent(c) && !IsDigit(c)) {
break;
}
*string = Skip(*string, 1);
begin.len += 1;
}
}
return begin;
}
bool MatchIdent(String16 *string, String16 expect) {
String16 copy = *string;
String16 ident = SkipIdent(&copy);
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);

View File

@@ -81,8 +81,8 @@ API String16 CutPrefix(String16 *string, int64_t len);
API String16 CutPostfix(String16 *string, int64_t len); API String16 CutPostfix(String16 *string, int64_t len);
// @todo: think about this API, for parsing, maybe redesign or something // @todo: think about this API, for parsing, maybe redesign or something
API String16 SkipNumberEx(String16 *string); API String16 SkipIntEx(String16 *string);
API Int SkipNumber(String16 *string); API Int SkipInt(String16 *string);
API String16 SkipUntil(String16 *string, String16 str); API String16 SkipUntil(String16 *string, String16 str);
API String16 SkipWhitespace(String16 *string); API String16 SkipWhitespace(String16 *string);
API String16 ChopNumberEx(String16 *string); API String16 ChopNumberEx(String16 *string);

View File

@@ -150,7 +150,7 @@ void Test(mco_coro *co) {
} }
void InitTests() { void InitTests() {
ConfigWaitForEvents = false; WaitForEvents = false;
TestDir = Format(TestArena, "%S/test_env", GetExeDir(TestArena)); TestDir = Format(TestArena, "%S/test_env", GetExeDir(TestArena));
CoData *data = CoAdd(Test); CoData *data = CoAdd(Test);
data->dont_wait_until_resolved = true; data->dont_wait_until_resolved = true;

View File

@@ -895,7 +895,7 @@ API void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
if (buffer->redo_stack.len > 0) { if (buffer->redo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->redo_stack); HistoryEntry *next = GetLast(buffer->redo_stack);
if (next->time - entry.time <= ConfigUndoMergeTimeWindow) { if (next->time - entry.time <= UndoMergeTime) {
RedoEdit(buffer, carets); RedoEdit(buffer, carets);
} }
} }
@@ -921,7 +921,7 @@ API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
if (buffer->undo_stack.len > 0) { if (buffer->undo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->undo_stack); HistoryEntry *next = GetLast(buffer->undo_stack);
if (entry.time - next->time <= ConfigUndoMergeTimeWindow) { if (entry.time - next->time <= UndoMergeTime) {
UndoEdit(buffer, carets); UndoEdit(buffer, carets);
} }
} }

View File

@@ -23,7 +23,8 @@ String GetDir(Buffer *buffer) {
if (buffer->is_dir) { if (buffer->is_dir) {
return buffer->name; return buffer->name;
} else { } else {
return ChopLastSlash(buffer->name); String result = ChopLastSlash(buffer->name);
return result;
} }
} }
@@ -166,7 +167,7 @@ void UIMessagef(const char *fmt, ...) {
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
RawAppendf(main.buffer, "\n %S\n :Close\n", string); RawAppendf(main.buffer, "\n %S\n :Close\n", string);
main.view->carets[0] = FindNext(main.buffer, u":Close", MakeCaret(0)); main.view->carets[0] = FindNext(main.buffer, u":Close", MakeCaret(0));
AddHook(&main.view->hooks, "Close", "escape", [](){ AddHook(&main.view->hooks, "Close", "escape | enter", [](){
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Close(active.buffer->id); Close(active.buffer->id);
}); });
@@ -178,7 +179,6 @@ void ReportErrorf(const char *fmt, ...) {
View *view = GetView(NullViewID); View *view = GetView(NullViewID);
if (view) { if (view) {
Appendf(view, "%S\n", string); Appendf(view, "%S\n", string);
NextActiveWindowID = NullWindowID;
} }
UIMessagef("%S", string); UIMessagef("%S", string);
} }
@@ -203,6 +203,19 @@ void ReportDebugf(const char *fmt, ...) {
RawAppendf(TraceBuffer, "%S\n", string); RawAppendf(TraceBuffer, "%S\n", string);
} }
void CMD_CenterView() {
BSet set = GetBSet(LastActiveLayoutWindowID);
Caret c = set.view->carets[0];
Int front = GetFront(c);
XY xy = PosToXY(set.buffer, front);
Vec2I size = GetSize(set.window->document_rect);
Int y = size.y / 2 / set.window->font->line_spacing;
set.view->scroll.x = 0;
if (xy.line > y) {
set.view->scroll.y = (xy.line) * set.window->font->line_spacing - (size.y / 2);
}
} RegisterCommand(CMD_CenterView, "");
void MoveCursorByPageSize(Window *window, int direction, bool shift = false) { void MoveCursorByPageSize(Window *window, int direction, bool shift = false) {
Assert(direction == DIR_UP || direction == DIR_DOWN); Assert(direction == DIR_UP || direction == DIR_DOWN);
BSet set = GetBSet(window); BSet set = GetBSet(window);
@@ -408,17 +421,17 @@ BSet ExecBuild(String cmd) {
return build; return build;
} }
void Command_SaveAll() { void CMD_SaveAll() {
For(Buffers) { For(Buffers) {
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved // NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
if (it->file_mod_time) { if (it->file_mod_time) {
SaveBuffer(it); SaveBuffer(it);
} }
} }
} RegisterCommand(Command_SaveAll, "ctrl-shift-s"); } RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
void Command_Build() { void CMD_Build() {
Command_SaveAll(); CMD_SaveAll();
#if OS_WINDOWS #if OS_WINDOWS
ExecBuild("build.bat"); ExecBuild("build.bat");
#else #else
@@ -426,24 +439,24 @@ void Command_Build() {
#endif #endif
BSet main = GetBSet(BuildWindowID); BSet main = GetBSet(BuildWindowID);
main.window->visible = true; main.window->visible = true;
} RegisterCommand(Command_Build, "f1"); } RegisterCommand(CMD_Build, "f1");
void Command_GotoNextInList() { void CMD_GotoNextInList() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
GotoNextInList(main.window, 1); GotoNextInList(main.window, 1);
} RegisterCommand(Command_GotoNextInList, "ctrl-e"); } RegisterCommand(CMD_GotoNextInList, "ctrl-e");
void Command_GotoPrevInList() { void CMD_GotoPrevInList() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
GotoNextInList(main.window, -1); GotoNextInList(main.window, -1);
} RegisterCommand(Command_GotoPrevInList, "alt-e"); } RegisterCommand(CMD_GotoPrevInList, "alt-e");
bool IsOpenBoundary(char c) { bool IsOpenBoundary(char c) {
bool result = c == 0 || IsParen(c) || IsBrace(c) || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\''; bool result = c == 0 || IsParen(c) || IsBrace(c) || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\'';
return result; return result;
} }
ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { ResolvedOpen ResolveOpen(Allocator alo, String path, String meta) {
ResolvedOpen result = {}; ResolvedOpen result = {};
path = Trim(path); path = Trim(path);
@@ -473,7 +486,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
// Web // Web
{ {
if (StartsWith(path, "https://") || StartsWith(path, "http://")) { if (StartsWith(path, "https://") || StartsWith(path, "http://")) {
result.path = Format(scratch, "%S %S", ConfigInternetBrowser, path); result.path = Format(alo, "%S %S", InternetBrowser, path);
result.kind = OpenKind_BackgroundExec; result.kind = OpenKind_BackgroundExec;
return result; return result;
} }
@@ -483,14 +496,17 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
{ {
if (StartsWith(path, "commit ")) { if (StartsWith(path, "commit ")) {
path = Skip(path, 7); path = Skip(path, 7);
result.path = Format(scratch, "git --no-pager show %S", path); result.path = Format(alo, "git --no-pager show %S", path);
result.kind = OpenKind_Exec; result.kind = OpenKind_Exec;
return result; return result;
} }
} }
{ {
String p = NormalizePath(scratch, path); String p = NormalizePath(alo, path);
if (p.len == 2 && IsAlphabetic(ToLowerCase(At(p, 0))) && At(p, 1) == ':') {
p = Format(alo, "%S/", p);
}
String pstart = p; String pstart = p;
bool is_absolute = false; bool is_absolute = false;
@@ -509,18 +525,18 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
if (At(p, 0) == ':') { if (At(p, 0) == ':') {
p = Skip(p, 1); p = Skip(p, 1);
result.line = SkipNumber(&p); result.line = SkipInt(&p);
if (At(p, 0) == ':') { if (At(p, 0) == ':') {
p = Skip(p, 1); p = Skip(p, 1);
Int b = SkipNumber(&p); Int b = SkipInt(&p);
result.col = b; result.col = b;
} }
} else if (At(p, 0) == '(') { } else if (At(p, 0) == '(') {
p = Skip(p, 1); p = Skip(p, 1);
result.line = SkipNumber(&p); result.line = SkipInt(&p);
if (At(p, 0) == ',') { if (At(p, 0) == ',') {
p = Skip(p, 1); p = Skip(p, 1);
Int b = SkipNumber(&p); Int b = SkipInt(&p);
result.col = b; result.col = b;
} }
} }
@@ -538,7 +554,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
result.kind = OpenKind_Goto; result.kind = OpenKind_Goto;
return result; return result;
} else { } else {
String workspace_path = Format(scratch, "%S/%S", WorkDir, path); String workspace_path = Format(alo, "%S/%S", WorkDir, path);
bool existing_buffer = GetBuffer(workspace_path, NULL); bool existing_buffer = GetBuffer(workspace_path, NULL);
if (existing_buffer || FileExists(workspace_path)) { if (existing_buffer || FileExists(workspace_path)) {
result.existing_buffer = existing_buffer; result.existing_buffer = existing_buffer;
@@ -547,7 +563,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
return result; return result;
} }
String rel_path = Format(scratch, "%S/%S", GetMainDir(), path); String rel_path = Format(alo, "%S/%S", GetMainDir(), path);
existing_buffer = GetBuffer(rel_path, NULL); existing_buffer = GetBuffer(rel_path, NULL);
if (existing_buffer || FileExists(rel_path)) { if (existing_buffer || FileExists(rel_path)) {
result.existing_buffer = existing_buffer; result.existing_buffer = existing_buffer;
@@ -578,12 +594,14 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
} }
if (IsDir(o.path)) { if (IsDir(o.path)) {
View *view = WindowOpenBufferView(set.window, o.path); View *view = WindowOpenBufferView(set.window, o.path);
SetFuzzy(view);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
ResetBuffer(buffer); ResetBuffer(buffer);
RawAppendf(buffer, "..\n"); RawAppendf(buffer, "\n..\n");
for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) { for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) {
RawAppendf(buffer, "%S\n", it.filename); RawAppendf(buffer, "%S\n", it.filename);
} }
SelectRange(view, GetBufferBeginAsRange(buffer));
} else { } else {
View *view = WindowOpenBufferView(set.window, o.path); View *view = WindowOpenBufferView(set.window, o.path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
@@ -593,7 +611,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
view->carets[0] = MakeCaret(pos); view->carets[0] = MakeCaret(pos);
} }
} }
UpdateScroll(set.window, true); CMD_CenterView();
} else if (o.kind == OpenKind_Exec) { } else if (o.kind == OpenKind_Exec) {
if (set_active) { if (set_active) {
NextActiveWindowID = set.window->id; NextActiveWindowID = set.window->id;
@@ -626,23 +644,23 @@ BSet Open(String16 path, String meta) {
return Open(string, meta); return Open(string, meta);
} }
void Command_Save() { void CMD_Save() {
BSet active = GetBSet(LastActiveLayoutWindowID); BSet active = GetBSet(LastActiveLayoutWindowID);
SaveBuffer(active.buffer); SaveBuffer(active.buffer);
} RegisterCommand(Command_Save, "ctrl-s"); } RegisterCommand(CMD_Save, "ctrl-s");
void Command_Reopen() { void CMD_Reopen() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
ReopenBuffer(main.buffer); ReopenBuffer(main.buffer);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
} RegisterCommand(Command_Reopen, ""); } RegisterCommand(CMD_Reopen, "");
void Command_New() { void CMD_New() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
New(main.window, ""); New(main.window, "");
} RegisterCommand(Command_New, "ctrl-n"); } RegisterCommand(CMD_New, "ctrl-n");
void Command_ToggleFullscreen() { void CMD_ToggleFullscreen() {
if (IsInFullscreen) { if (IsInFullscreen) {
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY); SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY); SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY);
@@ -657,12 +675,12 @@ void Command_ToggleFullscreen() {
} }
IsInFullscreen = !IsInFullscreen; IsInFullscreen = !IsInFullscreen;
} RegisterCommand(Command_ToggleFullscreen, "f11"); } RegisterCommand(CMD_ToggleFullscreen, "f11");
void Command_SetWorkDir() { void CMD_SetWorkDir() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
WorkDir = GetDir(main.buffer); WorkDir = GetDir(main.buffer);
} RegisterCommand(Command_SetWorkDir, ""); } RegisterCommand(CMD_SetWorkDir, "");
String CodeSkipPatterns[] = {".git/", ".obj", ".o", ".pdb", ".exe"}; String CodeSkipPatterns[] = {".git/", ".obj", ".o", ".pdb", ".exe"};
String Coro_OpenCodeDir; String Coro_OpenCodeDir;
@@ -700,18 +718,18 @@ void OpenCode(String dir) {
data->dont_wait_until_resolved = true; data->dont_wait_until_resolved = true;
} }
void Command_OpenCode() { void CMD_OpenCode() {
OpenCode(WorkDir); OpenCode(WorkDir);
} RegisterCommand(Command_OpenCode, ""); } RegisterCommand(CMD_OpenCode, "");
void Command_KillProcess() { void CMD_KillProcess() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
KillProcess(main.view); KillProcess(main.view);
} RegisterCommand(Command_KillProcess, ""); } RegisterCommand(CMD_KillProcess, "");
void Command_CloseWindow() { void CMD_CloseWindow() {
Close(LastActiveLayoutWindowID); Close(LastActiveLayoutWindowID);
} RegisterCommand(Command_CloseWindow, ""); } RegisterCommand(CMD_CloseWindow, "");
void AddHook(Array<CommandData> *arr, String name, String binding, Function *function) { void AddHook(Array<CommandData> *arr, String name, String binding, Function *function) {
CommandData n = {name, binding, function, ParseKeyCached(binding)}; CommandData n = {name, binding, function, ParseKeyCached(binding)};
@@ -756,9 +774,9 @@ void Coro_Rename(mco_coro *co) {
buffer->name = Intern(&GlobalInternTable, string); buffer->name = Intern(&GlobalInternTable, string);
} }
} }
void Command_Rename() { void CMD_Rename() {
CoAdd(Coro_Rename); CoAdd(Coro_Rename);
} RegisterCommand(Command_Rename, ""); } RegisterCommand(CMD_Rename, "");
String Coro_YesNoCancel(mco_coro *co, BSet main, String question) { String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
JumpTempBuffer(&main); JumpTempBuffer(&main);
@@ -830,9 +848,9 @@ void Coro_Close(mco_coro *co) {
} ElseInvalidCodepath(); } ElseInvalidCodepath();
} }
void Command_Close() { void CMD_Close() {
CoAdd(Coro_Close); CoAdd(Coro_Close);
} RegisterCommand(Command_Close, "ctrl-w"); } RegisterCommand(CMD_Close, "ctrl-w");
// Considerations with coroutines: // Considerations with coroutines:
// 1. Does scratch memory leak across Yield boundary? Or interacts badly with Yield stuff in any way? // 1. Does scratch memory leak across Yield boundary? Or interacts badly with Yield stuff in any way?
@@ -875,322 +893,322 @@ void Coro_Quit(mco_coro *co) {
} }
} }
void Command_Quit() { void CMD_Quit() {
CoAdd(Coro_Quit); CoAdd(Coro_Quit);
} RegisterCommand(Command_Quit, ""); } RegisterCommand(CMD_Quit, "");
void Coro_CloseAll(mco_coro *co) { void Coro_CloseAll(mco_coro *co) {
Coro_CloseAllEx(co); Coro_CloseAllEx(co);
} }
void Command_CloseAll() { void CMD_CloseAll() {
CoAdd(Coro_CloseAll); CoAdd(Coro_CloseAll);
} RegisterCommand(Command_CloseAll, ""); } RegisterCommand(CMD_CloseAll, "");
void Command_JumpPrev() { void CMD_JumpPrev() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
JumpToLastValidView(main.window); JumpToLastValidView(main.window);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
} RegisterCommand(Command_JumpPrev, "ctrl-tab"); } RegisterCommand(CMD_JumpPrev, "ctrl-tab");
void Command_Prev() { void CMD_Prev() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->skip_checkpoint = true; main.window->skip_checkpoint = true;
JumpBack(main.window); JumpBack(main.window);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
} RegisterCommand(Command_Prev, "alt-q | mousex1"); } RegisterCommand(CMD_Prev, "alt-q | mousex1");
void Command_Next() { void CMD_Next() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->skip_checkpoint = true; main.window->skip_checkpoint = true;
JumpForward(main.window); JumpForward(main.window);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
} RegisterCommand(Command_Next, "alt-shift-q | mousex2"); } RegisterCommand(CMD_Next, "alt-shift-q | mousex2");
void Command_OpenUpFolder() { void CMD_OpenUpFolder() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
String name = ChopLastSlash(main.buffer->name); String name = ChopLastSlash(main.buffer->name);
Open(name); Open(name);
} RegisterCommand(Command_OpenUpFolder, "ctrl-period"); } RegisterCommand(CMD_OpenUpFolder, "ctrl-period");
void Command_EncloseLine() { void CMD_EncloseLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
EncloseLine(active.view); EncloseLine(active.view);
} RegisterCommand(Command_EncloseLine, "ctrl-l"); } RegisterCommand(CMD_EncloseLine, "ctrl-l");
void Command_SelectAll() { void CMD_SelectAll() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectEntireBuffer(active.view); SelectEntireBuffer(active.view);
active.view->update_scroll = false; active.view->update_scroll = false;
} RegisterCommand(Command_SelectAll, "ctrl-a"); } RegisterCommand(CMD_SelectAll, "ctrl-a");
void Command_Redo() { void CMD_Redo() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
RedoEdit(active.buffer, &active.view->carets); RedoEdit(active.buffer, &active.view->carets);
} RegisterCommand(Command_Redo, "ctrl-shift-z"); } RegisterCommand(CMD_Redo, "ctrl-shift-z");
void Command_Undo() { void CMD_Undo() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
UndoEdit(active.buffer, &active.view->carets); UndoEdit(active.buffer, &active.view->carets);
} RegisterCommand(Command_Undo, "ctrl-z"); } RegisterCommand(CMD_Undo, "ctrl-z");
void Command_MakeFontLarger() { void CMD_MakeFontLarger() {
ConfigFontSize += 1; FontSize += 1;
ReloadFont(ConfigFont, (U32)ConfigFontSize); ReloadFont(Font, (U32)FontSize);
} RegisterCommand(Command_MakeFontLarger, "ctrl-equals"); } RegisterCommand(CMD_MakeFontLarger, "ctrl-equals");
void Command_MakeFontSmaller() { void CMD_MakeFontSmaller() {
if (ConfigFontSize > 4) { if (FontSize > 4) {
ConfigFontSize -= 1; FontSize -= 1;
ReloadFont(ConfigFont, (U32)ConfigFontSize); ReloadFont(Font, (U32)FontSize);
} }
} RegisterCommand(Command_MakeFontSmaller, "ctrl-minus"); } RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus");
void Command_Open() { void CMD_Open() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Open(FetchLoadWord(active.view)); Open(FetchLoadWord(active.view));
} RegisterCommand(Command_Open, "ctrl-q"); } RegisterCommand(CMD_Open, "ctrl-q");
void Command_KillSelectedLines() { void CMD_KillSelectedLines() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
KillSelectedLines(active.view); KillSelectedLines(active.view);
} RegisterCommand(Command_KillSelectedLines, "ctrl-shift-k"); } RegisterCommand(CMD_KillSelectedLines, "ctrl-shift-k");
void Command_IndentSelectedLines() { void CMD_IndentSelectedLines() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
IndentSelectedLines(active.view); IndentSelectedLines(active.view);
} RegisterCommand(Command_IndentSelectedLines, "ctrl-rightbracket | tab"); } RegisterCommand(CMD_IndentSelectedLines, "ctrl-rightbracket | tab");
void Command_DedentSelectedLines() { void CMD_DedentSelectedLines() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
IndentSelectedLines(active.view, true); IndentSelectedLines(active.view, true);
} RegisterCommand(Command_DedentSelectedLines, "ctrl-leftbracket | shift-tab"); } RegisterCommand(CMD_DedentSelectedLines, "ctrl-leftbracket | shift-tab");
void Command_DuplicateLineDown() { void CMD_DuplicateLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
DuplicateLine(active.view, DIR_DOWN); DuplicateLine(active.view, DIR_DOWN);
} RegisterCommand(Command_DuplicateLineDown, "ctrl-alt-down"); } RegisterCommand(CMD_DuplicateLineDown, "ctrl-alt-down");
void Command_CreateCursorDown() { void CMD_CreateCursorDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
CreateCursorVertical(active.view, DIR_DOWN); CreateCursorVertical(active.view, DIR_DOWN);
} RegisterCommand(Command_CreateCursorDown, "alt-shift-down"); } RegisterCommand(CMD_CreateCursorDown, "alt-shift-down");
void Command_SelectDownToEmptyLine() { void CMD_SelectDownToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_SelectDownToEmptyLine, "ctrl-shift-down"); } RegisterCommand(CMD_SelectDownToEmptyLine, "ctrl-shift-down");
void Command_MoveLineDown() { void CMD_MoveLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCaretsLine(active.view, DIR_DOWN); MoveCaretsLine(active.view, DIR_DOWN);
} RegisterCommand(Command_MoveLineDown, "alt-down"); } RegisterCommand(CMD_MoveLineDown, "alt-down");
void Command_MoveDownToEmptyLine() { void CMD_MoveDownToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED);
} RegisterCommand(Command_MoveDownToEmptyLine, "ctrl-down"); } RegisterCommand(CMD_MoveDownToEmptyLine, "ctrl-down");
void Command_SelectDown() { void CMD_SelectDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS); MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectDown, "shift-down"); } RegisterCommand(CMD_SelectDown, "shift-down");
void Command_MoveDown() { void CMD_MoveDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN); MoveCarets(active.view, DIR_DOWN);
} RegisterCommand(Command_MoveDown, "down"); } RegisterCommand(CMD_MoveDown, "down");
void Command_DuplicateLineUp() { void CMD_DuplicateLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
DuplicateLine(active.view, DIR_UP); DuplicateLine(active.view, DIR_UP);
} RegisterCommand(Command_DuplicateLineUp, "ctrl-alt-up"); } RegisterCommand(CMD_DuplicateLineUp, "ctrl-alt-up");
void Command_CreateCursorUp() { void CMD_CreateCursorUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
CreateCursorVertical(active.view, DIR_UP); CreateCursorVertical(active.view, DIR_UP);
} RegisterCommand(Command_CreateCursorUp, "alt-shift-up"); } RegisterCommand(CMD_CreateCursorUp, "alt-shift-up");
void Command_SelectUpToEmptyLine() { void CMD_SelectUpToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_SelectUpToEmptyLine, "ctrl-shift-up"); } RegisterCommand(CMD_SelectUpToEmptyLine, "ctrl-shift-up");
void Command_MoveLineUp() { void CMD_MoveLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCaretsLine(active.view, DIR_UP); MoveCaretsLine(active.view, DIR_UP);
} RegisterCommand(Command_MoveLineUp, "alt-up"); } RegisterCommand(CMD_MoveLineUp, "alt-up");
void Command_MoveUpToEmptyLine() { void CMD_MoveUpToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, CTRL_PRESSED); MoveCarets(active.view, DIR_UP, CTRL_PRESSED);
} RegisterCommand(Command_MoveUpToEmptyLine, "ctrl-up"); } RegisterCommand(CMD_MoveUpToEmptyLine, "ctrl-up");
void Command_SelectUp() { void CMD_SelectUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS); MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectUp, "shift-up"); } RegisterCommand(CMD_SelectUp, "shift-up");
void Command_MoveUp() { void CMD_MoveUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP); MoveCarets(active.view, DIR_UP);
} RegisterCommand(Command_MoveUp, "up"); } RegisterCommand(CMD_MoveUp, "up");
void Command_BoundarySelectLeft() { void CMD_BoundarySelectLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_BoundarySelectLeft, "ctrl-shift-left"); } RegisterCommand(CMD_BoundarySelectLeft, "ctrl-shift-left");
void Command_BoundaryMoveLeft() { void CMD_BoundaryMoveLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED);
} RegisterCommand(Command_BoundaryMoveLeft, "ctrl-left"); } RegisterCommand(CMD_BoundaryMoveLeft, "ctrl-left");
void Command_SelectLeft() { void CMD_SelectLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS); MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectLeft, "shift-left"); } RegisterCommand(CMD_SelectLeft, "shift-left");
void Command_FocusLeftWindow() { void CMD_FocusLeftWindow() {
NextActiveWindowID = SwitchWindow(DIR_LEFT)->id; NextActiveWindowID = SwitchWindow(DIR_LEFT)->id;
} RegisterCommand(Command_FocusLeftWindow, "alt-left"); } RegisterCommand(CMD_FocusLeftWindow, "alt-left");
void Command_MoveLeft() { void CMD_MoveLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT); MoveCarets(active.view, DIR_LEFT);
} RegisterCommand(Command_MoveLeft, "left"); } RegisterCommand(CMD_MoveLeft, "left");
void Command_BoundarySelectRight() { void CMD_BoundarySelectRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_BoundarySelectRight, "ctrl-shift-right"); } RegisterCommand(CMD_BoundarySelectRight, "ctrl-shift-right");
void Command_BoundaryMoveRight() { void CMD_BoundaryMoveRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED);
} RegisterCommand(Command_BoundaryMoveRight, "ctrl-right"); } RegisterCommand(CMD_BoundaryMoveRight, "ctrl-right");
void Command_SelectRight() { void CMD_SelectRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS); MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectRight, "shift-right"); } RegisterCommand(CMD_SelectRight, "shift-right");
void Command_FocusRightWindow() { void CMD_FocusRightWindow() {
NextActiveWindowID = SwitchWindow(DIR_RIGHT)->id; NextActiveWindowID = SwitchWindow(DIR_RIGHT)->id;
} RegisterCommand(Command_FocusRightWindow, "alt-right"); } RegisterCommand(CMD_FocusRightWindow, "alt-right");
void Command_MoveRight() { void CMD_MoveRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT); MoveCarets(active.view, DIR_RIGHT);
} RegisterCommand(Command_MoveRight, "right"); } RegisterCommand(CMD_MoveRight, "right");
void Command_MoveUpAPage() { void CMD_MoveUpAPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_UP); MoveCursorByPageSize(active.window, DIR_UP);
} RegisterCommand(Command_MoveUpAPage, "pageup"); } RegisterCommand(CMD_MoveUpAPage, "pageup");
void Command_SelectUpPage() { void CMD_SelectUpPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS); MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS);
} RegisterCommand(Command_SelectUpPage, "shift-pageup"); } RegisterCommand(CMD_SelectUpPage, "shift-pageup");
void Command_MoveToStart() { void CMD_MoveToStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectRange(active.view, MakeRange(0)); SelectRange(active.view, MakeRange(0));
} RegisterCommand(Command_MoveToStart, "ctrl-pageup"); } RegisterCommand(CMD_MoveToStart, "ctrl-pageup");
void Command_SelectDownPage() { void CMD_SelectDownPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS); MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS);
} RegisterCommand(Command_SelectDownPage, "shift-pagedown"); } RegisterCommand(CMD_SelectDownPage, "shift-pagedown");
void Command_MoveToEnd() { void CMD_MoveToEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectRange(active.view, MakeRange(active.buffer->len)); SelectRange(active.view, MakeRange(active.buffer->len));
} RegisterCommand(Command_MoveToEnd, "ctrl-pagedown"); } RegisterCommand(CMD_MoveToEnd, "ctrl-pagedown");
void Command_MoveDownPage() { void CMD_MoveDownPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_DOWN); MoveCursorByPageSize(active.window, DIR_DOWN);
} RegisterCommand(Command_MoveDownPage, "pagedown"); } RegisterCommand(CMD_MoveDownPage, "pagedown");
void Command_SelectToLineStart() { void CMD_SelectToLineStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS); MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS);
} RegisterCommand(Command_SelectToLineStart, "shift-home"); } RegisterCommand(CMD_SelectToLineStart, "shift-home");
void Command_MoveToLineStart() { void CMD_MoveToLineStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT); MoveCursorToSide(active.view, DIR_LEFT);
} RegisterCommand(Command_MoveToLineStart, "home"); } RegisterCommand(CMD_MoveToLineStart, "home");
void Command_MoveToLineEnd() { void CMD_MoveToLineEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT); MoveCursorToSide(active.view, DIR_RIGHT);
} RegisterCommand(Command_MoveToLineEnd, "end"); } RegisterCommand(CMD_MoveToLineEnd, "end");
void Command_SelectToLineEnd() { void CMD_SelectToLineEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS); MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS);
} RegisterCommand(Command_SelectToLineEnd, "shift-end"); } RegisterCommand(CMD_SelectToLineEnd, "shift-end");
void Command_Delete() { void CMD_Delete() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_LEFT); Delete(active.view, DIR_LEFT);
} RegisterCommand(Command_Delete, "shift-backspace | backspace"); } RegisterCommand(CMD_Delete, "shift-backspace | backspace");
void Command_DeleteBoundary() { void CMD_DeleteBoundary() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_LEFT, SHIFT_PRESS); Delete(active.view, DIR_LEFT, SHIFT_PRESS);
} RegisterCommand(Command_DeleteBoundary, "ctrl-backspace"); } RegisterCommand(CMD_DeleteBoundary, "ctrl-backspace");
void Command_DeleteForward() { void CMD_DeleteForward() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_RIGHT); Delete(active.view, DIR_RIGHT);
} RegisterCommand(Command_DeleteForward, "shift-delete | delete"); } RegisterCommand(CMD_DeleteForward, "shift-delete | delete");
void Command_DeleteForwardBoundary() { void CMD_DeleteForwardBoundary() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_RIGHT, SHIFT_PRESS); Delete(active.view, DIR_RIGHT, SHIFT_PRESS);
} RegisterCommand(Command_DeleteForwardBoundary, "ctrl-delete"); } RegisterCommand(CMD_DeleteForwardBoundary, "ctrl-delete");
void Command_InsertNewLineUp() { void CMD_InsertNewLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT); MoveCursorToSide(active.view, DIR_LEFT);
IdentedNewLine(active.view); IdentedNewLine(active.view);
MoveCarets(active.view, DIR_UP); MoveCarets(active.view, DIR_UP);
} RegisterCommand(Command_InsertNewLineUp, "ctrl-shift-enter"); } RegisterCommand(CMD_InsertNewLineUp, "ctrl-shift-enter");
void Command_InsertNewLineDown() { void CMD_InsertNewLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT); MoveCursorToSide(active.view, DIR_RIGHT);
IdentedNewLine(active.view); IdentedNewLine(active.view);
} RegisterCommand(Command_InsertNewLineDown, "ctrl-enter"); } RegisterCommand(CMD_InsertNewLineDown, "ctrl-enter");
void Command_NewLine() { void CMD_NewLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
IdentedNewLine(active.view); IdentedNewLine(active.view);
} RegisterCommand(Command_NewLine, "enter | shift-enter"); } RegisterCommand(CMD_NewLine, "enter | shift-enter");
void Command_CreateCaretOnNextFind() { void CMD_CreateCaretOnNextFind() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
String16 string = GetString(active.buffer, active.view->carets[0].range); String16 string = GetString(active.buffer, active.view->carets[0].range);
Caret caret = FindNext(active.buffer, string, active.view->carets[0]); Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
Insert(&active.view->carets, caret, 0); Insert(&active.view->carets, caret, 0);
MergeCarets(active.buffer, &active.view->carets); MergeCarets(active.buffer, &active.view->carets);
} RegisterCommand(Command_CreateCaretOnNextFind, "ctrl-d"); } RegisterCommand(CMD_CreateCaretOnNextFind, "ctrl-d");
void Command_FocusWindow1() { void CMD_FocusWindow1() {
NextActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id; NextActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow1, "ctrl-1"); } RegisterCommand(CMD_FocusWindow1, "ctrl-1");
void Command_FocusWindow2() { void CMD_FocusWindow2() {
Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID)); Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID));
Vec2I p = GetSideOfWindow(first, DIR_RIGHT); Vec2I p = GetSideOfWindow(first, DIR_RIGHT);
NextActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id; NextActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow2, "ctrl-2"); } RegisterCommand(CMD_FocusWindow2, "ctrl-2");
void Command_FocusWindow3() { void CMD_FocusWindow3() {
Window *first = GetOverlappingWindow({0,0}); Window *first = GetOverlappingWindow({0,0});
if (first) { if (first) {
Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT)); Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT));
@@ -1201,13 +1219,13 @@ void Command_FocusWindow3() {
} }
} }
} }
} RegisterCommand(Command_FocusWindow3, "ctrl-3"); } RegisterCommand(CMD_FocusWindow3, "ctrl-3");
void Command_NewWindow() { void CMD_NewWindow() {
CreateWind(); CreateWind();
} RegisterCommand(Command_NewWindow, "ctrl-backslash"); } RegisterCommand(CMD_NewWindow, "ctrl-backslash");
void Command_ClearCarets() { void CMD_ClearCarets() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
active.view->carets.len = 1; active.view->carets.len = 1;
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0])); active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
@@ -1225,4 +1243,193 @@ void Command_ClearCarets() {
it->visible = false; it->visible = false;
} }
} }
} RegisterCommand(Command_ClearCarets, "escape"); } RegisterCommand(CMD_ClearCarets, "escape");
void Set(String16 string) {
Scratch scratch;
SkipWhitespace(&string);
if (At(string, 0) != u':') {
ReportErrorf("Expected :Set");
return;
}
string = Skip(string, 1);
if (!MatchIdent(&string, u"Set")) {
ReportErrorf("Expected :Set");
return;
}
SkipWhitespace(&string);
String16 name = SkipIdent(&string);
if (name.len == 0) {
ReportErrorf("Set command failed to parse at the variable name");
return;
}
String name8 = ToString(scratch, name);
Variable *var = NULL;
For (Variables) {
if (name8 == it.name) {
var = &it;
break;
}
}
if (var) {
SkipWhitespace(&string);
if (var->type == VariableType_String) {
char16_t c = At(string, 0);
String16 q = {&c, 1};
if (c == u'"' || c == u'\'') {
string = Skip(string, 1);
String16 quote = SkipUntil(&string, q);
if (At(string, 0) != c) {
ReportErrorf("Failed to parse :Set %S <error here>, unclosed quote", name8);
return;
}
String quote8 = ToString(scratch, quote);
ReportConsolef(":Set %S %c%S%c", name8, c, quote8, c);
*var->string = Intern(&GlobalInternTable, quote8);
} else {
ReportErrorf("Failed to parse :Set %S <expected string>", name8);
return;
}
} else if (var->type == VariableType_Int) {
if (IsDigit(At(string, 0))) {
Int number = SkipInt(&string);
ReportConsolef(":Set %S %lld", name8, number);
*var->i = number;
} else {
ReportErrorf("Failed to parse :Set %S <expected integer>", name8);
return;
}
} else if (var->type == VariableType_Float) {
if (IsDigit(At(string, 0)) || At(string, 0) == '.') {
Float number = SkipFloat(&string);
ReportConsolef(":Set %S %f", name8, number);
*var->f = number;
} else {
ReportErrorf("Failed to parse :Set %S <expected float>", name8);
return;
}
} else if (var->type == VariableType_Color) {
if (IsHexDigit(At(string, 0))) {
String16 begin = {string.data, 0};
while (IsHexDigit(At(string, 0))) {
string = Skip(string, 1);
begin.len += 1;
}
String p = ToString(scratch, begin);
ReportConsolef(":Set %S %S", name8, p);
var->color->value = (uint32_t)strtoll(p.data, NULL, 16);
} else {
ReportErrorf("Failed to parse :Set %S <expected integer>", name8);
return;
}
} ElseInvalidCodepath();
if (name8 == "FontSize" || name8 == "Font") {
ReloadFont(Font, (U32)FontSize);
}
return;
}
CommandData *cmd = NULL;
For (CommandFunctions) {
if (it.name == name8) {
cmd = &it;
break;
}
}
if (cmd) {
SkipWhitespace(&string);
char16_t c = At(string, 0);
String16 q = {&c, 1};
if (c == u'"' || c == u'\'') {
string = Skip(string, 1);
String16 quote = SkipUntil(&string, q);
if (At(string, 0) != c) {
ReportErrorf("Failed to parse :Set %S <error here>, unclosed quote", name8);
return;
}
String quote8 = Intern(&GlobalInternTable, ToString(scratch, quote));
ReportConsolef(":Set %S %c%S%c", name8, c, quote8, c);
Trigger *trigger = ParseKeyCached(quote8);
if (trigger) {
cmd->binding = quote8;
cmd->trigger = trigger;
}
} else {
ReportErrorf("Failed to parse :Set %S <expected string>", name8);
return;
}
return;
}
ReportErrorf("Failed to :Set, no such variable found: %S", name8);
}
void CMD_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(CMD_Set, "");
void EvalCommandsLineByLine(BSet set) {
WindowID save_last = LastActiveLayoutWindowID;
WindowID save_active = ActiveWindowID;
WindowID save_next = NextActiveWindowID;
ActiveWindowID = set.window->id;
LastActiveLayoutWindowID = set.window->id;
NextActiveWindowID = set.window->id;
for (Int i = 0; i < set.buffer->line_starts.len; i += 1) {
Int pos = GetLineRangeWithoutNL(set.buffer, i).min;
SelectRange(set.view, MakeRange(pos));
Range range = EncloseLoadWord(set.buffer, pos);
String16 string = GetString(set.buffer, range);
string = Trim(string);
if (string.len == 0) {
continue;
}
if (StartsWith(string, u"//")) {
continue;
}
Open(string);
}
LastActiveLayoutWindowID = save_last;
ActiveWindowID = save_active;
NextActiveWindowID = save_next;
}
void CMD_EvalCommandsLineByLine() {
BSet set = GetBSet(LastActiveLayoutWindowID);
EvalCommandsLineByLine(set);
} RegisterCommand(CMD_EvalCommandsLineByLine, "");
void GenerateConfig(Buffer *buffer) {
For (Variables) {
if (it.type == VariableType_String) {
RawAppendf(buffer, "// :Set %S '%S'\n", it.name, *it.string);
} else if (it.type == VariableType_Int) {
RawAppendf(buffer, "// :Set %S '%lld'\n", it.name, (long long)*it.i);
} else if (it.type == VariableType_Float) {
RawAppendf(buffer, "// :Set %S '%f'\n", it.name, *it.f);
} else if (it.type == VariableType_Color) {
RawAppendf(buffer, "// :Set %S %x\n", it.name, it.color->value);
} ElseInvalidCodepath();
}
For (CommandFunctions) {
RawAppendf(buffer, "// :Set %S '%S'\n", it.name, it.binding);
}
}

View File

@@ -87,19 +87,19 @@ void ClipboardPaste(View *view) {
EndEdit(buffer, &edits, &view->carets, KILL_SELECTION); EndEdit(buffer, &edits, &view->carets, KILL_SELECTION);
} }
void Command_Paste() { void CMD_Paste() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
ClipboardPaste(active.view); ClipboardPaste(active.view);
} RegisterCommand(Command_Paste, "ctrl-v"); } RegisterCommand(CMD_Paste, "ctrl-v");
void Command_Copy() { void CMD_Copy() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
ClipboardCopy(active.view); ClipboardCopy(active.view);
} RegisterCommand(Command_Copy, "ctrl-c"); } RegisterCommand(CMD_Copy, "ctrl-c");
void Command_Cut() { void CMD_Cut() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets); SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
ClipboardCopy(active.view); ClipboardCopy(active.view);
Replace(active.view, u""); Replace(active.view, u"");
} RegisterCommand(Command_Cut, "ctrl-x"); } RegisterCommand(CMD_Cut, "ctrl-x");

View File

@@ -130,7 +130,7 @@ void DrawWindow(Window *window, Event &event) {
Rect2I combined_document_line_number = window->document_rect; Rect2I combined_document_line_number = window->document_rect;
if (window->draw_line_numbers) { if (DrawLineNumbers && window->draw_line_numbers) {
combined_document_line_number.min.x = window->line_numbers_rect.min.x; combined_document_line_number.min.x = window->line_numbers_rect.min.x;
} }
SetScissor(combined_document_line_number); SetScissor(combined_document_line_number);
@@ -242,7 +242,7 @@ void DrawWindow(Window *window, Event &event) {
} }
// Draw line numbers // Draw line numbers
if (window->draw_line_numbers) { if (DrawLineNumbers && window->draw_line_numbers) {
ProfileScope(DrawLineNumbers); ProfileScope(DrawLineNumbers);
Scratch scratch; Scratch scratch;
SetScissor(window->line_numbers_rect); SetScissor(window->line_numbers_rect);
@@ -269,7 +269,7 @@ void DrawWindow(Window *window, Event &event) {
} }
// Draw scrollbar // Draw scrollbar
if (window->draw_scrollbar) { if (DrawScrollbar && window->draw_scrollbar) {
ProfileScope(DrawScrollbar); ProfileScope(DrawScrollbar);
SetScissor(window->scrollbar_rect); SetScissor(window->scrollbar_rect);
DrawRect(window->scrollbar_rect, ColorScrollbarBackground); DrawRect(window->scrollbar_rect, ColorScrollbarBackground);

View File

@@ -473,7 +473,7 @@ Array<Event> GetEventsForFrame(Allocator allocator) {
} }
SDL_Event event; SDL_Event event;
if (WaitForEvents) { if (WaitForEventsState) {
SDL_WaitEvent(&event); SDL_WaitEvent(&event);
Event ev = TranslateSDLEvent(&event); Event ev = TranslateSDLEvent(&event);
AddEvent(&result, ev); AddEvent(&result, ev);

View File

@@ -4,7 +4,7 @@ int FullScreenSizeX, FullScreenSizeY;
int FullScreenPositionX, FullScreenPositionY; int FullScreenPositionX, FullScreenPositionY;
bool Testing = false; bool Testing = false;
bool AppIsRunning = true; bool AppIsRunning = true;
bool WaitForEvents = true; bool WaitForEventsState = true;
bool RunGCThisFrame; bool RunGCThisFrame;
bool SearchCaseSensitive = false; bool SearchCaseSensitive = false;
bool SearchWordBoundary = false; bool SearchWordBoundary = false;
@@ -153,14 +153,13 @@ RegisterVariable(Color, ColorTitleBarLineHighlight, GruvboxLight0Soft);
RegisterVariable(Color, ColorTitleBarOutline, GruvboxLight3); RegisterVariable(Color, ColorTitleBarOutline, GruvboxLight3);
RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard); RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard);
RegisterVariable(Color, ColorResizerOutline, GruvboxLight3); RegisterVariable(Color, ColorResizerOutline, GruvboxLight3);
RegisterVariable(Int, ConfigWaitForEvents, 1); RegisterVariable(Int, WaitForEvents, 1);
RegisterVariable(Int, ConfigDrawLineNumbers, 1); RegisterVariable(Int, DrawLineNumbers, 1);
RegisterVariable(Int, ConfigDrawScrollbar, 1); RegisterVariable(Int, DrawScrollbar, 1);
RegisterVariable(Int, ConfigIndentSize, 4); RegisterVariable(Int, IndentSize, 4);
RegisterVariable(Int, ConfigFontSize, 15); RegisterVariable(Int, FontSize, 15);
RegisterVariable(Int, ConfigFontFilter, 0); RegisterVariable(String, Font, "");
RegisterVariable(String, ConfigFont, "/home/krz/text_editor/package/CascadiaMono.ttf"); RegisterVariable(String, VCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(String, ConfigVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); RegisterVariable(Float, UndoMergeTime, 0.3);
RegisterVariable(Float, ConfigUndoMergeTimeWindow, 0.3); RegisterVariable(Float, JumpHistoryMergeTime, 0.3);
RegisterVariable(Float, ConfigJumpHistoryMergeTimeWindow, 0.3); RegisterVariable(String, InternetBrowser, "firefox");
RegisterVariable(String, ConfigInternetBrowser, "firefox");

View File

@@ -119,6 +119,7 @@ void SetMouseCursor(Event event) {
} }
SetMouseCursor(SDL_SYSTEM_CURSOR_DEFAULT); SetMouseCursor(SDL_SYSTEM_CURSOR_DEFAULT);
} }
void UpdateScroll(Window *window, bool update_caret_scrolling) { void UpdateScroll(Window *window, bool update_caret_scrolling) {
ProfileFunction(); ProfileFunction();
BSet set = GetBSet(window); BSet set = GetBSet(window);
@@ -415,7 +416,7 @@ void OnCommand(Event event) {
} }
if (event.kind == EVENT_QUIT) { if (event.kind == EVENT_QUIT) {
Command_Quit(); CMD_Quit();
} }
IF_DEBUG(AssertRanges(main.view->carets)); IF_DEBUG(AssertRanges(main.view->carets));
@@ -561,7 +562,7 @@ void Update(Event event) {
OnCommand(event); OnCommand(event);
StatusWindowUpdate(); StatusWindowUpdate();
DebugWindowUpdate(); DebugWindowUpdate();
CommandWindowUpdate(); FuzzySearchViewUpdate();
SearchWindowUpdate(); SearchWindowUpdate();
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); CoUpdate(&event);
@@ -647,7 +648,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
Scratch scratch; Scratch scratch;
String working_dir = WorkDir; String working_dir = WorkDir;
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-"); String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
String cmd = Format(scratch, "\"%S\" && set", ConfigVCVarsall); String cmd = Format(scratch, "\"%S\" && set", VCVarsall);
view = ExecHidden(buffer_name, cmd, working_dir); view = ExecHidden(buffer_name, cmd, working_dir);
} }
for (;;) { for (;;) {
@@ -700,9 +701,9 @@ void MainLoop() {
} }
} }
WaitForEvents = ConfigWaitForEvents; WaitForEventsState = WaitForEvents;
if (IsDocumentSelectionValid() || IsScrollbarSelectionValid() || ActiveProcesses.len || dont_wait_until_resolved) { if (IsDocumentSelectionValid() || IsScrollbarSelectionValid() || ActiveProcesses.len || dont_wait_until_resolved) {
WaitForEvents = false; WaitForEventsState = false;
} }
// This shouldn't matter to the state of the program, only appearance for // This shouldn't matter to the state of the program, only appearance for
@@ -845,7 +846,7 @@ int main(int argc, char **argv)
InitBuffers(); InitBuffers();
InitRender(); InitRender();
ReloadFont(ConfigFont, (U32)ConfigFontSize); ReloadFont(Font, (U32)FontSize);
InitWindows(); InitWindows();
InitOS(ReportWarningf); InitOS(ReportWarningf);
@@ -872,6 +873,23 @@ int main(int argc, char **argv)
} }
} }
{
Scratch scratch;
String exe_dir = GetExeDir(scratch);
String config_path = Format(scratch, "%S/config.te", exe_dir);
Window *window = GetWindow(NullWindowID);
View *view = WindowOpenBufferView(window, config_path);
Buffer *buffer = GetBuffer(view->active_buffer);
bool file_exists = buffer->file_mod_time != 0;
if (!file_exists) {
GenerateConfig(buffer);
} else {
EvalCommandsLineByLine({window, view, buffer});
}
buffer->dirty = false;
}
ReportConsolef("WorkDir = %S", WorkDir); ReportConsolef("WorkDir = %S", WorkDir);
if (Testing) InitTests(); if (Testing) InitTests();
#if OS_WINDOWS #if OS_WINDOWS

View File

@@ -136,7 +136,7 @@ struct Register_Function {
}; };
#define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name) #define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name)
struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(fucs, {name, binding, function}); } }; struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding) { if (StartsWith(name, "CMD_")) name = Skip(name, sizeof("CMD_") - 1); Add(fucs, {name, binding, function}); } };
#define RegisterCommand(name, binding) Register_Command RC__##name(&CommandFunctions, name, #name, binding) #define RegisterCommand(name, binding) Register_Command RC__##name(&CommandFunctions, name, #name, binding)
const int DIR_RIGHT = 0; const int DIR_RIGHT = 0;

View File

@@ -443,9 +443,9 @@ void Delete(View *view, int direction, bool ctrl = false) {
Range indent_range = GetIndentRangeAtPos(buffer, it.range.min); Range indent_range = GetIndentRangeAtPos(buffer, it.range.min);
if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) { if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) {
Int offset = it.range.min - indent_range.min; Int offset = it.range.min - indent_range.min;
Int to_delete = (offset % (ConfigIndentSize)); Int to_delete = (offset % (IndentSize));
if (to_delete == 0) to_delete = ConfigIndentSize; if (to_delete == 0) to_delete = IndentSize;
to_delete = Clamp(to_delete, (Int)1, ConfigIndentSize); to_delete = Clamp(to_delete, (Int)1, IndentSize);
for (Int i = 0; i < to_delete; i += 1) { for (Int i = 0; i < to_delete; i += 1) {
it = MoveCaret(buffer, it, direction, false, SHIFT_PRESS); it = MoveCaret(buffer, it, direction, false, SHIFT_PRESS);
} }
@@ -512,12 +512,12 @@ void IndentSelectedLines(View *view, bool shift = false) {
Range pos_range_of_line = GetLineRange(buffer, i); Range pos_range_of_line = GetLineRange(buffer, i);
if (!shift) { if (!shift) {
String16 whitespace_string = {u" ", ConfigIndentSize}; String16 whitespace_string = {u" ", IndentSize};
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string); AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string);
} else { } else {
String16 string = GetString(buffer, pos_range_of_line); String16 string = GetString(buffer, pos_range_of_line);
Int whitespace_len = 0; Int whitespace_len = 0;
for (Int i = 0; i < ConfigIndentSize && i < string.len && string.data[i] == ' '; i += 1) { for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == ' '; i += 1) {
whitespace_len += 1; whitespace_len += 1;
} }

View File

@@ -21,6 +21,7 @@ struct View {
struct { struct {
unsigned close : 1; unsigned close : 1;
unsigned special : 1; unsigned special : 1;
unsigned fuzzy : 1;
}; };
}; };

View File

@@ -8,8 +8,8 @@ Window *CreateWind() {
w->font = &PrimaryFont; w->font = &PrimaryFont;
w->visible = true; w->visible = true;
w->layout = true; w->layout = true;
w->draw_scrollbar = ConfigDrawScrollbar; w->draw_scrollbar = true;
w->draw_line_numbers = ConfigDrawLineNumbers; w->draw_line_numbers = true;
w->draw_line_highlight = true; w->draw_line_highlight = true;
w->jump_history = true; w->jump_history = true;
w->id = AllocWindowID(w); w->id = AllocWindowID(w);
@@ -126,8 +126,8 @@ void InitWindows() {
void CalcNiceties(Window *n) { void CalcNiceties(Window *n) {
float scrollbar_size = (10.f * DPIScale); float scrollbar_size = (10.f * DPIScale);
float line_numbers_size = (float)n->font->char_spacing * 10.f; float line_numbers_size = (float)n->font->char_spacing * 10.f;
if (n->draw_scrollbar) n->scrollbar_rect = CutRight(&n->document_rect, (Int)scrollbar_size); if (DrawScrollbar && n->draw_scrollbar) n->scrollbar_rect = CutRight(&n->document_rect, (Int)scrollbar_size);
if (n->draw_line_numbers) n->line_numbers_rect = CutLeft(&n->document_rect, (Int)line_numbers_size); if (DrawLineNumbers && n->draw_line_numbers) n->line_numbers_rect = CutLeft(&n->document_rect, (Int)line_numbers_size);
} }
double WindowCalcEvenResizerValue(Int screen_size_x, Int *out_count = NULL) { double WindowCalcEvenResizerValue(Int screen_size_x, Int *out_count = NULL) {
@@ -278,7 +278,7 @@ void JumpBack(Window *window) {
if (window->goto_history.len) { if (window->goto_history.len) {
GotoCrumb *next = GetLast(window->goto_history); GotoCrumb *next = GetLast(window->goto_history);
if (c.view_id == next->view_id && c.time - next->time <= ConfigJumpHistoryMergeTimeWindow) { if (c.view_id == next->view_id && c.time - next->time <= JumpHistoryMergeTime) {
JumpBack(window); JumpBack(window);
} }
} }
@@ -298,7 +298,7 @@ void JumpForward(Window *window) {
if (window->goto_redo.len) { if (window->goto_redo.len) {
GotoCrumb *next = GetLast(window->goto_redo); GotoCrumb *next = GetLast(window->goto_redo);
if (c.view_id == next->view_id && next->time - c.time <= ConfigJumpHistoryMergeTimeWindow) { if (c.view_id == next->view_id && next->time - c.time <= JumpHistoryMergeTime) {
JumpForward(window); JumpForward(window);
} }
} }

View File

@@ -27,7 +27,7 @@ void BuildWindowLayout(Rect2I *rect, Int wx, Int wy) {
n->document_rect = n->total_rect = CutBottom(rect, barsize); n->document_rect = n->total_rect = CutBottom(rect, barsize);
} }
void Command_ShowBuildWindow() { void CMD_ShowBuildWindow() {
BSet main = GetBSet(BuildWindowID); BSet main = GetBSet(BuildWindowID);
if (ActiveWindowID != BuildWindowID) { if (ActiveWindowID != BuildWindowID) {
main.window->visible = true; main.window->visible = true;
@@ -35,4 +35,4 @@ void Command_ShowBuildWindow() {
} else { } else {
main.window->visible = false; main.window->visible = false;
} }
} RegisterCommand(Command_ShowBuildWindow, "ctrl-grave"); } RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave");

View File

@@ -41,10 +41,10 @@ Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_
return ratings; return ratings;
} }
void CommandWindowUpdate() { void FuzzySearchViewUpdate() {
ProfileFunction(); ProfileFunction();
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) { if (active.view->fuzzy) {
Scratch scratch; Scratch scratch;
String16 line_string = GetLineStringWithoutNL(active.buffer, 0); String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
if (active.view->prev_search_line != line_string) { if (active.view->prev_search_line != line_string) {
@@ -69,8 +69,8 @@ void CommandWindowUpdate() {
} }
} }
void Command_ShowCommands() { void CMD_ShowCommands() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowCommands) { if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowCommands) {
NextActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
@@ -88,10 +88,10 @@ void Command_ShowCommands() {
} }
command_bar.view->update_scroll = true; command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); } RegisterCommand(CMD_ShowCommands, "ctrl-shift-p");
void Command_ShowDebugBufferList() { void CMD_ShowDebugBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowDebugBufferList) { if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
NextActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
@@ -106,10 +106,10 @@ void Command_ShowDebugBufferList() {
} }
command_bar.view->update_scroll = true; command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowDebugBufferList, ""); } RegisterCommand(CMD_ShowDebugBufferList, "");
void Command_ShowBufferList() { void CMD_ShowBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowBufferList) { if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowBufferList) {
NextActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
@@ -121,13 +121,13 @@ void Command_ShowBufferList() {
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For (Buffers) { For (Buffers) {
if (it->special || it->temp) { if (it->special || it->temp) {
continue; if (it->id != NullBufferID) continue;
} }
RawAppendf(command_bar.buffer, "\n%S", it->name); RawAppendf(command_bar.buffer, "\n%S", it->name);
} }
command_bar.view->update_scroll = true; command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowBufferList, "ctrl-p"); } RegisterCommand(CMD_ShowBufferList, "ctrl-p");
void OpenCommand(BSet active) { void OpenCommand(BSet active) {
ProfileFunction(); ProfileFunction();
@@ -144,7 +144,7 @@ void OpenCommand(BSet active) {
Open(string); Open(string);
} }
void Command_CommandWindowOpen() { void CMD_CommandWindowOpen() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
@@ -161,6 +161,11 @@ void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {
n->document_rect = n->total_rect = CutBottom(rect, barsize); n->document_rect = n->total_rect = CutBottom(rect, barsize);
} }
void SetFuzzy(View *view) {
view->fuzzy = true;
AddHook(&view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen);
}
void CommandWindowInit() { void CommandWindowInit() {
Window *window = CreateWind(); Window *window = CreateWind();
CommandWindowID = window->id; CommandWindowID = window->id;
@@ -168,6 +173,7 @@ void CommandWindowInit() {
buffer->special = true; buffer->special = true;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
view->special = true; view->special = true;
SetFuzzy(view);
window->active_view = view->id; window->active_view = view->id;
window->draw_line_numbers = false; window->draw_line_numbers = false;
window->draw_scrollbar = false; window->draw_scrollbar = false;
@@ -178,5 +184,4 @@ void CommandWindowInit() {
window->sync_visibility_with_focus = true; window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true; window->lose_focus_on_escape = true;
window->jump_history = false; window->jump_history = false;
AddHook(&view->hooks, "Open", "ctrl-q | enter", Command_CommandWindowOpen);
} }

View File

@@ -79,7 +79,7 @@ void DebugWindowUpdate() {
RawAppendf(set.buffer, "int temp = %d\n", main.buffer->temp); RawAppendf(set.buffer, "int temp = %d\n", main.buffer->temp);
} }
void Command_ToggleDebug() { void CMD_ToggleDebug() {
Window *window = GetWindow(DebugWindowID); Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible; window->visible = !window->visible;
} RegisterCommand(Command_ToggleDebug, "ctrl-0"); } RegisterCommand(CMD_ToggleDebug, "ctrl-0");

View File

@@ -1,4 +1,4 @@
void Command_Search() { void CMD_Search() {
BSet main = GetBSet(ActiveWindowID); BSet main = GetBSet(ActiveWindowID);
String16 string = {}; String16 string = {};
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) { if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
@@ -12,7 +12,7 @@ void Command_Search() {
Replace(set.view, string); Replace(set.view, string);
SelectEntireBuffer(set.view); SelectEntireBuffer(set.view);
} }
} RegisterCommand(Command_Search, "ctrl-f"); } RegisterCommand(CMD_Search, "ctrl-f");
void SearchWindowFindNext(bool forward = true) { void SearchWindowFindNext(bool forward = true) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
@@ -22,21 +22,21 @@ void SearchWindowFindNext(bool forward = true) {
main.window->search_bar_anchor = main.view->carets[0]; main.window->search_bar_anchor = main.view->carets[0];
} }
void Command_SearchNextInSearch() { void CMD_SearchNextInSearch() {
SearchWindowFindNext(true); SearchWindowFindNext(true);
} }
void Command_SearchPrevInSearch() { void CMD_SearchPrevInSearch() {
SearchWindowFindNext(false); SearchWindowFindNext(false);
} }
void Command_SearchNext() { void CMD_SearchNext() {
SearchWindowFindNext(true); SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNext, "f3"); } RegisterCommand(CMD_SearchNext, "f3");
void Command_SearchPrev() { void CMD_SearchPrev() {
SearchWindowFindNext(false); SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrev, "shift-f3"); } RegisterCommand(CMD_SearchPrev, "shift-f3");
void SearchAll() { void SearchAll() {
Scratch scratch; Scratch scratch;
@@ -53,19 +53,19 @@ void SearchAll() {
} }
} }
void Command_SearchAll() { void CMD_SearchAll() {
SearchAll(); SearchAll();
BSet set = GetBSet(SearchWindowID); BSet set = GetBSet(SearchWindowID);
set.window->visible = false; set.window->visible = false;
} RegisterCommand(Command_SearchAll, "alt-f3"); } RegisterCommand(CMD_SearchAll, "alt-f3");
void Command_ToggleCaseSensitiveSearch() { void CMD_ToggleCaseSensitiveSearch() {
SearchCaseSensitive = !SearchCaseSensitive; SearchCaseSensitive = !SearchCaseSensitive;
} RegisterCommand(Command_ToggleCaseSensitiveSearch, "alt-c"); } RegisterCommand(CMD_ToggleCaseSensitiveSearch, "alt-c");
void Command_ToggleSearchWordBoundary() { void CMD_ToggleSearchWordBoundary() {
SearchWordBoundary = !SearchWordBoundary; SearchWordBoundary = !SearchWordBoundary;
} RegisterCommand(Command_ToggleSearchWordBoundary, "alt-w"); } RegisterCommand(CMD_ToggleSearchWordBoundary, "alt-w");
void SearchWindowUpdate() { void SearchWindowUpdate() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
@@ -107,7 +107,7 @@ void SearchWindowInit() {
window->visible = false; window->visible = false;
window->lose_visibility_on_escape = true; window->lose_visibility_on_escape = true;
window->jump_history = false; window->jump_history = false;
AddHook(&view->hooks, "SearchAll", "alt-enter", Command_SearchAll); AddHook(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll);
AddHook(&view->hooks, "SearchPrevInSearch", "shift-enter", Command_SearchPrevInSearch); AddHook(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
AddHook(&view->hooks, "SearchNextInSearch", "enter", Command_SearchNextInSearch); AddHook(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
} }