605 |
605 |
606 fun new_exec keywords state node proper_init command_id' (assign_update, command_exec, init) = |
606 fun new_exec keywords state node proper_init command_id' (assign_update, command_exec, init) = |
607 if not proper_init andalso is_none init then NONE |
607 if not proper_init andalso is_none init then NONE |
608 else |
608 else |
609 let |
609 let |
610 val (_, (eval, _)) = command_exec; |
|
611 |
|
612 val command_visible = visible_command node command_id'; |
610 val command_visible = visible_command node command_id'; |
613 val command_overlays = overlays node command_id'; |
611 val command_overlays = overlays node command_id'; |
614 val (command_name, blob_digests, blobs_index, span0) = the_command state command_id'; |
612 val (command_name, blob_digests, blobs_index, span0) = the_command state command_id'; |
615 val blobs = map (resolve_blob state) blob_digests; |
613 val blobs = map (resolve_blob state) blob_digests; |
616 val span = Lazy.force span0; |
614 val span = Lazy.force span0; |
617 |
615 |
618 val eval' = |
616 val eval' = |
619 Command.eval keywords (master_directory node) |
617 Command.eval keywords (master_directory node) (fn () => the_default illegal_init init span) |
620 (fn () => the_default illegal_init init span) (blobs, blobs_index) span eval; |
618 (blobs, blobs_index) span (#1 (#2 command_exec)); |
621 val prints' = |
619 val prints' = |
622 perhaps (Command.print command_visible command_overlays keywords command_name eval') []; |
620 perhaps (Command.print command_visible command_overlays keywords command_name eval') []; |
623 val exec' = (eval', prints'); |
621 val exec' = (eval', prints'); |
624 |
622 |
625 val assign_update' = assign_update_new (command_id', SOME exec') assign_update; |
623 val assign_update' = assign_update_new (command_id', SOME exec') assign_update; |
626 val init' = if command_name = Thy_Header.theoryN then NONE else init; |
624 val init' = if command_name = Thy_Header.theoryN then NONE else init; |
627 in SOME (assign_update', (command_id', (eval', prints')), init') end; |
625 in SOME (assign_update', (command_id', exec'), init') end; |
628 |
626 |
629 fun removed_execs node0 (command_id, exec_ids) = |
627 fun removed_execs node0 (command_id, exec_ids) = |
630 subtract (op =) exec_ids (Command.exec_ids (lookup_entry node0 command_id)); |
628 subtract (op =) exec_ids (Command.exec_ids (lookup_entry node0 command_id)); |
631 |
629 |
632 in |
630 in |
677 val common_command_exec = |
675 val common_command_exec = |
678 (case common of |
676 (case common of |
679 SOME id => (id, the_default Command.no_exec (the_entry node id)) |
677 SOME id => (id, the_default Command.no_exec (the_entry node id)) |
680 | NONE => (Document_ID.none, Command.init_exec ml_root)); |
678 | NONE => (Document_ID.none, Command.init_exec ml_root)); |
681 |
679 |
682 val (updated_execs, (command_id', (eval', _)), _) = |
680 val (updated_execs, (command_id', exec'), _) = |
683 (print_execs, common_command_exec, if initial then SOME init else NONE) |
681 (print_execs, common_command_exec, if initial then SOME init else NONE) |
684 |> (still_visible orelse node_required) ? |
682 |> (still_visible orelse node_required) ? |
685 iterate_entries_after common |
683 iterate_entries_after common |
686 (fn ((prev, id), _) => fn res => |
684 (fn ((prev, id), _) => fn res => |
687 if not node_required andalso prev = visible_last node then NONE |
685 if not node_required andalso prev = visible_last node then NONE |
696 |
694 |
697 val last_exec = |
695 val last_exec = |
698 if command_id' = Document_ID.none then NONE else SOME command_id'; |
696 if command_id' = Document_ID.none then NONE else SOME command_id'; |
699 val result = |
697 val result = |
700 if is_none last_exec orelse is_some (after_entry node last_exec) then NONE |
698 if is_none last_exec orelse is_some (after_entry node last_exec) then NONE |
701 else SOME eval'; |
699 else SOME (#1 exec'); |
702 |
700 |
703 val assign_update = assign_update_result assigned_execs; |
701 val assign_update = assign_update_result assigned_execs; |
704 val removed = maps (removed_execs node0) assign_update; |
702 val removed = maps (removed_execs node0) assign_update; |
705 val _ = List.app Execution.cancel removed; |
703 val _ = List.app Execution.cancel removed; |
706 |
704 |