                  { --- Insert/overwrite subroutines --- }

procedure insert_mode_on_off;
begin
insert_flag:=not insert_flag;
if insert_flag then write(cursor2) else write(cursor1);
end; { insert_mode_on_off }

procedure insert_char(ch:char);   { inserts character at position index }
var i,j:integer;
begin
if move_up(1) then
    begin
    text[index]:=ch;
    if block_flag then
        begin
        if index<block_begin then block_begin:=block_begin+1;
        if index<=block_end+1 then block_end:=block_end+1;
        end;
    if ch=CR then
        begin
        n_lines:=n_lines+1;
        find_page_bottom_line;
        find_page_bottom_index;
        display_rest_page(index,cx,cy);
        end
    else
        begin
        if index<page_bottom_index then page_bottom_index:=page_bottom_index+1;
        display_rest_line(index,cx,cy);
    end;
    character_right;
    end;
end; { insert_char }

procedure insert_line;
begin insert_char(CR); character_left; end;

procedure carriage_return;
begin
if insert_flag then insert_char(CR)
else begin index:=index+ch_to_eol(index); character_right; end;
end; { carriage_return }

procedure text_character;
var tabflag:boolean;
begin
if insert_flag then insert_char(ch)
else
    begin
    if text[index]=CR then insert_char(ch)
    else
        begin
        tabflag:= (text[index]=TAB) or (ch=TAB);
        text[index]:=ch;
        if tabflag then
            begin display_rest_line(index,cx,cy); character_right; end
        else begin display_char(index,cx,cy); index:=index+1; end;
        end;
    end;
end; { text_character }
