From 505b2d0ffa7c98343c4a1e17a3c907d6895a938c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 1 Jan 2026 18:00:21 +0100 Subject: [PATCH] Improving command parsing semantics, gofmt, warn when command reported --- build.bat | 20 ++++++++++---------- src/backup/todo.txt | 4 ++-- src/text_editor/buffer.cpp | 10 ++++++++-- src/text_editor/commands.cpp | 21 ++++++++++++++++----- src/text_editor/globals.cpp | 2 +- src/text_editor/text_editor.cpp | 1 + src/text_editor/text_editor.h | 2 +- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/build.bat b/build.bat index 65734ac..c099011 100755 --- a/build.bat +++ b/build.bat @@ -1,16 +1,16 @@ @echo off if not exist "src\external\SDL" ( - pushd src\external - git clone https://github.com/libsdl-org/SDL.git - pushd SDL - git checkout release-3.4.0 - cmake -S . -B build_win32_static -DCMAKE_BUILD_TYPE=Release -DSDL_STATIC=ON - pushd build_win32_static - msbuild SDL3.sln - popd - popd - popd + pushd src\external + git clone https://github.com/libsdl-org/SDL.git + pushd SDL + git checkout release-3.4.0 + cmake -S . -B build_win32_static -DCMAKE_BUILD_TYPE=Release -DSDL_STATIC=ON + pushd build_win32_static + msbuild SDL3.sln + popd + popd + popd ) set sdl=..\src\external\SDL set sdllib=%sdl%\build_win32_static\Debug diff --git a/src/backup/todo.txt b/src/backup/todo.txt index d682387..602047d 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -3,17 +3,17 @@ - Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep) - Add Bool variable -- Not rendering U+0009 TAB properly +- SetWorkDir should rewrite the buffer name paths for special buffers - Initialize all keybindings at the start and refer using global variables? - RegisterCommand should_appear_in_listing variable - Maybe one list for all variables including the commands etc? -- Problem generating configs don't know which quotation marks would be good .... Use session 3: - Maybe status view, commit changes (like to buffer name or line) on enter? How to go about search/replace, opening code and other considerations +- Search and replace sign Find@>ReplaceWith - We can use sed + find to search and replace, the automatic reopen should do the job - Maybe also we can List all files recursively instead of opening them, how fast is that??? - For fuzzy find number of files is the problem - most likely just getting them in one place is the biggest problem that can be optimized diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index dd5685d..f61c765 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -1515,10 +1515,16 @@ void ReopenBuffer(Buffer *buffer) { void SaveBuffer(Buffer *buffer) { bool formatted = false; - if (FormatUsingClangFormatWhenCCode) { + if (FormatCode) { bool c = EndsWith(buffer->name, ".c") || EndsWith(buffer->name, ".cpp") || EndsWith(buffer->name, ".h") || EndsWith(buffer->name, ".hpp"); if (c) { - ApplyClangFormat(buffer); + ApplyFormattingTool(buffer, "clang-format"); + formatted = true; + } + + bool go = EndsWith(buffer->name, ".go"); + if (go) { + ApplyFormattingTool(buffer, "gofmt"); formatted = true; } } diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 3614c3e..03f8bda 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -316,10 +316,10 @@ void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) view->update_scroll = false; } -void ApplyClangFormat(Buffer *buffer) { +void ApplyFormattingTool(Buffer *buffer, String tool) { Scratch scratch; String string = AllocCharString(scratch, buffer); - Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string); + Buffer *temp_buffer = ExecAndWait(scratch, tool, GetDir(buffer), string); ReplaceWithoutMovingCarets(buffer, GetRange(buffer), {temp_buffer->str, temp_buffer->len}); } @@ -468,7 +468,14 @@ ResolvedOpen ResolveOpen(Allocator alo, String path, String meta) { { if (StartsWith(path, ":")) { result.kind = OpenKind_Command; - result.path = Skip(path, 1); + path = Skip(path, 1); + result.path.data = path.data; + for (Int i = 0; i < path.len; i += 1) { + if (IsNonWord(path.data[i])) { + break; + } + result.path.len += 1; + } return result; } } @@ -682,13 +689,16 @@ void CMD_ToggleFullscreen() { } RegisterCommand(CMD_ToggleFullscreen, "f11"); void CMD_SetWorkDir() { + Scratch scratch; BSet main = GetBSet(LastActiveLayoutWindowID); WorkDir = GetDir(main.buffer); + For (Buffers) { + String name = SkipToLastSlash(it->name); + it->name = Intern(&GlobalInternTable, Format(scratch, "%S/%S", WorkDir, name)); + } } RegisterCommand(CMD_SetWorkDir, ""); -String CodeSkipPatterns[] = {".git/", ".obj", ".o", ".pdb", ".exe", "SDL/", ".ilk", ".ttf", ".ico", ".gif"}; String Coro_OpenCodeDir; - void Coro_OpenCode(mco_coro *co) { Array patterns = Split(CoCurr->arena, NonCodePatterns_EndsWith, "|"); Array dirs = {CoCurr->arena}; @@ -1381,6 +1391,7 @@ void Set(String16 string) { void CMD_Set() { BSet set = GetBSet(ActiveWindowID); Range range = set.view->carets[0].range; + range.max = range.min; // We only scan for :Set if (GetSize(range) == 0) { range = EncloseLoadWord(set.buffer, range.min); } diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index f48712c..40a246a 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -162,4 +162,4 @@ 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"); RegisterVariable(Int, TrimTrailingWhitespace, 1); -RegisterVariable(Int, FormatUsingClangFormatWhenCCode, 0); \ No newline at end of file +RegisterVariable(Int, FormatCode, 0); \ No newline at end of file diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 4a4e7e3..221f6c3 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -460,6 +460,7 @@ void EvalCommand(String command) { return; } } + ReportErrorf("Failed to match with any of the commands: %S", command); } void EvalCommand(String16 command) { diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 0f2db12..4e300a7 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -196,4 +196,4 @@ struct ResolvedOpen { ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta); void CenterView(WindowID window); void TrimWhitespace(Buffer *buffer, bool trim_lines_with_caret = false); -void ApplyClangFormat(Buffer *buffer); \ No newline at end of file +void ApplyFormattingTool(Buffer *buffer, String tool); \ No newline at end of file