7
votes

I'm dealing with some code that has fantastically long methods (10k lines!) and some odd use of try-finally and try-except blocks. Some of the latter are long by themselves, and don't always have the try at the start of the method.

Obviously I'm trying to refactor the code, but in the meantime just being able to fix a couple of common pathologies would be much easier if I could jump to the start of a block and see what is happening there. When it's 20+ pages away finding it even with the CNPack rainbows ("code structure highlight") is just tedious.

I'm using D2010 and have GExperts (with DelForExp), CNPack and DDevExtensions installed, but I can't find anything that lets me jump from the try to the finally or back. Am I missing something? Is there another add-in that I can use that will get me this?

2
cnpack.org/index.php?lang=en has something some of us call "rainbow" it's enabled by default and you can clearly see the matching "end" for functions/procedures, loops, try-except/finally, etc.user497849
Yes, and I call it that too. It kinda helps a bit in this situation, but it's very easy to accidentally skip the end of one method/start of another and just keep following the blue line down as I hit page-dn repeatedly. Jumping 2000 lines in one key combo is much better.Móż

2 Answers

11
votes

GExperts have it in Editor Experts: "Move to Matching Delimiter", with the keyboard shortcut Ctrl+Alt+Right by default. If you invoke it repeatedly it cycles from try to the matching finally or except, to end, then back to try, and so on.

0
votes

If you are going to refactor the code, I'd advice you to name each Try Except/finally End code block and move it into a separate function/procedure within the main method.

Second advice, start with the inner most try except/finally end code block.

procedure class1.method1 ;
var
   anyVariables : ... ;
begin
 ....
 try 
 ....
 finally
 ... 
 end ;
 ....
end ;

.

procedure class1.method1 ;
var
   anyVariables : ... ;
   procedure first_try_finally_block ;
   begin 
      try 
      ....
      finally
      ... 
      end ;
   end ;
begin
 ....
 first_try_finally_block
 ....
end ;

I hope that this will help you to solve your problem.