Compare commits

...

6 Commits

Author SHA1 Message Date
Krzosa Karol
77c6bf3da9 Add config.te 2026-01-05 10:15:31 +01:00
Krzosa Karol
565a005dcb Misc improvements and add config.te 2026-01-05 10:15:26 +01:00
Krzosa Karol
40b15ec7aa Fix bug in coroutine of SearchProject and use selected string as seed for search 2026-01-05 10:14:35 +01:00
Krzosa Karol
9073909cfc Redesign of show buffers / show debug buffers 2026-01-05 10:13:59 +01:00
Krzosa Karol
cc57da69fd Argument parsing executes commands now 2026-01-05 10:13:17 +01:00
Krzosa Karol
31ebf0bb14 SkipWhitespace fix and LoadWord change 2026-01-05 00:25:23 +01:00
13 changed files with 110 additions and 50 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?
- We need regex for: [FormatCode matching, IsCode matching,
- Variable documentation
- Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?)
- Project config
- IndentKind has issues with stuff still like cleaning whitespace etc.
- 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
- ListVariables instead of GenerateConfig, auto saving of variables

View File

@@ -423,19 +423,20 @@ API String SkipUntil(String *string, String str) {
*string = Skip(*string, 1);
}
return begin;
}
}
API String SkipWhitespace(String *string) {
String begin = {string->data, 0};
for (Int i = 0; i < string->len; i += 1) {
if (!IsWhitespace(string->data[i])) break;
for (;string->len;) {
if (!IsWhitespace(At(*string, 0))) {
break;
}
*string = Skip(*string, 1);
begin.len += 1;
}
return begin;
}
API String ChopNumberEx(String *string) {
String col = {};
for (int64_t i = string->len - 1; i >= 0; i -= 1) {

View File

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

View File

@@ -307,7 +307,7 @@ API Int GetWordEnd(Buffer *buffer, Int pos) {
}
API bool IsLoadWord(char16_t w) {
bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@' || w == u',';
bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@';
if (!result) {
result = !(IsSymbol(w) || IsWhitespace(w));
}

View File

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

View File

@@ -175,6 +175,7 @@ struct CachedTrigger {
Array<CachedTrigger> CachedTriggers;
Trigger *ParseKeyCached(String key) {
key = Trim(key);
if (key.len == 0) {
return NULL;
}

View File

@@ -36,6 +36,7 @@ WindowID BuildWindowID;
ViewID BuildViewID;
BufferID BuildBufferID;
BufferID SearchProjectBufferID;
BufferID GlobalConfigBufferID;
WindowID NextActiveWindowID;
WindowID ActiveWindowID;
@@ -154,14 +155,15 @@ RegisterVariable(Int, WaitForEvents, 1);
RegisterVariable(Int, DrawLineNumbers, 1);
RegisterVariable(Int, DrawScrollbar, 1);
RegisterVariable(Int, IndentSize, 4);
RegisterVariable(String, IndentKind, "spaces");
RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces");
RegisterVariable(Int, FontSize, 15);
RegisterVariable(String, WorkDir, "");
RegisterVariable(String, Font, "");
RegisterVariable(String, VCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(String, PathToFont, "");
RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(Float, UndoMergeTime, 0.3);
RegisterVariable(Float, JumpHistoryMergeTime, 0.3);
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(Int, TrimTrailingWhitespace, 1);
RegisterVariable(Int, FormatCode, 0);
RegisterVariable(Int, SetModifiesConfig, 1);

View File

@@ -676,7 +676,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
Scratch scratch;
String working_dir = WorkDir;
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);
}
for (;;) {
@@ -874,7 +874,7 @@ int main(int argc, char **argv)
InitBuffers();
InitRender();
ReloadFont(Font, (U32)FontSize);
ReloadFont(PathToFont, (U32)FontSize);
InitWindows();
InitOS(ReportWarningf);
@@ -885,20 +885,7 @@ int main(int argc, char **argv)
}
for (int i = 1; i < argc; i += 1) {
String it = argv[i];
if (it == "--testing") {
Testing = true;
} else if (IsDir(it)) {
WorkDir = GetAbsolutePath(Perm, it);
OpenCode(WorkDir);
} else {
if (!FileExists(it)) {
continue;
}
Window *window = GetWindow({0});
WindowOpenBufferView(window, it);
}
Open(argv[i]);
}
{
@@ -908,13 +895,9 @@ int main(int argc, char **argv)
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(view);
} else {
buffer->special = true;
GlobalConfigBufferID = buffer->id;
EvalCommandsLineByLine({window, view, buffer});
}
buffer->dirty = false;
if (window->active_view == view->id) {
window->active_view = NullViewID;
}

View File

@@ -167,7 +167,7 @@ struct Variable {
struct Register_Variable {
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, ...) \
@@ -199,6 +199,7 @@ struct ResolvedOpen {
Int line, col;
bool existing_buffer;
};
ResolvedOpen ResolveOpen(Allocator scratch, String path, ResolveOpenMeta meta);
BSet Open(String 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 c = u' ';
if (IndentKind == "spaces") {
if (IndentKindWhichIsTabsOrSpaces == "spaces") {
c = u' ';
} else if (IndentKind == "tabs") {
} else if (IndentKindWhichIsTabsOrSpaces == "tabs") {
c = u'\t';
} else {
ReportErrorf("Invalid IndentKind value: %S", IndentKind);
ReportErrorf("Invalid IndentKindWhichIsTabsOrSpaces value: %S", IndentKindWhichIsTabsOrSpaces);
}
return c;
}

View File

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

View File

@@ -13,15 +13,49 @@ void CMD_ShowCommands() {
if (it.name == "OpenCommand") {
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) {
RawAppendf(command_bar.buffer, " |::| %S", it.doc);
RawAppendf(command_bar.buffer, "%S", it.doc);
}
}
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} 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() {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
NextActiveWindowID = PrimaryWindowID;
@@ -34,6 +68,10 @@ void CMD_ShowDebugBufferList() {
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
if (!is_special) {
continue;
}
RawAppendf(command_bar.buffer, "\n%S", it->name);
}
command_bar.view->update_scroll = true;
@@ -52,8 +90,9 @@ void CMD_ShowBufferList() {
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
if (it->special || it->temp || it->is_dir) {
if (it->id != NullBufferID) continue;
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
if (is_special) {
continue;
}
RawAppendf(command_bar.buffer, "\n%S", it->name);
}
@@ -148,8 +187,15 @@ struct SearchProjectParams {
void Coro_SearchProject(mco_coro *co) {
SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx;
Array<BufferID> buffers = {CoCurr->arena};
For (Buffers) {
if (it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
Add(&buffers, it->id);
}
ForItem (id, buffers) {
Buffer *it = GetBuffer(id, NULL);
if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
continue;
}
@@ -248,6 +294,11 @@ void FuzzySearchViewUpdate() {
void CMD_SearchProject() {
BSet main = GetBSet(PrimaryWindowID);
String16 string = {};
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
string = GetString(main.buffer, main.view->carets[0].range);
}
NextActiveWindowID = main.window->id;
Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID);
View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
@@ -255,6 +306,10 @@ void CMD_SearchProject() {
view->kind = ViewKind_ActiveSearch;
AddHook(&view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen);
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
if (string.len) {
Replace(view, string);
SelectEntireBuffer(view);
}
} RegisterCommand(CMD_SearchProject, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
void SetFuzzy(View *view) {