Why isn't there an easier way to align blocks of code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Bulgrien
    Carpal Tunnel
    • Oct 2007
    • 1772

    Why isn't there an easier way to align blocks of code?

    screencast
    BC v4.0.7 build 19761
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • Chris
    Team Scooter
    • Oct 2007
    • 5538

    #2
    Michael,

    This is a limitation of the alignment algorithm we use. "Align With" only lines up a single line at a time. In the Text Compare, it aligns a single line, but can automatically realign some of the text after it. The algorithm used to align text is more complicated in the merge because it is aligning three things instead of two, so it currently only aligns a single line and doesn't realign anything after that. We would like to improve this in the future. When I talked to our developers about it, the main issue is coming up with a better alignment algorithm, so it is a long term goal rather than a change we'll be able to make quickly.
    Chris K Scooter Software

    Comment

    • imurphy
      New User
      • Jan 2009
      • 2

      #3
      Not sure if anyone will see this as its an old post...

      A possible compromise would be to be able to restart the compare from the last aligned position. This way you could correct the alignment using F7 and then restart the compare process from this point.

      Ian

      Comment

      • imurphy
        New User
        • Jan 2009
        • 2

        #4
        Possible solution?

        As a possible solution, a 'recompare from here' function may achieve desired the effect of aligning a block of code.

        In my case 'recompare from here' would certainly have done what I wanted.

        Comment

        • dr_barnowl
          Expert
          • Apr 2008
          • 71

          #5
          Grammar-based alignment

          I'd like to see more grammar-based alignment.

          For example ; I'm merging XML model files. I'd love multi-line grammar that could
          • Denote a region bounded by delimiters or a regex as an "alignment block"
          • Place great weight on aligning blocks with the same identifier
          • Treat the region between the beginning and end of the node as a sub-document for alignment purposes.


          It would also be really nice if it remembered the block-order for each side, but was able to shuffle blocks to align on screen (perhaps with horizontal lines like the context mode to show you you're not dealing with linear files). VB3 used to "juggle" routines, so we had an converter that sorted the file per-routine for comparison, but we never implemented the inverse transform, so our compares had to be read-only with the file open in the IDE for editing.

          XML writing applications "juggle" even more, which I find tremendously annoying for version control purposes, but is a natural consequence of the internal implementation of many XML using tools.

          A system that could align blocks-composed-of-blocks would work for most sorts of code and tidied XML too.

          Comment

          • dr_barnowl
            Expert
            • Apr 2008
            • 71

            #6
            kdiff3 line-matching preprocessor

            Hunting around a bit, I quite like the sound of a solution in kdiff3 ; a line-matching pre-processor.

            First, it runs any "normal" preprocessor, then it runs another one which produces 1 line per line of input.

            It displays and works with data that's the output of the first stage, but matches lines based on the output of the line-matching stage.

            They have an example here

            Scooter can be proud that their code aligns the example in the "after" way without any special treatment! But I think the line-matching preprocessor feature could be implemented fairly quickly in BC3 - I'm going to be giving it a try in kdiff3 to see if it solves this particular problem.

            kdiff3 doesn't have a post-processor like BC3 does, so I'll have to use a wrapper script.

            Comment

            • geo_love
              Visitor
              • Jul 2009
              • 4

              #7
              Aligning blocks

              I'd like to re-visit the original post in the thread - the idea of manually aligning a block rather than a single line.

              I'm sure there is far more involved than I realize, but it seems on the surface to be a fairly straight-forward bit of work to select a contiguous block of lines on one window, click F7, then click a single line on the opposite window and have the result be a forced alignment between the lines in the block and a corresponding number of lines from the opposite window.

              What do you think?

              Comment

              • tlscales
                Expert
                • Oct 2007
                • 74

                #8
                I've actually run into a couple of situations in the last couple of days where this feature would have come in very handy. Often, if I have C++ or C# code with several similar methods, and add a new method in the middle of the file, comparing the versions lines up until the middle of one method, doesn't match the last part of the new method or the first part of the next, then finally lines up again for the last part of the next method. If I manually align the next line that should match up, sometimes this fixes the mismatch, but other times it just moves the break down a line or two.

                Ideally, I'd like to see alignment work as it does now if a single line is selected, but if a set of lines (the remainder of my mismatched method, in the cases I've been running into) is selected, I'd like it to prompt me to select a group of lines to align to (right click, drag the mouse to the end of the selection, release the button, then align, rather than aligning immediately on the click). Within the selection, the compare should take its best shot at comparing (usually, these sections are identical in the cases I've been running into), then continue as normal after the selected alignment section.

                Comment

                • Michael Bulgrien
                  Carpal Tunnel
                  • Oct 2007
                  • 1772

                  #9
                  Originally posted by geo_love
                  ...select a contiguous block of lines on one window, click F7, then click a single line on the opposite window and have the result be a forced alignment between the lines in the block and a corresponding number of lines from the opposite window
                  From your post, I'm not sure if you understand how Align With currently works... perhaps you do and are simply suggesting additional functionality. After selecting a contiguous block of lines on one side and pressing F7, select the contiguous block of lines on the other side that you wish to Align with (instead of a single click). When you release the drag that selects the lines on the other side, the selections on each side will be aligned to one another.

                  I agree that a single click solution would be nice. Making the second selection was not intuitive to me and took me a while to figure out...
                  BC v4.0.7 build 19761
                  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                  Comment

                  • geo_love
                    Visitor
                    • Jul 2009
                    • 4

                    #10
                    Mike, thanks for the feedback. That is the answer I was looking for. I agree too that having to select the target block is a bit counter-intuitive.

                    But, to be fair, I can imagine situations where I would like a source block to align with empty space on the target side. So you can't really blame the developers for having us identify the target block.

                    Thanks again for your feedback.

                    Comment

                    • JanusLazarus
                      New User
                      • Aug 2010
                      • 2

                      #11
                      Originally posted by Michael Bulgrien
                      ...
                      After selecting a contiguous block of lines on one side and pressing F7, select the contiguous block of lines on the other side that you wish to Align with (instead of a single click). When you release the drag that selects the lines on the other side, the selections on each side will be aligned to one another.
                      ...
                      It does not appear to be working that way in Beyond Compare 3.1.1 (build 12204). If I select a range of lines and press F7, a blue bar lights up next to the last line of the selection. Then I select another range of lines on another pane, and only the last lines of each range get aligned to each other. The rest of the lines stay unaligned.

                      That means I have to align one line at a time, and that is extremely unproductive. I understand you are having a difficulty designing an algorithm to handle three-way realignment automatically. In the meantime, implementing what Michael Bulgrien described would be a very useful stopgap. Surely you can write a For loop to extend what you already do with one pair of lines to multiple pairs? Thanks!

                      Comment

                      • Aaron
                        Team Scooter
                        • Oct 2007
                        • 16000

                        #12
                        Hello,

                        If you select multiple lines in the Text Compare session, and then press F7 or right click and select Align, you should see a light blue gutter bar for the entire selection. Other behavior would be unexpected.

                        If this is not the behavior you are seeing, could you email us a full screen screenshot and a copy of your BCSupport.zip (from the Help menu -> Support; Export). Please also include a link back to this forum post.
                        Aaron P Scooter Software

                        Comment

                        • Aaron
                          Team Scooter
                          • Oct 2007
                          • 16000

                          #13
                          For the Text Merge session type, it is on our Wishlist to add this feature.
                          Aaron P Scooter Software

                          Comment

                          • JanusLazarus
                            New User
                            • Aug 2010
                            • 2

                            #14
                            Yes, I was talking about Text Merge -- sorry about being unclear. I am glad you are looking into it.

                            Comment

                            Working...