! format.tec - program to reformat a block of text ! +0UW ! call: :EIformat$ or n:EIformat$ where n is width ! QW"E 70UW ' ! iif no width set width to 70 ! 20W ! set screen height to 20 lines ! !again! ! process again ! @^A% Position Cursor at start of block to format and press "." for start of block or press Esc to quit.% < ! loop ! 20:@EI%cursor%UC ! screen height is 20 lines let user ! ! navigate with cursor keys, return ! ! terminating char, stor in C.num ! QC-^^."E @O!dot! ' ! iif "." goto dot process ! QC-27"E $^[ ' ! iif exit ! 7^T ! if none of the above, beep ! > ! end loop ! !dot! .UF ! remember "from" position ! ::CUI ! remember possible indent ! @^A% Position Cursor at end of block to format and press "Enter" to format block or press Esc to try again.% < ! loop ! 20:@EI%cursor%UC ! screen height is 20 lines let user ! ! navigate with cursor keys, return ! ! terminating char, stor in C.num ! QC-13"E @O!format! ' ! iif enter go to format ! QC-27"E Oagain ' ! iif go again ! 7^T ! if none of the above, beep ! > ! end loop ! !format! .-QF"G Ook ' ! iif we have a valid block ok ! @^A% Block out of range% ! otherwise error message ! @O!again! ! go again ! !ok! QF,.XA ! place block of text to be re-formated ! ! into A.str ! QF,.K ! then kill it from current buffer (0) ! 1B ! select buffer 1 ! HK ! kill contents of buffer 1 ! QI/8<@I% %> ! insert indent # chars/8 tabs ! QI&7<@I% %> ! insert indent # chars mod 8 spaces ! ! at this time we use spaces not tabs ! HXI ! save text of indent ! GA ! tack on text to be reformated ! J <:@FD~-^E#^ES^M^J^E#^ES~;> ! delete all "-[][]" ! ! (un-hyphenate words) ! <:@FS~^E#^ES^M^J^E#^ES~ ~;> ! replace all "[][]" ! ! with " " ! -QI%W$ ! reduce the specified width by the indent ! < ! loop ! QW:C; ! advance width-indent # characters ! ! return success/fail, exit loop fail ! -@FS% % % ! replace current or preceeding ! ! with ! GI ! insert indent ! > ! end loop ! ZJ ! go to end of buffer ! -1A-10"N ! if previous character NOT ! @I% % ! insert ! ' ! endif ! HXA ! put everything into A.str ! 0B ! go back to our spot in buffer 0 ! GA ! insert formatted text into buffer ! @O!again! ! try again !