// FRMT_V.VDM - Format block programs for improved readability // 6 Feb 1996 (Requires 4.2) // Latest change: 13 June 2003 Force BOF, disable WordWrap // Author:- // Ian Binnie // 8 Berripa Close // East Ryde 2113 // Australia // // The first part of this program may be used to format // any block structured program e.g. VEDIT Macros // // Numeric codes are use to search for (,),{,} // Numeric registers 40 - 46 are used // // Use default indent increment of 4 if not set if(Config(PG_IND_INC)==0) { Config(PG_IND_INC, 4) } #40=Config(PG_IND_INC) Config( W_WORD_WRAP, 0) // // First some general tidy up (remove formatting) // // strip leading whitespace from outer program blocks // lines outside blocks are not affected // a program block is all contained between {...} Begin_Of_File() REPEAT(ALL) { Search("|123",ERRBREAK) Block_Begin(Cur_Pos) Match_Paren() Block_End(Cur_Pos+1) Goto_Pos(Block_Begin) Search("|<|W",REVERSE|NOERR) Replace_Block("|<|W","",CP,Block_End,ALL|NOERR) Goto_Pos(Block_End) } Block_Begin(CLEAR) // now ensure that all blocks start on a new line // unless the block is on a single line Begin_Of_File() REPEAT(ALL) { Search("|123",ERRBREAK) if(Cur_Col==1) { Char(1) Continue } // OK - at start of line #45=Cur_Pos #43=Cur_Line Match_Paren() #44=Cur_Line Goto_Pos(#45) // restore position if(#44>#43) { Ins_Newline(1) } // not on same line Char(1) } // strip trailing whitespace Replace("|W|>","",BEGIN|ALL|NOERR) // now ensure that all blocks end on a clear line // unless the block is followed by a comment Begin_Of_File() REPEAT(ALL) { Search("|125",ERRBREAK) #45=Cur_Pos #43=Cur_Col End_Of_Line() if(Cur_Col-#43==1) { Continue } // OK - at end of line Goto_Pos(#45+1) // position after end of block // check if followed by comment if(Match("|[|W]/|{/,*}")==0) { Continue } // OK Ins_Newline(1) Replace("|<|W","",NOERR) } // // Now the real task begins Begin_Of_File() // locate & mark outer program block REPEAT(ALL) { Search("|123",ERRBREAK) Call("indnt_blk") } // // Main task finished // tidy up & finish Return() // routine to indent block // on entry current position is start of block // on exit current position is end of block :indnt_blk: #43=Cur_Line Block_Begin(Cur_Pos) Match_Paren() #46=Cur_Pos #44=Cur_Line Block_End(Cur_Pos+1) Goto_Pos(Block_End) if(#43==#44) { return() } // block on one line Do_Visual("\ID\") //relocate beginning & end of block as it may have moved Goto_Line(#43) Search("|123",ERRBREAK) #45=Cur_Pos Match_Paren() #46=Cur_Pos Block_Begin(CLEAR) Goto_Pos(#45+1) // point past beginning of block // search for inner block REPEAT(ALL) { Search("|123",ERRBREAK) if(Cur_Line>#44) { // outside block:- so no inner block found Goto_Pos(#45) Match_Paren() // position at end of block Return() } Num_Push(44,45) //save regs Call("indnt_blk") // recursively call subroutine to indent inner block Num_Pop(44,45) } Goto_Pos(#45) Match_Paren() // position at end of block Return()