about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-01-25 23:07:43 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-01-25 23:07:43 -0800
commit32d86bfc7f375a288a67549e95faea788da44d04 (patch)
tree2f457d04e061b03bf3293c0b3827c8c049c6b310 /src
parent7fd434a692d6f6b7d6d1ef2c4fd447c6492483c4 (diff)
downloadteliva-32d86bfc7f375a288a67549e95faea788da44d04.tar.gz
override big picture view with doc:bp if it exists
Going to big picture from doc:bp still goes to the default
auto-generated big picture view.

While doc:bp provides some programmability, it's also far klunkier than
the default view. Rendering is worse, and it's always in edit mode
because I'm trying to avoid complicating the UX with a notion of
rendered markup. That means cursor movement is less convenient. It's
also easy to accidentally edit the big-picture view.
Diffstat (limited to 'src')
-rw-r--r--src/teliva.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/teliva.c b/src/teliva.c
index 7e769c9..b588829 100644
--- a/src/teliva.c
+++ b/src/teliva.c
@@ -359,7 +359,7 @@ static int starts_with(const char* s, const char* pre) {
 static int edit_current_definition(lua_State* L);
 static void recent_changes_view(lua_State* L);
 static const char* events_view();
-void big_picture_view(lua_State* L) {
+void default_big_picture_view(lua_State* L) {
   /* Without any intervening edits, big_picture_view always stably renders
    * definitions in exactly the same spatial order, both in levels from top to
    * bottom and in indexes within each level from left to right. */
@@ -622,6 +622,23 @@ restart:
   /* never gets here */
 }
 
+static int look_up_definition (lua_State* L, const char* name);
+extern int editProse(lua_State* L, char* filename);
+void big_picture_view(lua_State* L) {
+  int oldtop = lua_gettop(L);
+  if (!look_up_definition(L, "doc:bp")) {
+    default_big_picture_view(L);
+  } else {
+    FILE* out = fopen("teliva_big_picture", "w");
+    fprintf(out, "%s", lua_tostring(L, -1));
+    fclose(out);
+    int back_to_big_picture = editProse(L, "teliva_big_picture");
+    if (back_to_big_picture)
+      default_big_picture_view(L);
+  }
+  lua_settop(L, oldtop);
+}
+
 /* return true if:
  *  - editor_state exists, and
  *  - editor_state is applicable to the current image
@@ -870,7 +887,6 @@ int load_editor_buffer_to_current_definition_in_image_and_reload(lua_State* L) {
 /* return true if user chose to back into the big picture view */
 /* But only if there are no errors. Otherwise things can get confusing. */
 extern int edit(lua_State* L, char* filename);
-extern int editProse(lua_State* L, char* filename);
 static int edit_current_definition(lua_State* L) {
   if (starts_with(Current_definition, "doc:")) {
     int back_to_big_picture = editProse(L, "teliva_editor_buffer");