relayout Function

private function relayout(text, changed, opts) result(out)

text with the statements at changed (byte ranges, in order) laid out again, each on its own at the column where it starts. text is formatted apart from those statements, and they do not depend on the lines around them (see stands_alone), so this gives what formatting the whole text again would, in a fraction of the time.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

the text, after lines were split

integer, intent(in) :: changed(:,:)

byte ranges of the statements to lay out

type(format_options_t), intent(in) :: opts

the formatting options

Return Value character(len=:), allocatable


Calls

proc~~relayout~~CallsGraph proc~relayout relayout proc~builder_append string_builder_t%builder_append proc~relayout->proc~builder_append proc~builder_get string_builder_t%builder_get proc~relayout->proc~builder_get proc~format_pass format_pass proc~relayout->proc~format_pass proc~analyze_structure analyze_structure proc~format_pass->proc~analyze_structure proc~compute_case compute_case proc~format_pass->proc~compute_case proc~compute_gaps compute_gaps proc~format_pass->proc~compute_gaps proc~layout layout proc~format_pass->proc~layout proc~parse_source parse_source proc~format_pass->proc~parse_source proc~set_views set_views proc~format_pass->proc~set_views proc~to_s to_s proc~format_pass->proc~to_s proc~analyze_structure->proc~to_s proc~classify_statement classify_statement proc~analyze_structure->proc~classify_statement proc~closes closes proc~analyze_structure->proc~closes proc~conditional_kind conditional_kind proc~analyze_structure->proc~conditional_kind proc~construct_label construct_label proc~analyze_structure->proc~construct_label proc~fypp_depths fypp_depths proc~analyze_structure->proc~fypp_depths proc~middle_fits middle_fits proc~analyze_structure->proc~middle_fits proc~stack_push scope_stack_t%stack_push proc~analyze_structure->proc~stack_push proc~stack_restore scope_stack_t%stack_restore proc~analyze_structure->proc~stack_restore proc~stack_snapshot scope_stack_t%stack_snapshot proc~analyze_structure->proc~stack_snapshot proc~token_lower token_lower proc~analyze_structure->proc~token_lower proc~kind_part kind_part proc~compute_case->proc~kind_part proc~names_case names_case proc~compute_case->proc~names_case proc~statement_case statement_case proc~compute_case->proc~statement_case proc~comment_gaps comment_gaps proc~compute_gaps->proc~comment_gaps proc~statement_gaps statement_gaps proc~compute_gaps->proc~statement_gaps proc~layout->proc~builder_get proc~emit_blank emit_blank proc~layout->proc~emit_blank proc~emit_comment_line emit_comment_line proc~layout->proc~emit_comment_line proc~emit_fypp_line emit_fypp_line proc~layout->proc~emit_fypp_line proc~emit_range emit_range proc~layout->proc~emit_range proc~emit_statement emit_statement proc~layout->proc~emit_statement proc~protected_items protected_items proc~parse_source->proc~protected_items proc~split_statements split_statements proc~parse_source->proc~split_statements proc~tokenize tokenize proc~parse_source->proc~tokenize proc~set_view set_view proc~set_views->proc~set_view proc~closed_construct closed_construct proc~classify_statement->proc~closed_construct proc~expand_keyword expand_keyword proc~classify_statement->proc~expand_keyword proc~read_label read_label proc~classify_statement->proc~read_label proc~set set proc~classify_statement->proc~set proc~view_closing statement_view_t%view_closing proc~classify_statement->proc~view_closing proc~view_kind_of statement_view_t%view_kind_of proc~classify_statement->proc~view_kind_of proc~utf8_width utf8_width proc~comment_gaps->proc~utf8_width proc~put put proc~emit_blank->proc~put proc~token_text token_text proc~emit_blank->proc~token_text proc~emit_comment_line->proc~emit_range proc~comment_column comment_column proc~emit_comment_line->proc~comment_column proc~input_column input_column proc~emit_comment_line->proc~input_column proc~emit_comment_line->proc~put proc~emit_comment_line->proc~token_text proc~trim_blanks trim_blanks proc~emit_comment_line->proc~trim_blanks proc~emit_fypp_line->proc~emit_range proc~first_non_blank first_non_blank proc~emit_fypp_line->proc~first_non_blank proc~emit_fypp_line->proc~put proc~emit_range->proc~put proc~emit_range->proc~token_text proc~emit_statement->proc~emit_range proc~emit_statement->proc~token_lower proc~emit_statement->proc~comment_column proc~continuation_target continuation_target proc~emit_statement->proc~continuation_target proc~emit_body emit_body proc~emit_statement->proc~emit_body proc~emit_continuation emit_continuation proc~emit_statement->proc~emit_continuation proc~emit_statement->proc~first_non_blank proc~fitting_column fitting_column proc~emit_statement->proc~fitting_column proc~emit_statement->proc~input_column proc~emit_statement->proc~put proc~emit_statement->proc~token_text proc~fypp_depths->proc~token_lower proc~fypp_kind fypp_kind proc~fypp_depths->proc~fypp_kind proc~names_case->proc~view_kind_of proc~view_word statement_view_t%view_word proc~names_case->proc~view_word proc~directive directive proc~protected_items->proc~directive proc~make_lowercase make_lowercase proc~set_view->proc~make_lowercase proc~ends_with_continuation ends_with_continuation proc~split_statements->proc~ends_with_continuation proc~find_semicolon find_semicolon proc~split_statements->proc~find_semicolon proc~line_end_token line_end_token proc~split_statements->proc~line_end_token proc~line_kind line_kind proc~split_statements->proc~line_kind proc~push statement_list_t%push proc~split_statements->proc~push proc~stack_restore->proc~stack_push proc~statement_case->proc~view_closing proc~statement_case->proc~view_kind_of proc~statement_case->proc~view_word proc~is_chevron is_chevron proc~statement_gaps->proc~is_chevron proc~is_word is_word proc~statement_gaps->proc~is_word proc~statement_gaps->proc~view_kind_of proc~statement_gaps->proc~view_word proc~token_lower->proc~make_lowercase proc~add add proc~tokenize->proc~add proc~comment_kind comment_kind proc~tokenize->proc~comment_kind proc~dotop_at dotop_at proc~tokenize->proc~dotop_at proc~dotop_end dotop_end proc~tokenize->proc~dotop_end proc~fypp_inline_end fypp_inline_end proc~tokenize->proc~fypp_inline_end proc~is_blank is_blank proc~tokenize->proc~is_blank proc~is_digit is_digit proc~tokenize->proc~is_digit proc~is_preproc_start is_preproc_start proc~tokenize->proc~is_preproc_start proc~is_quote is_quote proc~tokenize->proc~is_quote proc~lex_number lex_number proc~tokenize->proc~lex_number proc~line_end line_end proc~tokenize->proc~line_end proc~name_end name_end proc~tokenize->proc~name_end proc~operator_end operator_end proc~tokenize->proc~operator_end proc~peek peek proc~tokenize->proc~peek proc~preproc_end preproc_end proc~tokenize->proc~preproc_end proc~string_end string_end proc~tokenize->proc~string_end proc~add->proc~is_blank proc~add->proc~peek proc~is_code_char is_code_char proc~add->proc~is_code_char proc~push~2 token_list_t%push proc~add->proc~push~2 proc~comment_column->proc~fitting_column proc~comment_column->proc~input_column proc~comment_kind->proc~peek proc~is_letter is_letter proc~comment_kind->proc~is_letter proc~lowercase lowercase proc~comment_kind->proc~lowercase proc~directive->proc~token_text proc~dotop_at->proc~peek proc~dotop_at->proc~is_letter proc~dotop_end->proc~name_end proc~dotop_end->proc~peek proc~is_name_char is_name_char proc~dotop_end->proc~is_name_char proc~dotop_end->proc~lowercase proc~emit_body->proc~kind_part proc~emit_body->proc~token_lower proc~emit_body->proc~input_column proc~emit_body->proc~put proc~line_pieces line_pieces proc~emit_body->proc~line_pieces proc~to_case to_case proc~emit_body->proc~to_case proc~emit_continuation->proc~emit_body proc~emit_continuation->proc~first_non_blank proc~emit_continuation->proc~fitting_column proc~emit_continuation->proc~input_column proc~emit_continuation->proc~put proc~first_piece_width first_piece_width proc~fitting_column->proc~first_piece_width proc~line_width line_width proc~fitting_column->proc~line_width proc~fypp_inline_end->proc~peek proc~input_column->proc~utf8_width proc~is_preproc_start->proc~peek proc~lex_number->proc~dotop_at proc~lex_number->proc~is_digit proc~lex_number->proc~name_end proc~lex_number->proc~peek proc~digits_end digits_end proc~lex_number->proc~digits_end proc~lex_number->proc~is_name_char proc~lower_char lower_char proc~lex_number->proc~lower_char proc~name_end->proc~peek proc~name_end->proc~is_name_char proc~preproc_end->proc~line_end proc~preproc_end->proc~peek proc~last_nonblank last_nonblank proc~preproc_end->proc~last_nonblank proc~put->proc~builder_append proc~put->proc~utf8_width proc~string_end->proc~is_blank proc~string_end->proc~line_end proc~string_end->proc~peek proc~only_blanks_to_eol only_blanks_to_eol proc~string_end->proc~only_blanks_to_eol proc~digits_end->proc~is_digit proc~digits_end->proc~peek proc~first_piece_width->proc~utf8_width proc~first_piece_width->proc~line_pieces proc~is_code_char->proc~is_blank proc~is_name_char->proc~is_digit proc~is_name_char->proc~is_letter proc~last_nonblank->proc~is_blank proc~line_width->proc~utf8_width proc~line_width->proc~line_pieces proc~lowercase->proc~lower_char proc~only_blanks_to_eol->proc~line_end proc~only_blanks_to_eol->proc~last_nonblank

Called by

proc~~relayout~~CalledByGraph proc~relayout relayout proc~format_text format_text proc~format_text->proc~relayout proc~process_text process_text proc~process_text->proc~format_text proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

function relayout(text, changed, opts) result(out)
    !! `text` with the statements at `changed` (byte ranges, in order) laid out again, each on its own
    !! at the column where it starts. `text` is formatted apart from those statements, and they do
    !! not depend on the lines around them (see [[stands_alone]]), so this gives what formatting the
    !! whole text again would, in a fraction of the time.
    character(len=*), intent(in) :: text                 !! the text, after lines were split
    integer, intent(in) :: changed(:, :)                 !! byte ranges of the statements to lay out
    type(format_options_t), intent(in) :: opts           !! the formatting options
    character(len=:), allocatable :: out
    type(format_options_t) :: alone
    type(diagnostic_t), allocatable :: unused(:)
    type(string_builder_t) :: buf
    character(len=:), allocatable :: piece
    integer :: j, next

    alone = opts
    next = 1
    do j = 1, size(changed, 2)
        associate (a => changed(1, j), b => changed(2, j))
            call buf%append(text(next:a - 1))
            alone%base_indent = verify(text(a:b)//'x', ' ') - 1    ! its indentation
            call format_pass(text(a:b), alone, piece, unused)
            call buf%append(piece)
            next = b + 1
        end associate
    end do
    call buf%append(text(next:))
    out = buf%get()
end function relayout