RunFile python, open scratch buffer what ever is already there

This commit is contained in:
Krzosa Karol
2026-01-31 10:45:56 +01:00
parent 217659256b
commit d5d99cddf7
4 changed files with 12 additions and 25 deletions

1
.gitignore vendored
View File

@@ -18,3 +18,4 @@ te_debug
text_editor.js
*.map
*.exe
scratch

View File

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

View File

@@ -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 <<EOF\nclang %S -o cfile.exe -g -Wall -Wno-missing-braces -Wno-writable-strings -Wno-writable-strings -fsanitize=address -fdiagnostics-absolute-paths -lm \n./cfile.exe \nrm cfile.exe\nEOF", primary.buffer->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 <<EOF\nclang %S -o cfile.exe -g -Wall -Wno-missing-braces -Wno-writable-strings -Wno-writable-strings -fsanitize=address -fdiagnostics-absolute-paths -lm \n./cfile.exe \nrm cfile.exe\nEOF", primary.buffer->name);
}
ExecBuild(windows_command, unix_command, GetDirectory(primary.buffer));
} RegisterCommand(CMD_RunFile, "", "Run and build current file, currently only C/C++ supported");

View File

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