about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-30 17:23:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-30 17:26:46 -0700
commit32f123259441d0210d499595d56fc70fa4ce50ca (patch)
tree02b3184d0ada4ad220fcac3e4c5003eecf9a11cc
parent57a8a8e7186a32c59c2a9a19aa1868093ac87419 (diff)
downloadmu-32f123259441d0210d499595d56fc70fa4ce50ca.tar.gz
1898
-rw-r--r--edit.mu119
1 files changed, 61 insertions, 58 deletions
diff --git a/edit.mu b/edit.mu
index 692132bf..88226a66 100644
--- a/edit.mu
+++ b/edit.mu
@@ -1,4 +1,7 @@
-# Environment for learning programming using mu.
+# Environment for learning programming using mu: http://akkartik.name/post/mu
+#
+# Consists of one editor on the left for recipes and one on the right for the
+# sandbox.
 
 recipe main [
   local-scope
@@ -13,13 +16,7 @@ recipe main [
   # never gets here
 ]
 
-container programming-environment-data [
-  recipes:address:editor-data
-  recipe-warnings:address:array:character
-  current-sandbox:address:editor-data
-  sandbox:address:sandbox-data
-  sandbox-in-focus?:boolean  # false => focus in recipes; true => focus in current-sandbox
-]
+## the basic editor data structure, and how it displays text to the screen
 
 scenario editor-initially-prints-string-to-screen [
   assume-screen 10/width, 5/height
@@ -34,9 +31,6 @@ scenario editor-initially-prints-string-to-screen [
   ]
 ]
 
-## In which we introduce the editor data structure, and show how it displays
-## text to the screen.
-
 container editor-data [
   # editable text: doubly linked list of characters (head contains a special sentinel)
   data:address:duplex-list
@@ -2325,8 +2319,15 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [
   ]
 ]
 
-## the environment consists of one editor on the left for recipes and one on
-## the right for the sandbox
+## putting the environment together out of editors
+
+container programming-environment-data [
+  recipes:address:editor-data
+  recipe-warnings:address:array:character
+  current-sandbox:address:editor-data
+  sandbox:address:sandbox-data
+  sandbox-in-focus?:boolean  # false => focus in recipes; true => focus in current-sandbox
+]
 
 recipe new-programming-environment [
   local-scope
@@ -2663,7 +2664,7 @@ recipe update-cursor [
   move-cursor screen, cursor-row, cursor-column
 ]
 
-## Running code from the editors
+## running code from the editor and creating sandboxes
 
 container sandbox-data [
   data:address:array:character
@@ -2997,50 +2998,6 @@ recipe render-screen [
   reply row/same-as-ingredient:4, screen/same-as-ingredient:0
 ]
 
-after +global-touch [
-  # on a sandbox delete icon? process delete
-  {
-    was-delete?:boolean <- delete-sandbox *t, env
-    break-unless was-delete?
-#?     trace [app], [delete clicked] #? 1
-    screen <- render-sandbox-side screen, env, 1/clear
-    update-cursor screen, recipes, current-sandbox, *sandbox-in-focus?
-    show-screen screen
-    loop +next-event:label
-  }
-]
-
-# was-deleted?:boolean <- delete-sandbox t:touch-event, env:address:programming-environment-data
-recipe delete-sandbox [
-  local-scope
-  t:touch-event <- next-ingredient
-  env:address:programming-environment-data <- next-ingredient
-  click-column:number <- get t, column:offset
-  current-sandbox:address:editor-data <- get *env, current-sandbox:offset
-  right:number <- get *current-sandbox, right:offset
-  at-right?:boolean <- equal click-column, right
-  reply-unless at-right?, 0/false
-  click-row:number <- get t, row:offset
-  prev:address:address:sandbox-data <- get-address *env, sandbox:offset
-  curr:address:sandbox-data <- get *env, sandbox:offset
-  {
-    break-unless curr
-    # more sandboxes to check
-    {
-      target-row:number <- get *curr, starting-row-on-screen:offset
-      delete-curr?:boolean <- equal target-row, click-row
-      break-unless delete-curr?
-      # delete this sandbox, rerender and stop
-      *prev <- get *curr, next-sandbox:offset
-      reply 1/true
-    }
-    prev <- get-address *curr, next-sandbox:offset
-    curr <- get *curr, next-sandbox:offset
-    loop
-  }
-  reply 0/false
-]
-
 scenario run-updates-results [
   $close-trace  # trace too long for github
   assume-screen 100/width, 12/height
@@ -3180,6 +3137,8 @@ scenario run-instruction-and-print-warnings-only-once [
   ]
 ]
 
+## deleting sandboxes
+
 scenario deleting-sandboxes [
   $close-trace  # trace too long for github
   assume-screen 100/width, 15/height
@@ -3246,6 +3205,50 @@ scenario deleting-sandboxes [
   ]
 ]
 
+after +global-touch [
+  # on a sandbox delete icon? process delete
+  {
+    was-delete?:boolean <- delete-sandbox *t, env
+    break-unless was-delete?
+#?     trace [app], [delete clicked] #? 1
+    screen <- render-sandbox-side screen, env, 1/clear
+    update-cursor screen, recipes, current-sandbox, *sandbox-in-focus?
+    show-screen screen
+    loop +next-event:label
+  }
+]
+
+# was-deleted?:boolean <- delete-sandbox t:touch-event, env:address:programming-environment-data
+recipe delete-sandbox [
+  local-scope
+  t:touch-event <- next-ingredient
+  env:address:programming-environment-data <- next-ingredient
+  click-column:number <- get t, column:offset
+  current-sandbox:address:editor-data <- get *env, current-sandbox:offset
+  right:number <- get *current-sandbox, right:offset
+  at-right?:boolean <- equal click-column, right
+  reply-unless at-right?, 0/false
+  click-row:number <- get t, row:offset
+  prev:address:address:sandbox-data <- get-address *env, sandbox:offset
+  curr:address:sandbox-data <- get *env, sandbox:offset
+  {
+    break-unless curr
+    # more sandboxes to check
+    {
+      target-row:number <- get *curr, starting-row-on-screen:offset
+      delete-curr?:boolean <- equal target-row, click-row
+      break-unless delete-curr?
+      # delete this sandbox, rerender and stop
+      *prev <- get *curr, next-sandbox:offset
+      reply 1/true
+    }
+    prev <- get-address *curr, next-sandbox:offset
+    curr <- get *curr, next-sandbox:offset
+    loop
+  }
+  reply 0/false
+]
+
 scenario run-instruction-manages-screen-per-sandbox [
   $close-trace  # trace too long for github #? 1
   assume-screen 100/width, 20/height