Announcement

Collapse
No announcement yet.

Strict comparisions: align only if exact match

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • Strict comparisions: align only if exact match

    I'm looking for a way to align based on a strictly comparison of part a line. For example,

    FILE1:
    cat=1
    dog=1
    horse=1


    FILE2:
    cat=1
    frog=1
    horse=1


    BC partial matches dog to frog and aligns them, but as variables these are completely different. Thus, I'd like a strict comparison that says if some expression does not match, like (^\w+=), then lines should not align.

    Is this possible? Seems like there should be a "Strict" checkbox for grammar. Or better yet, strictly match only part of a RegEx by allowing users to specify which groups of the RegEx must match. E.g., set (^\s*)(\w+)(\s*=) then specify a strict match only on $2, which, assuming my noob RegEx is right, should exactly match the word between the start of a line and the first equal sign, ignoring any differences in leading & trailing spaces.

    This could improve alignment for everything, like ensuring "if orange = 1" doesn't partial match and align to "for range = 1 to 10", which is obviously completely different code.

  • #2
    Hello,

    For examples like this, you can try a few different things. One way I've found to be effective is to define a Grammar element for your Variables (^.*= or a similar RegEx).

    Then go to the Session Settings, and mark Variable as important, and uncheck Everything Else marking it as Unimportant. This way differences detected in the variable name are red, and other differences are blue (toggle Ignore Unimportant Differences in the toolbar to Off).

    Then in the Session Settings, Alignment tab, check Never Align Differences. This will then not align your variable names, but mark any differences in values as blue.


    Alternatively, you can assign Line Weights (under File Formats) and tweak Alignment options to align your text differently.
    Aaron P Scooter Software

    Comment


    • #3
      Well, that's a novel hack. Convoluted, but at least it works. (I better copy these instructions somewhere safe--I'll never remember then otherwise.)

      I tried the line weights before but could never see any changes in alignment. I suppose line weights don't help much in registry & INI files since there's really only 1 line type.

      I still think a "strict" option would be easier. Plus, it would help more complicated alignment like XML elements, which always drive me crazy when BC matches a bunch of random letters for lines with completely different elements.

      Anyway, thanks for the suggestion. I'll play with it and maybe find a way to match base elements in XML, too.

      Comment


      • #4
        I tried this but it doesn’t seem to be working at all other than not aligning different… namely it isn’t aligning the “ Variables” pattern either nor even after manually aligning, it doesn’t highlight the assignment (RHS) as a difference.

        I’ve tried to debug/figure out where it is going wrong but haven’t been able to figure it out.

        I’d just like to bump the request to make this easier since it is a common workflow for example when updating configuration files with dependencies between projects… eg go.mod files between projects.

        Comment


        • #5
          Hello,

          The key to the above workaround is for only the 'variable' to be important, and "everything else" in the Session Settings, Importance tab would be Unimportant. Combined with the Session Setting Alignment option "Never Align Differences" then only uses Important text (unimportant can still align). This usually pushes things into place.

          Also, this is an older thread, and we've since added alternate alignment options like Patience diff, which usually does a good job if your functions have brackets or a similar notation. Do any of the Alignment tab's options or combinations help?

          If you'd like, you can post an example set here or send in sample files privately, we could take a look and help with specific settings. You can email us at [email protected] with a link back to this forum thread. If including a screenshot, please include View menu -> Line Numbers.
          Aaron P Scooter Software

          Comment


          • #6
            Thank you, I was trying different grammars to get things to work and when I tried using the actual pattern from this thread (modifying my text to match) somehow the regex option got disabled on the grammer pattern!-P Then when I went back to my original pattern to match (go.mod) my actual file I realized an issue in the regex pattern.
            So I do have it aligning as desired on the "variable" (LHS) only.

            But the unfortunate part is the RHS (assignment value), shows up as unimportant. I'd really like the differences to be highlighted in red.

            Comment


            • #7
              Blue (Unimportant) Differences are still differences unless hidden with the toggle to Hide Unimportant Differences. It's not an ideal situation, but otherwise you would have to mark the text as Important again (perhaps with specific grammars on the sections you need?) and see how it impacts the alignment. If you email in specific example files, I can add them to our test cases for alignment.

              Update: and if you can include line numbers in any screenshot or describe which line should align where, that would help me identify and build the example case.
              Last edited by Aaron; 08-Jun-2023, 09:50 AM. Reason: Update
              Aaron P Scooter Software

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎