                { --- Block command subroutines }

procedure block_hide_display;
begin
block_flag:=not block_flag;
display_rest_page(page_top_index,1,SCREENTOP);
end; { block_hide_display }

procedure begin_block;
begin
block_begin:=index; block_flag:=(block_begin<=block_end);
display_rest_page(page_top_index,1,SCREENTOP);
end; { begin_block }

procedure end_block;
begin
block_end:=index-1; block_flag:=(block_begin<=block_end);
display_rest_page(page_top_index,1,SCREENTOP);
end; { end_block }

procedure mark_single_word;
begin
block_begin:=index;
while (block_begin>1) and (text[block_begin-1] in alphanums) do
    block_begin:=block_begin-1;
while (block_end<text_length) and (text[block_end+1] in alphanums) do
    block_end:=block_end+1;
block_flag:=(block_begin<=block_end);
display_rest_page(page_top_index,1,SCREENTOP);
end; { mark_single_word }

procedure copy_text(copy:boolean);
label exit;
var i,l,cr_count:integer;
begin
if not block_flag then goto exit;
l:=block_end-block_begin+1;
if (l>0) and (text_length+l<TMAX) then
    begin
    cr_count:=0;
    for i:=block_begin to block_end do
        if eol(i) then cr_count:=cr_count+1;
    if (block_begin>=index) then
        begin
        block_begin:=block_begin+l;
        block_end:=block_end+l;
        end
    else if block_end>=index then goto exit;
    for i:=text_length downto index do text[i+l]:=text[i];
    for i:=0 to l-1 do text[index+i]:=text[block_begin+i];
    text_length:=text_length+l;
    if copy then
        begin
        block_begin:=index;
        block_end:=block_begin+l-1;
        n_lines:=n_lines+cr_count;
        end
    else
        begin
        block_end:=index; index:=block_begin;
        delete_chars(l,false);
        index:=block_end; block_begin:=index; block_end:=block_begin+l-1;
        end;
    find_page(index,cx,cy);
    display_rest_page(page_top_index,1,SCREENTOP);
    end;
exit:
end; { copy_text }

procedure copy_block;
begin copy_text(true); end;

procedure move_block;
begin copy_text(false); end;

procedure delete_block;
var k:integer;
begin
if block_flag then
    begin
    k:=block_end-block_begin+1;
    if k>0 then
        begin
        index:=block_begin;
        find_page(index,cx,cy);
        delete_chars(k,true);
        block_flag:=false;
        end;
    end;
end; { delete_block }

