From d5d99cddf7ea6a09987703cc2b8d560942fea144 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 31 Jan 2026 10:45:56 +0100 Subject: [PATCH] RunFile python, open scratch buffer what ever is already there --- .gitignore | 1 + src/text_editor/globals.cpp | 19 ------------------- src/text_editor/plugin_build_window.cpp | 11 +++++++++-- src/text_editor/text_editor.cpp | 6 ++---- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 56ec3f6..d46dc8a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ te_debug text_editor.js *.map *.exe +scratch \ No newline at end of file diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index 2ae1b19..e83f88d 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -10,25 +10,6 @@ bool SearchCaseSensitive = false; bool SearchWordBoundary = false; bool BreakOnError = false; Int ErrorCount; -#if DEBUG_BUILD -String16 InitialScratchContent = uR"==(:OpenProject -C:/text_editor/src/text_editor/text_editor.cpp -:Set FontSize 70 -/* -!python {{TEMP}} -for it in i: - memes -*/ -0 -1 -2 -3 -4 -5 -6)=="; -#else -String16 InitialScratchContent; -#endif Allocator SysAllocator = {SystemAllocatorProc}; String ConfigDir; diff --git a/src/text_editor/plugin_build_window.cpp b/src/text_editor/plugin_build_window.cpp index 00d3e03..3680cd7 100644 --- a/src/text_editor/plugin_build_window.cpp +++ b/src/text_editor/plugin_build_window.cpp @@ -67,8 +67,15 @@ void CMD_Build4() { void CMD_RunFile() { Scratch scratch; BSet primary = GetBSet(PrimaryWindowID); - String windows_command = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe && del cfile.*", primary.buffer->name); - String unix_command = Format(scratch, "bash <name); + // @todo: this calls for language_cpp, language_c, language_python etc. + String windows_command = ""; + String unix_command = ""; + if (EndsWith(primary.buffer->name, ".py")) { + unix_command = windows_command = Format(scratch, "python %S", primary.buffer->name); + } else { + windows_command = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe && del cfile.*", primary.buffer->name); + unix_command = Format(scratch, "bash <name); + } ExecBuild(windows_command, unix_command, GetDirectory(primary.buffer)); } RegisterCommand(CMD_RunFile, "", "Run and build current file, currently only C/C++ supported"); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index ce6bc08..ec4e40b 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -966,14 +966,11 @@ int main(int argc, char **argv) { Allocator sys_allocator = GetSystemAllocator(); Scratch scratch; - Buffer *null_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "scratch", "")); + Buffer *null_buffer = CreateBuffer(sys_allocator, Format(scratch, "%S/scratch", ProjectDirectory)); null_buffer->special = true; View *null_view = CreateView(null_buffer->id); null_view->special = true; Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID); - if (InitialScratchContent.len) { - RawAppend(null_buffer, InitialScratchContent); - } Buffer *logs_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "logs", "")); logs_buffer->special = true; @@ -998,6 +995,7 @@ int main(int argc, char **argv) InitRender(); ReloadFont(PathToFont, (U32)FontSize); CreateWind(); + ReopenBuffer(GetBuffer(NullBufferID)); InitOS(ReportWarningf); For (GlobalCommands) {