about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-01-25 20:45:00 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-01-25 20:45:00 -0800
commit2e38583da2f6db92ce375e08840ec3a1dae35549 (patch)
tree758d9f54bf02308de9ca1754ff6b4d010db8252d
parent39781351ee01da37f83df3701adf08d922374bf1 (diff)
downloadteliva-2e38583da2f6db92ce375e08840ec3a1dae35549.tar.gz
save doc: buffers to .tlv images
-rw-r--r--src/teliva.c18
-rw-r--r--src/teliva.h1
2 files changed, 17 insertions, 2 deletions
diff --git a/src/teliva.c b/src/teliva.c
index 7e9624f..914842a 100644
--- a/src/teliva.c
+++ b/src/teliva.c
@@ -654,7 +654,10 @@ int restore_editor_view(lua_State* L) {
   int cx = lua_tointeger(L, -1);
   lua_settop(L, editor_state_index);
   int back_to_big_picture = editFrom(L, "teliva_editor_buffer", rowoff, coloff, cy, cx);
-  if (starts_with(Current_definition, "doc:")) return back_to_big_picture;
+  if (starts_with(Current_definition, "doc:")) {
+    load_editor_buffer_to_current_definition_in_image(L);
+    return back_to_big_picture;
+  }
   // error handling
   int oldtop = lua_gettop(L);
   while (1) {
@@ -808,6 +811,13 @@ static void update_definition(lua_State* L, const char* name, char* new_contents
 }
 
 extern void save_tlv(lua_State* L, char* filename);
+void load_editor_buffer_to_current_definition_in_image(lua_State* L) {
+  char new_contents[8192] = {0};
+  read_editor_buffer(new_contents, 8190);
+  update_definition(L, Current_definition, new_contents);
+  save_tlv(L, Image_name);
+}
+
 extern int docall(lua_State* L, int narg, int clear);
 int load_editor_buffer_to_current_definition_in_image_and_reload(lua_State* L) {
   char new_contents[8192] = {0};
@@ -824,7 +834,10 @@ int load_editor_buffer_to_current_definition_in_image_and_reload(lua_State* L) {
 extern int edit(lua_State* L, char* filename);
 static int edit_current_definition(lua_State* L) {
   int back_to_big_picture = edit(L, "teliva_editor_buffer");
-  if (starts_with(Current_definition, "doc:")) return back_to_big_picture;
+  if (starts_with(Current_definition, "doc:")) {
+    load_editor_buffer_to_current_definition_in_image(L);
+    return back_to_big_picture;
+  }
   // error handling
   int oldtop = lua_gettop(L);
   while (1) {
@@ -1109,6 +1122,7 @@ static int load_definitions(lua_State* L) {
         break;
       }
       if (is_special_history_key(key)) continue;
+      if (starts_with(key, "doc:")) continue;
       if (binding_exists(L, key))
         continue;  // most recent binding trumps older ones
       const char* value = lua_tostring(L, -1);
diff --git a/src/teliva.h b/src/teliva.h
index e991313..7a27779 100644
--- a/src/teliva.h
+++ b/src/teliva.h
@@ -158,6 +158,7 @@ extern void permissions_mode(lua_State* L);
 extern int file_operation_permitted(const char* filename, const char* mode);
 extern int net_operations_permitted;
 
+extern void load_editor_buffer_to_current_definition_in_image(lua_State* L);
 extern int load_editor_buffer_to_current_definition_in_image_and_reload(lua_State* L);
 extern void save_to_current_definition_and_editor_buffer(lua_State* L, const char* definition);
 extern void save_editor_state(int rowoff, int coloff, int cy, int cx);