This commit is contained in:
Krzosa Karol
2024-08-13 10:43:47 +02:00
parent 9cac98d961
commit 26c1180fad
3 changed files with 12 additions and 9 deletions

View File

@@ -21,6 +21,12 @@ String16 GetString(Buffer *buffer, Range range = {0, INT64_MAX}) {
return result; return result;
} }
String AllocCharString(Allocator allocator, Buffer *buffer, Range range = {0, INT64_MAX}) {
String16 string16 = GetString(buffer, range);
String result = ToString(allocator, string16);
return result;
}
Int Clamp(const Buffer *buffer, Int pos) { Int Clamp(const Buffer *buffer, Int pos) {
Int result = Clamp(pos, (Int)0, buffer->len); Int result = Clamp(pos, (Int)0, buffer->len);
return result; return result;

View File

@@ -384,16 +384,14 @@ void SaveBuffer(View *view) {
// { // {
// Scratch scratch; // Scratch scratch;
// String16 string16 = GetString(buffer); // String string = AllocCharString(scratch, buffer);
// String string = ToString(scratch, string16);
// Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string); // Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string);
// Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), {temp_buffer->str, temp_buffer->len}); // Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), {temp_buffer->str, temp_buffer->len});
// } // }
Scratch scratch; Scratch scratch;
String16 string16 = GetString(buffer); String string = AllocCharString(scratch, buffer);
String string = ToString(scratch, string16); bool success = WriteFile(buffer->name, string);
bool success = WriteFile(buffer->name, string);
if (success) { if (success) {
buffer->dirty = false; buffer->dirty = false;

View File

@@ -300,9 +300,8 @@ void UpdateLua() {
Buffer *lua_buffer = GetBuffer(LuaBufferID); Buffer *lua_buffer = GetBuffer(LuaBufferID);
if (lua_buffer->dirty == false && lua_buffer->change_id != LuaBufferChangeID) { if (lua_buffer->dirty == false && lua_buffer->change_id != LuaBufferChangeID) {
Scratch scratch; Scratch scratch;
String16 string16 = GetString(lua_buffer); String string = AllocCharString(scratch, lua_buffer);
String string = ToString(scratch, string16);
if (luaL_dostring(LuaState, string.data) == LUA_OK) { if (luaL_dostring(LuaState, string.data) == LUA_OK) {
if (lua_isstring(LuaState, -1)) { if (lua_isstring(LuaState, -1)) {
const char *text = lua_tostring(LuaState, -1); const char *text = lua_tostring(LuaState, -1);