Improving command parsing semantics, gofmt, warn when command reported

This commit is contained in:
Krzosa Karol
2026-01-01 18:00:21 +01:00
parent dd7e2ff655
commit 505b2d0ffa
7 changed files with 39 additions and 21 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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<String> patterns = Split(CoCurr->arena, NonCodePatterns_EndsWith, "|");
Array<String> 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);
}

View File

@@ -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);
RegisterVariable(Int, FormatCode, 0);

View File

@@ -460,6 +460,7 @@ void EvalCommand(String command) {
return;
}
}
ReportErrorf("Failed to match with any of the commands: %S", command);
}
void EvalCommand(String16 command) {

View File

@@ -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);
void ApplyFormattingTool(Buffer *buffer, String tool);