Compare commits

...

5 Commits

Author SHA1 Message Date
Krzosa Karol
3ab6639afb Fix underline drawing over line numbers 2026-02-04 08:26:32 +01:00
Krzosa Karol
7a73a982d2 Pause on lexing stuff 2026-02-03 23:23:49 +01:00
Krzosa Karol
51f1fd1b4f ProjectDirectory to ProjectFolder 2026-02-03 21:11:02 +01:00
Krzosa Karol
930620a49e Init variables, ReportErrorf now doesn't pop a message cause it doesn't do the queuing 2026-02-03 21:10:33 +01:00
Krzosa Karol
8cb1b49cd8 Fix ctrl-4 2026-02-03 20:06:56 +01:00
24 changed files with 246 additions and 180 deletions

View File

@@ -7,7 +7,7 @@
- Window position: vscode opens in fullscreen and then remembers what position it was close in (could be a config option) - Window position: vscode opens in fullscreen and then remembers what position it was close in (could be a config option)
- On Linux: Try to implement is_debugger_present() - On Linux: Try to implement is_debugger_present()
- Maybe IPC for te.exe when it's already open and file arguments are passed it should perhaps open a buffer in current window?? - Maybe IPC for te.exe when it's already open and file arguments are passed it should perhaps open a buffer in current window??
- Add <<File>> <<ProjectDirectory>> template strings to Open (Then remove SEtWorkdirhere) - Add <<File>> <<ProjectFolder>> template strings to Open (Then remove SEtWorkdirhere)
- :Set Filename to name current buffer ??? :O and others like that!! - :Set Filename to name current buffer ??? :O and others like that!!
- Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep) - Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep)
- Make the equivalent of SearchOpenBuffers but for cmds like !@git grep -n "@>" - Make the equivalent of SearchOpenBuffers but for cmds like !@git grep -n "@>"

View File

@@ -73,10 +73,10 @@ static const char *glsl_fshader_es3 = R"==(#version 300 es
} }
)=="; )==";
void ReportWarningf(const char *fmt, ...); void ReportErrorf(const char *fmt, ...);
void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) { void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) {
Unused(source); Unused(type); Unused(id); Unused(length); Unused(user); Unused(source); Unused(type); Unused(id); Unused(length); Unused(user);
ReportWarningf("OpenGL message: %s", message); ReportErrorf("OpenGL message: %s", message);
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) { if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL);
} }

View File

@@ -1557,7 +1557,7 @@ void SaveBuffer(Buffer *buffer) {
buffer->dirty = false; buffer->dirty = false;
buffer->temp = false; buffer->temp = false;
} else { } else {
ReportWarningf("Failed to save file with name: %S", buffer->name); ReportErrorf("Failed to save file with name: %S", buffer->name);
} }
} }

View File

@@ -67,6 +67,12 @@ void Appendf(View *view, const char *fmt, ...) {
Append(view, string, true); Append(view, string, true);
} }
void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
Appendf(LogView, "%S\n", string);
}
void ReportErrorf(const char *fmt, ...) { void ReportErrorf(const char *fmt, ...) {
ErrorCount += 1; ErrorCount += 1;
Scratch scratch; Scratch scratch;
@@ -77,28 +83,11 @@ void ReportErrorf(const char *fmt, ...) {
if (LogView) { if (LogView) {
Appendf(LogView, "%S\n", string); Appendf(LogView, "%S\n", string);
ShowUIMessagef("%S", string);
} else { } else {
printf("%.*s\n", (int)string.len, string.data); printf("%.*s\n", (int)string.len, string.data);
} }
} }
void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
Appendf(LogView, "%S\n", string);
}
void ReportWarningf(const char *fmt, ...) {
ErrorCount += 1;
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
if (BreakOnError) {
BREAK();
}
Appendf(LogView, "%S\n", string);
}
void CMD_CenterView() { void CMD_CenterView() {
CenterView(PrimaryWindowID); CenterView(PrimaryWindowID);
} RegisterCommand(CMD_CenterView, "", ""); } RegisterCommand(CMD_CenterView, "", "");

View File

@@ -1,12 +1,3 @@
struct Lexer {
Allocator allocator;
char *at;
char *start;
char *end;
char *name;
int line, column;
};
enum TriggerKind { enum TriggerKind {
TriggerKind_Error, TriggerKind_Error,
TriggerKind_Key, TriggerKind_Key,
@@ -34,35 +25,7 @@ struct CachedTrigger {
}; };
Array<CachedTrigger> CachedTriggers; Array<CachedTrigger> CachedTriggers;
void Advance(Lexer *lex) { void EatWhitespaceEx(Lexer *lex) {
if (lex->at < lex->end) {
if (lex->at[0] == '\n') {
lex->line += 1;
lex->column = 0;
} else {
lex->column += 1;
}
lex->at += 1;
}
}
void Advance(Lexer *lex, int n) {
for (int i = 0; i < n; i += 1) Advance(lex);
}
char At(Lexer *lex) {
if (lex->at < lex->end) {
return lex->at[0];
}
return 0;
}
String AsString(Lexer *lex) {
String result = {lex->at, lex->end - lex->at};
return result;
}
void EatWhitespace(Lexer *lex) {
while (At(lex) != '\n' && IsWhitespace(At(lex))) { while (At(lex) != '\n' && IsWhitespace(At(lex))) {
Advance(lex); Advance(lex);
} }
@@ -80,7 +43,7 @@ Trigger *TriggerBinary(Lexer *lex, Trigger *left, Trigger *right, int key) {
Trigger *ParseKeyAtom(Lexer *lex) { Trigger *ParseKeyAtom(Lexer *lex) {
Trigger *result = AllocType(lex->allocator, Trigger); Trigger *result = AllocType(lex->allocator, Trigger);
result->kind = TriggerKind_Key; result->kind = TriggerKind_Key;
EatWhitespace(lex); EatWhitespaceEx(lex);
for (;;) { for (;;) {
String lex_string = AsString(lex); String lex_string = AsString(lex);
if (StartsWith(lex_string, "ctrl")) { if (StartsWith(lex_string, "ctrl")) {
@@ -118,12 +81,12 @@ Trigger *ParseKeyAtom(Lexer *lex) {
if (!found) { if (!found) {
result->kind = TriggerKind_Error; result->kind = TriggerKind_Error;
ReportErrorf("%s:%d:%d: Failed to parse key trigger, unexpected identifier: '%d'", lex->name, lex->line, lex->column, result->key); ReportErrorf("%s:%d:%d: Failed to parse key trigger, unexpected identifier: '%d'", lex->file, lex->line, lex->column, result->key);
return result; return result;
} }
} else { } else {
result->kind = TriggerKind_Error; result->kind = TriggerKind_Error;
ReportErrorf("%s:%d:%d: Failed to parse key trigger, unexpected character: '%c'", lex->name, lex->line, lex->column, At(lex)); ReportErrorf("%s:%d:%d: Failed to parse key trigger, unexpected character: '%c'", lex->file, lex->line, lex->column, At(lex));
return result; return result;
} }
@@ -138,21 +101,21 @@ Trigger *ParseKeyAtom(Lexer *lex) {
Trigger *ParseKeyChord(Lexer *lex) { Trigger *ParseKeyChord(Lexer *lex) {
Trigger *left = ParseKeyAtom(lex); Trigger *left = ParseKeyAtom(lex);
EatWhitespace(lex); EatWhitespaceEx(lex);
while (IsAlphanumeric(At(lex))) { while (IsAlphanumeric(At(lex))) {
left = TriggerBinary(lex, left, ParseKeyChord(lex), ' '); left = TriggerBinary(lex, left, ParseKeyChord(lex), ' ');
EatWhitespace(lex); EatWhitespaceEx(lex);
} }
return left; return left;
} }
Trigger *ParseKeyOr(Lexer *lex) { Trigger *ParseKeyOr(Lexer *lex) {
Trigger *left = ParseKeyChord(lex); Trigger *left = ParseKeyChord(lex);
EatWhitespace(lex); EatWhitespaceEx(lex);
while (At(lex) == '|') { while (At(lex) == '|') {
Advance(lex); Advance(lex);
left = TriggerBinary(lex, left, ParseKeyOr(lex), '|'); left = TriggerBinary(lex, left, ParseKeyOr(lex), '|');
EatWhitespace(lex); EatWhitespaceEx(lex);
} }
return left; return left;
} }

View File

@@ -61,7 +61,7 @@ void UpdateCoroutines(Event *event) {
_CoroutineContext = &it; _CoroutineContext = &it;
mco_result ok = mco_resume(it.co); mco_result ok = mco_resume(it.co);
if (ok != MCO_SUCCESS) { if (ok != MCO_SUCCESS) {
ReportWarningf("failed to resume coroutine %d", ok); ReportErrorf("failed to resume coroutine %d", ok);
DestroyCoroutine(&it); DestroyCoroutine(&it);
remove_item = true; remove_item = true;
} }

View File

@@ -1,22 +1,25 @@
namespace DataDesc { typedef U32 TokenKind;
struct Lexer { enum {
Allocator allocator; TokenKind_EOF = 0,
char *at; TokenKind_Ident = (1<<0),
char *start; TokenKind_String = (1<<1),
char *end; TokenKind_Numeric = (1<<2),
TokenKind_Comment = (1<<3),
TokenKind_Error = (1<<4),
char *file; TokenKind_OpenBrace = (1<<5),
int line, column; TokenKind_CloseBrace = (1<<6),
TokenKind_Colon = (1<<7),
TokenKind_Comma = (1<<8),
TokenKind_Minus = (1<<9),
TokenKind_Tag = (1<<10),
TokenKind_Or = (1<<11),
}; };
enum TokenKind { typedef U32 TokenGroup;
TokenKind_EOF, enum {
TokenKind_String, TokenGroup_String = (TokenKind_Numeric|TokenKind_String|TokenKind_Ident),
TokenKind_Colon, TokenGroup_Symbol = (TokenKind_OpenBrace|TokenKind_CloseBrace|TokenKind_Colon|TokenKind_Comma|TokenKind_Minus|TokenKind_Tag|TokenKind_Or),
TokenKind_Comma,
TokenKind_OpenBrace,
TokenKind_CloseBrace,
TokenKind_Error,
}; };
struct Token { struct Token {
@@ -25,14 +28,42 @@ struct Token {
struct {char *data; Int len;}; struct {char *data; Int len;};
String string; String string;
}; };
int line, column; Float f;
Int line, column;
char *file; char *file;
}; };
Lexer MakeLexer(Allocator allocator, String string, char *file) { struct Lexer {
Assert(string.data != NULL && string.data != 0); Allocator allocator;
Lexer result = {allocator, string.data, string.data, string.data + string.len}; char *at;
result.file = file; char *start;
char *end;
char *file;
Int line, column;
};
Lexer MakeLexer(Allocator allocator, String string, char *file, Int line, Int column) {
Lexer lexer = {allocator, string.data, string.data, string.data + string.len, file, line, column};
return lexer;
}
void Advance(Lexer *lex) {
if (lex->at < lex->end) {
if (lex->at[0] == '\n') {
lex->line += 1;
lex->column = 0;
}
lex->column += 1;
lex->at += 1;
}
}
void Advance(Lexer *lex, int n) {
for (int i = 0; i < n; i += 1) Advance(lex);
}
String AsString(Lexer *lex) {
String result = {lex->at, lex->end - lex->at};
return result; return result;
} }
@@ -43,18 +74,6 @@ char At(Lexer *lex) {
return 0; return 0;
} }
void Advance(Lexer *lex) {
if (lex->at >= lex->end) {
return;
}
if (lex->at[0] == '\n') {
lex->line += 1;
lex->column = 0;
}
lex->column += 1;
lex->at += 1;
}
void EatWhitespace(Lexer *lex) { void EatWhitespace(Lexer *lex) {
while (IsWhitespace(At(lex))) { while (IsWhitespace(At(lex))) {
Advance(lex); Advance(lex);
@@ -82,8 +101,24 @@ void LexString(Lexer *lex, Token *t) {
t->len = (Int)(lex->at - t->data) - 1; t->len = (Int)(lex->at - t->data) - 1;
} }
bool IsOkForIdent(char cc) { void LexDigit(Lexer *lex, Token *t) {
bool result = IsAlphanumeric(cc) || cc == '_' || cc == '/' || cc == '-' || cc == '.' || cc == '@'; t->kind = TokenKind_Numeric;
for (;;) {
char c = At(lex);
if (c == 0) {
break;
}
if (!IsDigit(c)) {
break;
}
Advance(lex);
}
t->len = (Int)(lex->at - t->data);
t->f = (Float)strtoll(t->data, NULL, 10);
}
bool IsOkForIdent(Lexer *lex, char c) {
bool result = IsAlphanumeric(c) || c == '_' || c == '/';
return result; return result;
} }
@@ -99,7 +134,7 @@ Token Next(Lexer *lex) {
Advance(lex); Advance(lex);
if (c == 0) { if (c == 0) {
t.kind = TokenKind_EOF; return t;
} else if (c == '{') { } else if (c == '{') {
t.kind = TokenKind_OpenBrace; t.kind = TokenKind_OpenBrace;
} else if (c == '}') { } else if (c == '}') {
@@ -108,15 +143,17 @@ Token Next(Lexer *lex) {
t.kind = TokenKind_Colon; t.kind = TokenKind_Colon;
} else if (c == ',') { } else if (c == ',') {
t.kind = TokenKind_Comma; t.kind = TokenKind_Comma;
} else if (IsDigit(c)) {
LexDigit(lex, &t);
} else if (c == '"') { } else if (c == '"') {
LexString(lex, &t); LexString(lex, &t);
} else if (c == '`') { } else if (c == '`') {
LexString(lex, &t); LexString(lex, &t);
} else if (IsOkForIdent(c)) { } else if (IsOkForIdent(lex, c)) {
t.kind = TokenKind_String; t.kind = TokenKind_String;
for (;;) { for (;;) {
char cc = At(lex); char cc = At(lex);
bool ok = IsOkForIdent(cc); bool ok = IsOkForIdent(lex, cc);
if (!ok) { if (!ok) {
break; break;
} }
@@ -132,10 +169,10 @@ Token Next(Lexer *lex) {
return t; return t;
} }
void RunDataDescriptionTest() { void TestDataDesc() {
Scratch scratch; Scratch scratch;
String s = "{/usr/bin/python3, `Hidden`, Input:Clipboard}"; String s = "{/usr/bin/python3, `Hidden`, Input:Clipboard}";
Lexer lexer = MakeLexer(scratch, s, "test"); Lexer lexer = MakeLexer(scratch, s, "test", 0, 0);
{ {
Token tok = {}; Token tok = {};
tok = Next(&lexer); tok = Next(&lexer);
@@ -179,6 +216,4 @@ void RunDataDescriptionTest() {
Assert(tok.kind == TokenKind_EOF); Assert(tok.kind == TokenKind_EOF);
} }
} RegisterFunction(&TestFunctions, TestDataDesc);
} RegisterFunction(&TestFunctions, RunDataDescriptionTest);
}

View File

@@ -103,6 +103,7 @@ void DrawUnderline(Window *window, View *view, Buffer *buffer, Range range, Colo
Vec2I max = {xy_max.col * window->font->char_spacing, (xy_max.line + 1) * window->font->line_spacing}; Vec2I max = {xy_max.col * window->font->char_spacing, (xy_max.line + 1) * window->font->line_spacing};
Rect2I rect = {min, max}; Rect2I rect = {min, max};
Rect2I scrolled_rect = rect - view->scroll + window->document_rect.min; Rect2I scrolled_rect = rect - view->scroll + window->document_rect.min;
if (scrolled_rect.min.x < window->document_rect.min.x) scrolled_rect.min.x = window->document_rect.min.x;
DrawRectOutline(scrolled_rect, color); DrawRectOutline(scrolled_rect, color);
} }

View File

@@ -12,7 +12,6 @@ bool BreakOnError = false;
Int ErrorCount; Int ErrorCount;
Allocator SysAllocator = {SystemAllocatorProc}; Allocator SysAllocator = {SystemAllocatorProc};
String ConfigDir;
float DPIScale = 1.0f; float DPIScale = 1.0f;
// @WARNING: be careful about using this, should only be used for debugging // @WARNING: be careful about using this, should only be used for debugging
@@ -175,10 +174,12 @@ RegisterVariable(String, InternetBrowser, "firefox");
RegisterVariable(String, OpenCodePatterns, ".c .h .cpp .hpp .cc .cxx .rs .go .zig .py .lua .js .ts .jsx .tsx .java .kt .swift .cs .rb .php .html .css .scss .bat .sh .bash .zsh .sql .asm .s .cmake .make .json .yaml .toml .ini .txt .md .rst .Makefile .Dockerfile .gitignore .bashrc .zshrc"); RegisterVariable(String, OpenCodePatterns, ".c .h .cpp .hpp .cc .cxx .rs .go .zig .py .lua .js .ts .jsx .tsx .java .kt .swift .cs .rb .php .html .css .scss .bat .sh .bash .zsh .sql .asm .s .cmake .make .json .yaml .toml .ini .txt .md .rst .Makefile .Dockerfile .gitignore .bashrc .zshrc");
RegisterVariable(String, OpenCodeExcludePatterns, ""); RegisterVariable(String, OpenCodeExcludePatterns, "");
RegisterVariable(Int, TrimTrailingWhitespace, 1); RegisterVariable(Int, TrimTrailingWhitespace, 1);
RegisterVariable(String, HomeFolder, "");
RegisterVariable(String, ConfigFolder, "");
// PROJECT_MANAGEMENT // PROJECT_MANAGEMENT
// Set at the beginning of the program to current directory // Set at the beginning of the program to current directory
RegisterVariable(String, ProjectDirectory, ""); RegisterVariable(String, ProjectFolder, "");
// PLUGIN_BUILD_WINDOW // PLUGIN_BUILD_WINDOW
RegisterVariable(String, Build1OnWindows, "build.bat slow"); RegisterVariable(String, Build1OnWindows, "build.bat slow");

View File

@@ -5,7 +5,7 @@ BufferID BuildBufferID;
void InitBuildWindow() { void InitBuildWindow() {
Window *window = CreateWind(); Window *window = CreateWind();
BuildWindowID = window->id; BuildWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "build")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "build"));
buffer->special = true; buffer->special = true;
buffer->no_history = true; buffer->no_history = true;
BuildBufferID = buffer->id; BuildBufferID = buffer->id;
@@ -32,7 +32,7 @@ void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) {
window->document_rect = window->total_rect = CutBottom(rect, barsize); window->document_rect = window->total_rect = CutBottom(rect, barsize);
} }
BSet ExecBuild(String windows_cmd, String unix_cmd, String working_dir = ProjectDirectory) { BSet ExecBuild(String windows_cmd, String unix_cmd, String working_dir = ProjectFolder) {
SaveAll(); SaveAll();
Scratch scratch; Scratch scratch;
BSet build = GetBSet(BuildWindowID); BSet build = GetBSet(BuildWindowID);

View File

@@ -67,7 +67,7 @@ void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy) {
void InitCommandWindow() { void InitCommandWindow() {
Window *window = CreateWind(); Window *window = CreateWind();
CommandWindowID = window->id; CommandWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "command_bar")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "command_bar"));
buffer->special = true; buffer->special = true;
buffer->no_history = true; buffer->no_history = true;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);

View File

@@ -56,17 +56,6 @@ void CMD_EvalCommandsLineByLine() {
EvalCommandsLineByLine(set); EvalCommandsLineByLine(set);
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'"); } RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
Variable *GetVariable(String name) {
Variable *var = NULL;
For (Variables) {
if (name == it.name) {
var = &it;
break;
}
}
return var;
}
BufferID LoadConfig(String config_path) { BufferID LoadConfig(String config_path) {
ReportConsolef("Loading config %S...", config_path); ReportConsolef("Loading config %S...", config_path);
Window *window = GetWindow(NullWindowID); Window *window = GetWindow(NullWindowID);
@@ -128,8 +117,8 @@ void Set(String string) {
} }
#if PLUGIN_PROJECT_MANAGEMENT #if PLUGIN_PROJECT_MANAGEMENT
if (name == "ProjectDirectory") { if (name == "ProjectFolder") {
SetProjectDirectory(*var->string); SetProjectFolder(*var->string);
} }
#endif #endif
return; return;

View File

@@ -1,3 +1,4 @@
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
void Set(String string); void Set(String string);
String InsertVariables(Allocator allocator, String string);
#endif #endif

View File

@@ -12,7 +12,7 @@ void InitDebugWindow() {
window->primary = false; window->primary = false;
window->jump_history = false; window->jump_history = false;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "debug")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "debug"));
DebugBufferID = buffer->id; DebugBufferID = buffer->id;
buffer->no_history = true; buffer->no_history = true;
buffer->special = true; buffer->special = true;

View File

@@ -2,7 +2,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
View *view = NULL; View *view = NULL;
{ {
Scratch scratch; Scratch scratch;
String working_dir = ProjectDirectory; String working_dir = ProjectFolder;
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-"); String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
String cmd = Format(scratch, "\"%S\" && set", VCVarsPath); String cmd = Format(scratch, "\"%S\" && set", VCVarsPath);
view = OpenBufferView(buffer_name); view = OpenBufferView(buffer_name);

View File

@@ -1,5 +1,5 @@
void SetProjectDirectory(String dir) { void SetProjectFolder(String dir) {
ProjectDirectory = Intern(&GlobalInternTable, dir); ProjectFolder = Intern(&GlobalInternTable, dir);
Scratch scratch; Scratch scratch;
For (Buffers) { For (Buffers) {
if (it->special) { if (it->special) {
@@ -14,7 +14,7 @@ void CO_OpenCode(mco_coro *co) {
Array<String> patterns = SplitWhitespace(ctx->arena, OpenCodePatterns); Array<String> patterns = SplitWhitespace(ctx->arena, OpenCodePatterns);
Array<String> exclude_patterns = SplitWhitespace(ctx->arena, OpenCodeExcludePatterns); Array<String> exclude_patterns = SplitWhitespace(ctx->arena, OpenCodeExcludePatterns);
Array<String> dirs = {ctx->arena}; Array<String> dirs = {ctx->arena};
Add(&dirs, Copy(ctx->arena, ProjectDirectory)); Add(&dirs, Copy(ctx->arena, ProjectFolder));
for (int diri = 0; diri < dirs.len; diri += 1) { for (int diri = 0; diri < dirs.len; diri += 1) {
for (FileIter it = IterateFiles(ctx->arena, dirs[diri]); IsValid(it); Advance(&it)) { for (FileIter it = IterateFiles(ctx->arena, dirs[diri]); IsValid(it); Advance(&it)) {
bool should_open = true; bool should_open = true;
@@ -52,12 +52,12 @@ void CO_OpenCode(mco_coro *co) {
} RegisterCoroutineCommand( } RegisterCoroutineCommand(
CO_OpenCode, CO_OpenCode,
"", "",
"Open all code files in current ProjectDirectory, the code files are determined through NonCodePatterns_EndsWith config variable list", "Open all code files in current ProjectFolder, the code files are determined through NonCodePatterns_EndsWith config variable list",
data->dont_wait_until_resolved = true; data->dont_wait_until_resolved = true;
); );
void OpenProject(String directory) { void OpenProject(String directory) {
SetProjectDirectory(directory); SetProjectFolder(directory);
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
Scratch scratch; Scratch scratch;
for (FileIter it = IterateFiles(scratch, directory); IsValid(it); Advance(&it)) { for (FileIter it = IterateFiles(scratch, directory); IsValid(it); Advance(&it)) {
@@ -111,7 +111,7 @@ void CO_CreateProject(mco_coro *co) {
String src_dir = Format(scratch, "%S/src", project_dir); String src_dir = Format(scratch, "%S/src", project_dir);
MakeDir(project_dir); MakeDir(project_dir);
MakeDir(src_dir); MakeDir(src_dir);
SetProjectDirectory(project_dir); SetProjectFolder(project_dir);
Buffer *project = BufferOpenFile(Format(scratch, "%S/project.te", project_dir)); Buffer *project = BufferOpenFile(Format(scratch, "%S/project.te", project_dir));
RawAppendf(project, ":OpenCode\n:Set BinaryUnderDebug '%S/build/main.exe'\n", project_dir); RawAppendf(project, ":OpenCode\n:Set BinaryUnderDebug '%S/build/main.exe'\n", project_dir);

View File

@@ -1 +1 @@
void SetProjectDirectory(String name); void SetProjectFolder(String name);

View File

@@ -2124,7 +2124,7 @@ bool RDBG_InitConnection(mco_coro *co, bool create_session = true) {
if (file.len == 0) { if (file.len == 0) {
Scratch scratch; Scratch scratch;
for (FileIter it = IterateFiles(scratch, ProjectDirectory); IsValid(it); Advance(&it)) { for (FileIter it = IterateFiles(scratch, ProjectFolder); IsValid(it); Advance(&it)) {
if (EndsWith(it.filename, ".rdbg")) { if (EndsWith(it.filename, ".rdbg")) {
file = Intern(&GlobalInternTable, it.absolute_path); file = Intern(&GlobalInternTable, it.absolute_path);
break; break;
@@ -2133,7 +2133,7 @@ bool RDBG_InitConnection(mco_coro *co, bool create_session = true) {
} }
if (file.len == 0) { if (file.len == 0) {
ReportWarningf("Couldn't find neither .rdbg file, nor use the BinaryUnderDebug variable to locate the binary"); ReportErrorf("Couldn't find neither .rdbg file, nor use the BinaryUnderDebug variable to locate the binary");
return false; return false;
} }
} }
@@ -2178,7 +2178,7 @@ bool RDBG_InitConnection(mco_coro *co, bool create_session = true) {
rdbg_Id cfg_id; rdbg_Id cfg_id;
char *exe = file.data; char *exe = file.data;
char *args = NULL; char *args = NULL;
char *work_dir = ProjectDirectory.data; char *work_dir = ProjectFolder.data;
char *env = NULL; char *env = NULL;
AddSessionConfig(&RDBG_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id); AddSessionConfig(&RDBG_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id);
if (ContextHadError(&RDBG_Ctx)) { if (ContextHadError(&RDBG_Ctx)) {

View File

@@ -63,7 +63,7 @@ void CMD_ToggleSearchWordBoundary() {
void InitSearchWindow() { void InitSearchWindow() {
Window *window = CreateWind(); Window *window = CreateWind();
SearchWindowID = window->id; SearchWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "search")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "search"));
buffer->special = true; buffer->special = true;
SearchBufferID = buffer->id; SearchBufferID = buffer->id;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);

View File

@@ -3,7 +3,7 @@ WindowID StatusWindowID;
void InitStatusWindow() { void InitStatusWindow() {
Window *window = CreateWind(); Window *window = CreateWind();
StatusWindowID = window->id; StatusWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "status_bar")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "status_bar"));
buffer->special = true; buffer->special = true;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
view->special = true; view->special = true;

View File

@@ -57,7 +57,7 @@ void CMD_FocusWindow4() {
Window *third = GetOverlappingWindow(GetSideOfWindow(second, DIR_RIGHT)); Window *third = GetOverlappingWindow(GetSideOfWindow(second, DIR_RIGHT));
if (third) { if (third) {
Window *fourth = GetOverlappingWindow(GetSideOfWindow(third, DIR_RIGHT)); Window *fourth = GetOverlappingWindow(GetSideOfWindow(third, DIR_RIGHT));
if (fourth) NextActiveWindowID = third->id; if (fourth) NextActiveWindowID = fourth->id;
} }
} }
} }

View File

@@ -1,5 +1,6 @@
// MAAAAAAAAAAAAN I DONT LIKE THIS CODE, BUT HOPE IT WORKS // MAAAAAAAAAAAAN I DONT LIKE THIS CODE, BUT HOPE IT WORKS
// @todo: potentially bad that we are not checking against end! lexer->at[0] == 0 check is not enough
struct Lexer2 { struct Lexer2 {
char16_t *at; char16_t *at;
}; };

View File

@@ -854,25 +854,29 @@ extern char **environ;
int main(int argc, char **argv) int main(int argc, char **argv)
#endif #endif
{ {
InitScratch();
InitOS(ReportErrorf);
#if OS_WINDOWS #if OS_WINDOWS
int argc = __argc; int argc = __argc;
char **argv = __argv; char **argv = __argv;
AttachConsole(ATTACH_PARENT_PROCESS); AttachConsole(ATTACH_PARENT_PROCESS);
#endif #endif
InitScratch();
InitOS(ReportErrorf);
if (1) { ProjectFolder = GetWorkingDir(Perm);
RunArenaTest(); HomeFolder = SDL_GetUserFolder(SDL_FOLDER_HOME);
For (TestFunctions) { {
it.function(); String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
sdl_config_path = Chop(sdl_config_path, 1); // chop '/'
}
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '/') {
sdl_config_path = Chop(sdl_config_path, 1); // chop '/'
}
ConfigFolder = NormalizePath(Perm, sdl_config_path);
SDL_free(sdl_config_path.data);
} }
// ReportErrorf("Testing DONE\n"); #if OS_WINDOWS
// return 0;
}
#if OS_WINDOWS
{ {
wchar_t *p = GetEnvironmentStringsW(); wchar_t *p = GetEnvironmentStringsW();
for (;p && p[0];) { for (;p && p[0];) {
@@ -889,17 +893,14 @@ int main(int argc, char **argv)
} }
#endif #endif
ProjectDirectory = GetWorkingDir(Perm); if (1) {
{ RunArenaTest();
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor"); For (TestFunctions) {
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') { it.function();
sdl_config_path = Chop(sdl_config_path, 1); // chop '/'
} }
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '/') {
sdl_config_path = Chop(sdl_config_path, 1); // chop '/' // ReportErrorf("Testing DONE\n");
} // return 0;
ConfigDir = NormalizePath(Perm, sdl_config_path);
SDL_free(sdl_config_path.data);
} }
if (!SDL_Init(SDL_INIT_VIDEO)) { if (!SDL_Init(SDL_INIT_VIDEO)) {
@@ -979,13 +980,13 @@ int main(int argc, char **argv)
{ {
Allocator sys_allocator = GetSystemAllocator(); Allocator sys_allocator = GetSystemAllocator();
Scratch scratch; Scratch scratch;
Buffer *null_buffer = CreateBuffer(sys_allocator, Format(scratch, "%S/scratch", ProjectDirectory)); Buffer *null_buffer = CreateBuffer(sys_allocator, Format(scratch, "%S/scratch", ProjectFolder));
null_buffer->special = true; null_buffer->special = true;
View *null_view = CreateView(null_buffer->id); View *null_view = CreateView(null_buffer->id);
null_view->special = true; null_view->special = true;
Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID); Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID);
Buffer *logs_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "logs", "")); Buffer *logs_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectFolder, "logs", ""));
logs_buffer->special = true; logs_buffer->special = true;
View *logs_view = CreateView(logs_buffer->id); View *logs_view = CreateView(logs_buffer->id);
logs_view->special = true; logs_view->special = true;
@@ -993,13 +994,13 @@ int main(int argc, char **argv)
LogView = logs_view; LogView = logs_view;
#if PLUGIN_RECORD_GC #if PLUGIN_RECORD_GC
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "gc")); GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectFolder, "gc"));
GCInfoBuffer->special = true; GCInfoBuffer->special = true;
GCInfoBuffer->no_history = true; GCInfoBuffer->no_history = true;
#endif #endif
#if PLUGIN_RECORD_EVENTS #if PLUGIN_RECORD_EVENTS
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "events")); EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectFolder, "events"));
EventBuffer->no_history = true; EventBuffer->no_history = true;
EventBuffer->special = true; EventBuffer->special = true;
#endif #endif
@@ -1009,7 +1010,7 @@ int main(int argc, char **argv)
ReloadFont(PathToFont, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
CreateWind(); CreateWind();
ReopenBuffer(GetBuffer(NullBufferID)); ReopenBuffer(GetBuffer(NullBufferID));
InitOS(ReportWarningf); InitOS(ReportErrorf);
For (GlobalCommands) { For (GlobalCommands) {
if (it.binding.len != 0) { if (it.binding.len != 0) {
@@ -1028,7 +1029,7 @@ int main(int argc, char **argv)
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
{ {
Scratch scratch; Scratch scratch;
GlobalConfigBufferID = LoadConfig(Format(scratch, "%S/config.te", ConfigDir)); GlobalConfigBufferID = LoadConfig(Format(scratch, "%S/config.te", ConfigFolder));
} }
#endif #endif
for (int i = 1; i < argc; i += 1) { for (int i = 1; i < argc; i += 1) {

View File

@@ -217,15 +217,92 @@ bool IsOpenBoundary(char c) {
return result; return result;
} }
Variable *GetVariable(String name) {
Variable *var = NULL;
For (Variables) {
if (name == it.name) {
var = &it;
break;
}
}
return var;
}
String InsertVariables(Allocator allocator, String string) {
Scratch scratch(allocator);
Array<String> parts = {scratch};
String it = string;
for (;;) {
int64_t idx = 0;
bool found = Seek(it, "@", &idx, SeekFlag_None);
if (!found) {
if (it.len > 0) {
Add(&parts, it);
}
break;
}
String prev = GetPrefix(it, idx);
if (prev.len > 0) {
Add(&parts, prev);
}
it = Skip(it, idx + 1);
char c = At(it, 0);
String name = {};
if (c == '@') {
Add(&parts, String{"@", 1});
it = Skip(it, 1);
continue;
} else if (c == '(') {
char *start = it.data + 1;
while (At(it, 0) && At(it, 0) != ')') {
it = Skip(it, 1);
}
Int len = it.data - start;
name = {start, len};
it = Skip(it, 1); // skip ')'
} else {
char *start = it.data;
while (IsAlphanumeric(At(it, 0))) {
it = Skip(it, 1);
}
Int len = it.data - start;
name = {start, len};
}
Variable *variable = GetVariable(name);
if (!variable) {
ReportErrorf("Variable: %S, not found", name);
return string;
}
if (variable->type != VariableType_String) {
// @todo: this will not report - open will override
ReportErrorf("Variable: %S, not of type String", variable->type);
return string;
}
Add(&parts, *variable->string);
}
String result = Merge(allocator, parts, "");
return result;
}
void TestInsertVariable() {
Scratch scratch;
String a = "Thing/@(ProjectFolder)/Another";
String b = "Thing/@ProjectFolder/Another";
Assert(InsertVariables(scratch, a) == InsertVariables(scratch, b));
int c = 10;
} RegisterFunction(&TestFunctions, TestInsertVariable);
/* /*
Variables that control the default shell for '!' commands
DefaultShellWindows - "cmd"
DefaultShellUnix - "bash | sh"
Variables: Variables:
@ProjectDirectory/build/te @ProjectFolder/build/te
@(ProjectDirectory)/build/te @(ProjectFolder)/build/te
Start of string matchers: Start of string matchers:
! Execute with default shell ! Execute with default shell
@@ -238,7 +315,7 @@ Start of string matchers:
py: @todo, execute in python shell, this will use the python3 shell and pass the rest to it's stdin or maybe as a file py: @todo, execute in python shell, this will use the python3 shell and pass the rest to it's stdin or maybe as a file
More comprehensive syntax for commands: More comprehensive syntax for commands:
!{/usr/bin/python,Hidden,Input:Clipboard,Output:Clipboard,WorkingDirectory:@ProjectDirectory,Env:{Thing:asd}} !{/usr/bin/python,Hidden,Input:Clipboard,Output:Clipboard,WorkingDirectory:@ProjectFolder,Env:{Thing:asd}}
Otherwise it does filepath parsing: Otherwise it does filepath parsing:
C:/windows/path C:/windows/path
@@ -248,8 +325,16 @@ Otherwise it does filepath parsing:
./thing(10) ./thing(10)
TODO: need to add '~', but where? USECASE: Wouldn't it be cool to just select a part of codebase pipe that into a script
TODO: on linux find shell on first command and set as default and get a result in a clipboard or capture the output and change the selection?
PREV IDEA:
!{bash,Out:Sel} SCRIPT
!{bash,Out:Clip} SCRIPT
Use variables for injecting selection: @Sel
TODO: I would pause the data desc language, seems a bit cumbersome... think of more concrete, constrained ideas
TODO: Unify lexers (Set and Trigger)
*/ */
ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpenMeta meta) { ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpenMeta meta) {
@@ -258,7 +343,7 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
bool exec = !(ResolveOpenMeta_DontExec & meta); bool exec = !(ResolveOpenMeta_DontExec & meta);
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
// @todo: variable substitution {{ProjectDirectory}}/build/te.exe path = InsertVariables(alo, path);
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) { if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) {
result.kind = OpenKind_Set; result.kind = OpenKind_Set;