To Chris, or whomever it may concern:

I modified RubyPairMatcher and, more significantly, RubyHeuristicMatcher to
support matching of more than just {}()[] brackets.



Now it will match class/end, def/end, if/end, unless/end, begin/end,
module/end and, best of all do/end.



The pair matcher is the code used to highlight a matching bracket when you
move the caret over an opening or closing bracket, and also to jump to the
matching bracket if you use Navigate->Go To Matching Bracket (Ctrl+Shift+P)



I find this really handy (which is why I implemented basically - the old
Open Source standard of implement what you need yourself) especially given
the way that ruby files tend to be filled with confusing piles of nested
"ends".



There are plenty of limitations of course, including

  - There's no support for matches with "middle keywords" such as
  matching 'else' with 'if' or 'end', etc.
  - Only the first and last chars are highlighted, not the whole word.
  Unfortunately this seems to be built into the core eclipse code that calls
  the pair matcher - it's only made for single-char brackets.





The code is tricky as it has to handle all of those pairs with the same
closing peer: "end". But it's fairly generic, drawing it's pairs from the
constant array of pairs at the top of RubyHeuristicMatcher. Add a new pair
there, like TokenFOO, TokenBAR, and it will match on those too.



It also handle's the tricky case of conditional modifiers and even takes
line continuations (where a line ends with a backslash indicating that it
continues to the next line) into account.

E.g. in this code:

  begin

    puts "dog"

    if (false); end



the final "end" will match the "if" on the same line, but in this version



   begin

     puts "dog" \

     if (false); end



it will match the "begin" because the if(false) is a conditional modifier
for the "puts" statement



I tried not to mess with too much existing code, but I did remove the old
matchPairsAt() method from RubyPairMatcher and I also removed from
RubyHeuristicMatcher the method  isBracelessBlockStart because there's no
such thing in Ruby, and this seemed a hangover from the JDT version of the
class (and it wasn't used).



So this is all local at the moment, how can I best get it to you to
contribute it? Files? Diffs? Patches? Check in?


rhugards,

Rhubarb
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rubyeclipse-development mailing list
Rubyeclipse-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rubyeclipse-development

Reply via email to