Project configs

This commit is contained in:
Krzosa Karol
2026-01-05 11:54:10 +01:00
parent 233ebe0eba
commit 96d9847639
6 changed files with 102 additions and 90 deletions

View File

@@ -5,26 +5,23 @@
- Project config - Project config
- IndentKind has issues with stuff still like cleaning whitespace etc. - IndentKind has issues with stuff still like cleaning whitespace etc.
- Remedybg commands integrated! (like clicking f5 and opening up the window) - Remedybg commands integrated! (like clicking f5 and opening up the window)
- Variable documentation ????? not looking too good due to formatting
- OnUpdate view hooks!
- Macros - Macros
- ctrl-e started doing no-ops again ... ?? - ctrl-e started doing no-ops again ... ??
- Window position: vscode opens in fullscreen and then remembers what position it was close in (could be a config option)
- OnUpdate view hooks!
- OnSave buffer hooks which will execute the config on save
- Make the special view hooks also available for modification and registered but maybe under different name or something
Use session 4 Use session 4
- ListVariables instead of GenerateConfig, auto saving of variables
- Option for inserting tab instead of space
- Add <<File>> <<WorkDir>> template strings to Open (Then remove SEtWorkdirhere) - Add <<File>> <<WorkDir>> 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!!
- :Close Fuzzy search exact match doesn't match with Close - :Close Fuzzy search exact match doesn't match with Close
- Setting variables maybe should create and modify config, commit these changes immediately? So user can change keybindings in command window and commit immediately
- Make the special view hooks also available for modification and registered but maybe under different name or something
- 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 SearchProject but for cmds like !@git grep -n "@>" - Make the equivalent of SearchProject but for cmds like !@git grep -n "@>"
- Add Bool variable - Add Bool variable
- RegisterCommand should_appear_in_listing variable - RegisterCommand should_appear_in_listing variable
- Maybe one list for all variables including the commands etc?
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?
@@ -44,10 +41,9 @@ Debug session:
- Report errorf - use coroutine dialogs - Report errorf - use coroutine dialogs
- Replace in render layer also - Replace in render layer also
- BlockAllocator something is not working there which only showed after executing OpenCode on many files - BlockAllocator something is not working there which only showed after executing OpenCode on many files
- Some bad allocating happening in Clipboard for sure - Some bad allocating happening in Clipboard for sure OR MAYBE BLOCK ALLOCATOR ACTION
New UI Session New UI Session
- Cleanup String16/String with Open and EvalCommands after lua refactor
- Uneditable buffers ? - Uneditable buffers ?
- Maybe marked allocations??? So that we can associate allocations with a buffer or view and then dealloc all at the same time - Maybe marked allocations??? So that we can associate allocations with a buffer or view and then dealloc all at the same time

View File

@@ -176,6 +176,10 @@ void UIMessagef(const char *fmt, ...) {
void ReportErrorf(const char *fmt, ...) { void ReportErrorf(const char *fmt, ...) {
Scratch scratch; Scratch scratch;
STRING_FORMAT(scratch, fmt, string); STRING_FORMAT(scratch, fmt, string);
if (BreakOnError) {
BREAK();
}
View *view = GetView(NullViewID); View *view = GetView(NullViewID);
if (view) { if (view) {
Appendf(view, "%S\n", string); Appendf(view, "%S\n", string);
@@ -193,6 +197,9 @@ void ReportConsolef(const char *fmt, ...) {
void ReportWarningf(const char *fmt, ...) { void ReportWarningf(const char *fmt, ...) {
Scratch scratch; Scratch scratch;
STRING_FORMAT(scratch, fmt, string); STRING_FORMAT(scratch, fmt, string);
if (BreakOnError) {
BREAK();
}
View *null_view = GetView(NullViewID); View *null_view = GetView(NullViewID);
Appendf(null_view, "%S\n", string); Appendf(null_view, "%S\n", string);
} }
@@ -583,37 +590,6 @@ void Set(String string) {
ReportErrorf("Failed to :Set, no such variable found: %S", name); ReportErrorf("Failed to :Set, no such variable found: %S", name);
} }
void EvalCommandsLineByLine(BSet set) {
WindowID save_last = PrimaryWindowID;
WindowID save_active = ActiveWindowID;
WindowID save_next = NextActiveWindowID;
Caret save_caret = set.view->carets[0];
ActiveWindowID = set.window->id;
PrimaryWindowID = set.window->id;
NextActiveWindowID = set.window->id;
for (Int i = 0; i < set.buffer->line_starts.len; i += 1) {
Range range = GetLineRangeWithoutNL(set.buffer, i);
String16 string = GetString(set.buffer, range);
string = Trim(string);
if (string.len == 0) {
continue;
}
if (StartsWith(string, u"//")) {
continue;
}
Open(string);
}
set.view->carets[0] = save_caret;
PrimaryWindowID = save_last;
ActiveWindowID = save_active;
NextActiveWindowID = save_next;
}
void CMD_EvalCommandsLineByLine() {
BSet set = GetBSet(PrimaryWindowID);
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 '//'");
ResolvedOpen ResolveOpen(Allocator alo, String path, ResolveOpenMeta meta) { ResolvedOpen ResolveOpen(Allocator alo, String path, ResolveOpenMeta meta) {
ResolvedOpen result = {}; ResolvedOpen result = {};
path = Trim(path); path = Trim(path);

View File

@@ -285,3 +285,81 @@ void TestParser() {
} RegisterFunction(&TestFunctions, TestParser); } RegisterFunction(&TestFunctions, TestParser);
void CMD_OpenConfig() {
Buffer *buffer = GetBuffer(GlobalConfigBufferID);
Open(buffer->name);
} RegisterCommand(CMD_OpenConfig, "", "Open the global config file");
void CMD_OpenConfigOptions() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_OpenConfigOptions) {
NextActiveWindowID = PrimaryWindowID;
return;
}
ProfileFunction();
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Variables) {
RawAppendf(command_bar.buffer, "\n:Set %-50S ", it.name);
switch(it.type) {
case VariableType_Color: RawAppendf(command_bar.buffer, "%x", it.color->value); break;
case VariableType_String: RawAppendf(command_bar.buffer, "'%S'", *it.string); break;
case VariableType_Int: RawAppendf(command_bar.buffer, "%lld", (long long)*it.i); break;
case VariableType_Float: RawAppendf(command_bar.buffer, "%f", *it.f); break;
default: InvalidCodepath();
}
}
For (CommandFunctions) {
RawAppendf(command_bar.buffer, "\n:Set %-50S '%S'", it.name, it.binding);
}
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(CMD_OpenConfigOptions, "", "List available variables and associated documentation inside the command window");
void EvalCommandsLineByLine(BSet set) {
WindowID save_last = PrimaryWindowID;
WindowID save_active = ActiveWindowID;
WindowID save_next = NextActiveWindowID;
Caret save_caret = set.view->carets[0];
ActiveWindowID = set.window->id;
PrimaryWindowID = set.window->id;
NextActiveWindowID = set.window->id;
for (Int i = 0; i < set.buffer->line_starts.len; i += 1) {
Range range = GetLineRangeWithoutNL(set.buffer, i);
String16 string = GetString(set.buffer, range);
string = Trim(string);
if (string.len == 0) {
continue;
}
if (StartsWith(string, u"//")) {
continue;
}
Open(string);
}
set.view->carets[0] = save_caret;
PrimaryWindowID = save_last;
ActiveWindowID = save_active;
NextActiveWindowID = save_next;
}
void CMD_EvalCommandsLineByLine() {
BSet set = GetBSet(PrimaryWindowID);
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 '//'");
BufferID LoadConfig(String config_path) {
ReportConsolef("Loading config %S...", config_path);
Window *window = GetWindow(NullWindowID);
View *view = WindowOpenBufferView(window, config_path);
Buffer *buffer = GetBuffer(view->active_buffer);
buffer->special = true;
EvalCommandsLineByLine({window, view, buffer});
if (window->active_view == view->id) {
window->active_view = NullViewID;
}
return buffer->id;
}

View File

@@ -8,6 +8,7 @@ bool WaitForEventsState = true;
bool RunGCThisFrame; bool RunGCThisFrame;
bool SearchCaseSensitive = false; bool SearchCaseSensitive = false;
bool SearchWordBoundary = false; bool SearchWordBoundary = false;
bool BreakOnError = true;
WindowID WindowIDs; WindowID WindowIDs;
ViewID ViewIDs; ViewID ViewIDs;
@@ -22,7 +23,6 @@ BufferID NullBufferID;
ViewID NullViewID; ViewID NullViewID;
WindowID NullWindowID; WindowID NullWindowID;
// hidden floating window // hidden floating window
WindowID DebugWindowID; WindowID DebugWindowID;
ViewID DebugViewID; ViewID DebugViewID;
@@ -163,7 +163,7 @@ RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files
RegisterVariable(Float, UndoMergeTime, 0.3); RegisterVariable(Float, UndoMergeTime, 0.3);
RegisterVariable(Float, JumpHistoryMergeTime, 0.3); RegisterVariable(Float, JumpHistoryMergeTime, 0.3);
RegisterVariable(String, InternetBrowser, "firefox"); RegisterVariable(String, InternetBrowser, "firefox");
RegisterVariable(String, OpenCodeCommandExcludePatterns, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib"); RegisterVariable(String, OpenCodeCommandExcludePatterns, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib|SDL/");
RegisterVariable(Int, TrimTrailingWhitespace, 1); RegisterVariable(Int, TrimTrailingWhitespace, 1);
RegisterVariable(Int, FormatCode, 0); RegisterVariable(Int, FormatCode, 0);
RegisterVariable(Int, SetModifiesConfig, 1); RegisterVariable(Int, SetModifiesConfig, 1);

View File

@@ -896,25 +896,20 @@ int main(int argc, char **argv)
} }
} }
String project_config = {};
for (int i = 1; i < argc; i += 1) { for (int i = 1; i < argc; i += 1) {
String it = argv[i];
if (EndsWith(it, ".te")) {
project_config = it;
}
Open(argv[i]); Open(argv[i]);
} }
{
Scratch scratch; Scratch scratch;
String exe_dir = GetExeDir(scratch); GlobalConfigBufferID = LoadConfig(Format(scratch, "%S/config.te", GetExeDir(scratch)));
String config_path = Format(scratch, "%S/config.te", exe_dir); if (project_config.len) {
Window *window = GetWindow(NullWindowID); LoadConfig(project_config);
View *view = WindowOpenBufferView(window, config_path);
Buffer *buffer = GetBuffer(view->active_buffer);
buffer->special = true;
GlobalConfigBufferID = buffer->id;
EvalCommandsLineByLine({window, view, buffer});
if (window->active_view == view->id) {
window->active_view = NullViewID;
} }
}
ReportConsolef(":Set WorkDir '%S'", WorkDir); ReportConsolef(":Set WorkDir '%S'", WorkDir);
if (Testing) InitTests(); if (Testing) InitTests();

View File

@@ -23,39 +23,6 @@ void CMD_ShowCommands() {
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window"); } RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window");
void CMD_OpenConfig() {
Buffer *buffer = GetBuffer(GlobalConfigBufferID);
Open(buffer->name);
} RegisterCommand(CMD_OpenConfig, "", "Open the global config file");
void CMD_OpenConfigOptions() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_OpenConfigOptions) {
NextActiveWindowID = PrimaryWindowID;
return;
}
ProfileFunction();
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Variables) {
RawAppendf(command_bar.buffer, "\n:Set %-50S ", it.name);
switch(it.type) {
case VariableType_Color: RawAppendf(command_bar.buffer, "%x", it.color->value); break;
case VariableType_String: RawAppendf(command_bar.buffer, "'%S'", *it.string); break;
case VariableType_Int: RawAppendf(command_bar.buffer, "%lld", (long long)*it.i); break;
case VariableType_Float: RawAppendf(command_bar.buffer, "%f", *it.f); break;
default: InvalidCodepath();
}
}
For (CommandFunctions) {
RawAppendf(command_bar.buffer, "\n:Set %-50S '%S'", it.name, it.binding);
}
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(CMD_OpenConfigOptions, "", "List available variables and associated documentation inside the command window");
void CMD_ShowDebugBufferList() { void CMD_ShowDebugBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) { if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
NextActiveWindowID = PrimaryWindowID; NextActiveWindowID = PrimaryWindowID;