anchor.diff:                  {true, lists:keydelete(SubId, #element.id, Subs)}
           end
       end, State).
  +
  +delete_element(SchemaId, ElementId, State) ->
  +    modify_schema(SchemaId,
  +        fun(#schema{elements = Elements, connections = Connections} = Schema) ->
  +            case lists:keyfind(ElementId, #element.id, Elements) of
  +                false -> {false, Schema};
  +                Sub ->
  +                    NewCons = del_element_connections(ElementId, Connections),
  +                    notify_sub_deletion(Sub),
  +                    NewElems = lists:keydelete(ElementId, #element.id, Elements),
  +                    {true, Schema#schema{connections = NewCons,
  +                                         elements = NewElems}}
  +            end
  +        end, State).
   
   modify_schema(SchemaId, Fun,
           #state{schemas = Schemas} = State) ->
  
positive.code:         {true, lists:keyreplace(SubId, #element.id, Subs, Sub)}
      end, State).
  
  delete_sub(SchemaId, SubId, State, Modifier) ->
      Modifier(SchemaId, fun(Subs) ->
          case lists:keyfind(SubId, #element.id, Subs) of
              false -> {false, Subs};
              Sub ->
  
negative.code:     get_last_id(Rest, max(Id, Last));
  get_last_id([#connection{id = Id} | Rest], Last) ->
      get_last_id(Rest, max(Id, Last)).
  
  del_element_connections(_ElementId, []) ->
      [];
  del_element_connections(ElementId,
          [#connection{source_id = ElementId} = Con | Rest]) ->
      notify_sub_deletion(Con),
      del_element_connections(ElementId, Rest);
  del_element_connections(ElementId,
          [#connection{target_id = ElementId} = Con | Rest]) ->
      notify_sub_deletion(Con),
      del_element_connections(ElementId, Rest);
  del_element_connections(ElementId, [Cur|Rest]) ->
      [Cur | del_element_connections(ElementId, Rest)].
  
  
  %%%===================================================================
  