Misc improvements and add config.te

This commit is contained in:
Krzosa Karol
2026-01-05 10:15:26 +01:00
parent 40b15ec7aa
commit 565a005dcb
10 changed files with 78 additions and 28 deletions

2
config.te Normal file
View File

@@ -0,0 +1,2 @@
:Set FontSize 20
:Set InternetBrowser '"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"'

View File

@@ -2,10 +2,15 @@
! From a user (novice) point of view, how does it look like? ! From a user (novice) point of view, how does it look like?
- We need regex for: [FormatCode matching, IsCode matching, - We need regex for: [FormatCode matching, IsCode matching,
- Variable documentation - Project config
- Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?)
- 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!
- JumpHistory maybe a smarter algorithm is needed, like accept only if line also changed
- Macros
- ctrl-shift-f should insert the selected into search
- jump history batching doesn't work ...
Use session 4 Use session 4
- ListVariables instead of GenerateConfig, auto saving of variables - ListVariables instead of GenerateConfig, auto saving of variables

View File

@@ -105,6 +105,7 @@ Glyph *GetGlyph(Font *font, uint32_t codepoint) {
return &font->glyphs[index]; return &font->glyphs[index];
} }
} }
Font CreateFont(Atlas *atlas, int32_t size, String path) { Font CreateFont(Atlas *atlas, int32_t size, String path) {
Allocator allocator = GetSystemAllocator(); Allocator allocator = GetSystemAllocator();
Scratch scratch; Scratch scratch;

View File

@@ -547,12 +547,11 @@ void Set(String string) {
} ElseInvalidCodepath(); } ElseInvalidCodepath();
if (name == "FontSize" || name == "Font") { if (name == "FontSize" || name == "PathToFont") {
ReloadFont(Font, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
} else if (name == "WorkDir") { } else if (name == "WorkDir") {
SetWorkDirHere(*var->string); SetWorkDirHere(*var->string);
} }
return; return;
} }
@@ -1150,13 +1149,13 @@ void CMD_Undo() {
void CMD_MakeFontLarger() { void CMD_MakeFontLarger() {
FontSize += 1; FontSize += 1;
ReloadFont(Font, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
} RegisterCommand(CMD_MakeFontLarger, "ctrl-equals", "Increase the font size"); } RegisterCommand(CMD_MakeFontLarger, "ctrl-equals", "Increase the font size");
void CMD_MakeFontSmaller() { void CMD_MakeFontSmaller() {
if (FontSize > 4) { if (FontSize > 4) {
FontSize -= 1; FontSize -= 1;
ReloadFont(Font, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
} }
} RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus", "Decrease the font size"); } RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus", "Decrease the font size");

View File

@@ -36,6 +36,7 @@ WindowID BuildWindowID;
ViewID BuildViewID; ViewID BuildViewID;
BufferID BuildBufferID; BufferID BuildBufferID;
BufferID SearchProjectBufferID; BufferID SearchProjectBufferID;
BufferID GlobalConfigBufferID;
WindowID NextActiveWindowID; WindowID NextActiveWindowID;
WindowID ActiveWindowID; WindowID ActiveWindowID;
@@ -154,14 +155,15 @@ RegisterVariable(Int, WaitForEvents, 1);
RegisterVariable(Int, DrawLineNumbers, 1); RegisterVariable(Int, DrawLineNumbers, 1);
RegisterVariable(Int, DrawScrollbar, 1); RegisterVariable(Int, DrawScrollbar, 1);
RegisterVariable(Int, IndentSize, 4); RegisterVariable(Int, IndentSize, 4);
RegisterVariable(String, IndentKind, "spaces"); RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces");
RegisterVariable(Int, FontSize, 15); RegisterVariable(Int, FontSize, 15);
RegisterVariable(String, WorkDir, ""); RegisterVariable(String, WorkDir, "");
RegisterVariable(String, Font, ""); RegisterVariable(String, PathToFont, "");
RegisterVariable(String, VCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
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, NonCodePatterns_EndsWith, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib"); RegisterVariable(String, NonCodePatterns_EndsWith, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib");
RegisterVariable(Int, TrimTrailingWhitespace, 1); RegisterVariable(Int, TrimTrailingWhitespace, 1);
RegisterVariable(Int, FormatCode, 0); RegisterVariable(Int, FormatCode, 0);
RegisterVariable(Int, SetModifiesConfig, 1);

View File

@@ -676,7 +676,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", VCVarsall); String cmd = Format(scratch, "\"%S\" && set", WindowsVCVarsPathToLoadDevEnviroment);
view = ExecHidden(buffer_name, cmd, working_dir); view = ExecHidden(buffer_name, cmd, working_dir);
} }
for (;;) { for (;;) {
@@ -874,7 +874,7 @@ int main(int argc, char **argv)
InitBuffers(); InitBuffers();
InitRender(); InitRender();
ReloadFont(Font, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
InitWindows(); InitWindows();
InitOS(ReportWarningf); InitOS(ReportWarningf);
@@ -895,13 +895,9 @@ int main(int argc, char **argv)
Window *window = GetWindow(NullWindowID); Window *window = GetWindow(NullWindowID);
View *view = WindowOpenBufferView(window, config_path); View *view = WindowOpenBufferView(window, config_path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
bool file_exists = buffer->file_mod_time != 0; buffer->special = true;
if (!file_exists) { GlobalConfigBufferID = buffer->id;
GenerateConfig(view);
} else {
EvalCommandsLineByLine({window, view, buffer}); EvalCommandsLineByLine({window, view, buffer});
}
buffer->dirty = false;
if (window->active_view == view->id) { if (window->active_view == view->id) {
window->active_view = NullViewID; window->active_view = NullViewID;
} }

View File

@@ -167,7 +167,7 @@ struct Variable {
struct Register_Variable { struct Register_Variable {
Register_Variable(Array<Variable> *variables, VariableType type, String name, void *addr) { Register_Variable(Array<Variable> *variables, VariableType type, String name, void *addr) {
Add(variables, {type, name, addr}); Add(variables, {type, name, {addr}});
} }
}; };
#define RegisterVariable(type, name, ...) \ #define RegisterVariable(type, name, ...) \
@@ -199,6 +199,7 @@ struct ResolvedOpen {
Int line, col; Int line, col;
bool existing_buffer; bool existing_buffer;
}; };
ResolvedOpen ResolveOpen(Allocator scratch, String path, ResolveOpenMeta meta); ResolvedOpen ResolveOpen(Allocator scratch, String path, ResolveOpenMeta meta);
BSet Open(String path, ResolveOpenMeta meta = ResolveOpenMeta_Normal); BSet Open(String path, ResolveOpenMeta meta = ResolveOpenMeta_Normal);
BSet Open(String16 path, ResolveOpenMeta meta = ResolveOpenMeta_Normal); BSet Open(String16 path, ResolveOpenMeta meta = ResolveOpenMeta_Normal);

View File

@@ -508,12 +508,12 @@ Array<Range> GetSelectedLinesSorted(Allocator allocator, View *view) {
char16_t GetIndentChar() { char16_t GetIndentChar() {
char16_t c = u' '; char16_t c = u' ';
if (IndentKind == "spaces") { if (IndentKindWhichIsTabsOrSpaces == "spaces") {
c = u' '; c = u' ';
} else if (IndentKind == "tabs") { } else if (IndentKindWhichIsTabsOrSpaces == "tabs") {
c = u'\t'; c = u'\t';
} else { } else {
ReportErrorf("Invalid IndentKind value: %S", IndentKind); ReportErrorf("Invalid IndentKindWhichIsTabsOrSpaces value: %S", IndentKindWhichIsTabsOrSpaces);
} }
return c; return c;
} }

View File

@@ -2,8 +2,18 @@ struct View;
struct ViewID { Int id; View *o; }; struct ViewID { Int id; View *o; };
typedef void Function(); typedef void Function();
struct FunctionData { String name; Function *function; }; struct FunctionData {
struct CommandData { String name; String binding; Function *function; String doc; struct Trigger *trigger; }; String name;
Function *function;
};
struct CommandData {
String name;
String binding;
Function *function;
String doc;
struct Trigger *trigger;
};
enum ViewKind { enum ViewKind {
ViewKind_Normal, ViewKind_Normal,

View File

@@ -13,15 +13,49 @@ void CMD_ShowCommands() {
if (it.name == "OpenCommand") { if (it.name == "OpenCommand") {
continue; continue;
} }
RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding); // RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding);
RawAppendf(command_bar.buffer, "\n:%-30S <|| ", it.name);
if (it.doc.len) { if (it.doc.len) {
RawAppendf(command_bar.buffer, " |::| %S", it.doc); RawAppendf(command_bar.buffer, "%S", it.doc);
} }
} }
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(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;