Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Oct 2007
    Location
    Pennsylvania
    Posts
    1,772

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

    BC v4.0.7 build 19761
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

  2. #2
    Join Date
    Oct 2007
    Location
    Madison, WI
    Posts
    4,676

    Default

    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

  3. #3
    Join Date
    Jan 2009
    Posts
    2

    Default 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

  4. #4
    Join Date
    Jan 2009
    Posts
    2

    Default 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.

  5. #5
    Join Date
    Apr 2008
    Posts
    70

    Default 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.

  6. #6
    Join Date
    Apr 2008
    Posts
    70

    Default 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.

  7. #7
    Join Date
    Jul 2009
    Posts
    4

    Default 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?

  8. #8
    Join Date
    Oct 2007
    Location
    pittsburgh, PA
    Posts
    64

    Default

    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.

  9. #9
    Join Date
    Oct 2007
    Location
    Pennsylvania
    Posts
    1,772

    Default

    Quote Originally Posted by geo_love View Post
    ...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
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

  10. #10
    Join Date
    Jul 2009
    Posts
    4

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •