Combine 2 files line by line



  • So, really @astrosofista has found some amazing uses for the BetterMultiselection plugin.
    It makes one wonder, why isn’t this in Notepad++ itself (without need for the plugin)?
    @dail 's work with the plugin is really great, but why do we even need a plugin?
    I guess it would need to be in Scintilla, but these actions just make so much sense I wonder if the capabililty IS in Scintilla, and just not enabled in Notepad++'s use of Scintilla?
    Thoughts?



  • @Alan-Kilborn

    The newer versions of scintilla (which N++ is using) has a bit better support. However it still doesnt match what my plugin provides.

    I think the key is that Scintilla does not transform a rectangular selection into multiple stream selections.

    If I recall correctly, this was brought up on the Scintilla list or tracker and they concluded this functionality would not be added to Scintilla. There may be more technical reasons as to why it was not seen as beneficial, however I feel this plugin demonstrates how useful this kind of behavior is.



  • @dail said in Combine 2 files line by line:

    they concluded this functionality would not be added to Scintilla

    Bad news, in a way. In another sense it means that your plug-in will be guaranteed to have a long life.

    Please keep developing it. Thank you.



  • Hi @guy038

    That’s right, the End key will get the same outcome, though I’m not sure it’s any easier to understand. Anyway, good catch :)

    By the way, shouldn’t all the multi-carets be shown in red? At least that’s what I expected to see, since I wanted them to stand out in the animation.



  • @astrosofista said in Combine 2 files line by line:

    shouldn’t all the multi-carets be shown in red? At least that’s what I expected to see,

    Curious, why do you expect this?
    Typically the caret related to the main selection is supposed to visually “stand out” from any secondary carets. Several Notepad++ functions act only on the main selection, so sometimes it is helpful to know which this is going to be before invoking the function.

    In Pythonscript, I do this to make the different carets stand out well:

        for e in (editor1, editor2):
            e.setCaretFore((0xFF, 0, 0))  # turn the main caret bright red for better visibility
            e.setAdditionalCaretFore((0, 0, 0))  # turn the secondary carets black for good visibility
    


  • Hi @Alan-Kilborn

    For a reason of consistency. I expected to see all carets in the same color but not in the same shade, just as if I set the caret color to black in the Style Configurator, then the secondary carets are shown in gray.



  • @astrosofista

    So then how are you actually getting different colored carets and not just the same-base-color-but-different-shade effect?
    Maybe you don’t know and this is your question?

    Anyway, forgot to include the screenshot I made of my custom-colored carets; here it is:

    d16efd7d-e181-4f87-9f5e-4b9bf6dbc8f8-image.png



  • @Alan-Kilborn said in Combine 2 files line by line:

    So then how are you actually getting different colored carets and not just the same-base-color-but-different-shade effect?
    Maybe you don’t know and this is your question?

    That’s my question, yes.

    Concerning the screenshot, will try the code, though I will probably set all the carets to the same base color, just to check the effect.



  • @astrosofista I use a method similar to yours that works without any plugins (unless those are default plugins that I also have). I add blank lines to both the source and destination block (search: [\r\n]+ replace: \r\n\r\n. I then Alt+Shift block select the source block, cut, position the cursor on the first blank line in the destination and paste.





  • Hello, @cooeeeee and All,

    Ah…! Many thanks for that tip and work-around ! I didn’t even know that such an operation was possible ! Note that it’s works whatever the BetterMultiSelection plugin of @Dail is enabled or not ;-))

    Note that you may shorten your regex S/R as below :

    SEARCH \R

    REPLACE $0$0

    Best Regards,

    guy038



  • @guy038 and others:

    What allows it to work, is an odd(?) property of column blocks – the inability to copy line-endings.

    Here’s some text before blocking out a column, note where the CRLF line-endings are:

    809a4cf5-49cd-4d1e-9fd2-5c55363607cc-image.png

    Now here’s the same text after a rectangular block is put into place; again note where the CRLF are (they’re outside the selection), especially on the empty lines:

    4f9678ee-ce37-47ff-acc0-705ccf1a51b8-image.png

    Note that none of the line-ending characters made it into the block.
    Thus when this is copied and pasted, the originally empty lines are pasted as “nothingness”, allowing the technique by @Cooeeeee to work for merging data. Nice one.



  • Hi @Cooeeeee

    I see. The point of my post was to simplify @Fernando-Sorensen’s method, because although ingenious, it requires several steps. The basic idea was to do everything without additional windows, be it a second editor, the column editor or a search window, that would block or cut off the flow of the operation.

    The only thing that the BetterMultiSelection plugin is good for in my approach is precisely to insert the blank lines, an operation that standard multiselection cannot do - see @Alan-Kilborn’s post below - . But if the text already has blank lines interleaved, then the plugin is not necessary and, as your .gif shows, line interleaving can be done directly with standard multiselection.

    Which is the best method? For the reasons detailed above and because I have nothing against third party plugins either - in fact, I think they are a great addition to Notepad++ and heavily use them - I still prefer mine, but I have no objection to people using the one they find best.

    Thank you and, as always, have fun!


Log in to reply