From c5f6e30042fe45dc5c2d3b1ce8db6da468e48bbd Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 25 Jan 2022 20:29:35 -0800 Subject: [PATCH] start supporting non-code "buffers" First step: when a "definition" starts with "doc:" it's not a definition, just a buffer. Stop trying to interpret it as Lua. --- src/teliva.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/teliva.c b/src/teliva.c index 39a1d76..d1d3f22 100644 --- a/src/teliva.c +++ b/src/teliva.c @@ -632,6 +632,10 @@ void draw_callers_of_current_definition(lua_State* L) { assert(oldtop == lua_gettop(L)); } +static int starts_with(const char* s, const char* pre) { + return strncmp(pre, s, strlen(pre)) == 0; +} + extern int load_editor_buffer_to_current_definition_in_image(lua_State* L); extern int resumeEdit(lua_State* L); extern int editFrom(lua_State* L, char* filename, int rowoff, int coloff, int cy, int cx); @@ -651,6 +655,7 @@ 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; // error handling int oldtop = lua_gettop(L); while (1) { @@ -820,6 +825,7 @@ extern int load_editor_buffer_to_current_definition_in_image(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; // error handling int oldtop = lua_gettop(L); while (1) {