Community
    • Login

    Column-aligning jagged data

    Scheduled Pinned Locked Moved General Discussion
    17 Posts 9 Posters 12.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guy038G
      guy038
      last edited by

      Hi, @alan-kilborn,

      Another clarifying situation might be what if I want this to only affect certain lines, or only after a certain column point on specific lines…

      • Concerning the possibility to change text, after a specific column point c, simply use the regex ^.{c+ε}\K\x20+

      • Concerning reducing text changed to a specific block of lines, do a normal selection of your range of lines, first. So, when opening the Replace dialog, the In selection option is automatically ticked, and the Replace All operation is performed on the selection, only :-))

      Cheers,

      guy038

      1 Reply Last reply Reply Quote 0
      • Jim DaileyJ
        Jim Dailey
        last edited by

        @PeterJones

        The old man wasn’t invited to the tournament. Nevertheless, he ambled over to the tee box and took a swing with an ancient wooden driver that has been meticulously maintained for more than 40 years:

        gawk "{printf \"%-256s%s\n\",$1,$2}" $(FULL_CURRENT_PATH)
        

        :-)

        1 Reply Last reply Reply Quote 5
        • dailD
          dail
          last edited by

          Somewhat tangential but possibly a solution is the Elastic Tabstops plugin. Its would only require a single tab between columns but has the disadvantage of only working within Notepad++ itself.

          1 Reply Last reply Reply Quote 4
          • cipher-1024C
            cipher-1024
            last edited by

            Neither was the simpleton invited to the tournament but he stumbled up to the tee and out from his bag fell a TextFX plugin and hideous python script that would make a crow blush:

            # coding: iso-8859-1
            selected = editor.getSelText()
            selStart = editor.getSelectionStart()
            #replace any existing commas with a weird char
            selected = selected.replace(",", chr(174))
            #replace the double spaces
            while ( selected.find("  ") > 0 ):
            	selected = selected.replace("  ", " ")
            #replace the spaces with commas since our 'line up' function uses commas
            selected = selected.replace(" ", ",")
            selEnd = len(selected)
            editor.replaceSel(selected)
            #re-select the selection
            editor.setSelectionStart(selStart)
            editor.setSelectionEnd(selStart + selEnd)
            notepad.runMenuCommand("TextFX Edit", "Line up multiple lines by (,)")
            notepad.runMenuCommand("TextFX Edit", "E:Line up multiple lines by (,)")
            selected = editor.getSelText()
            #take out the lineup commas
            selected = selected.replace(",", " ")
            #put back any original commas
            selected = selected.replace(chr(174), ",")
            editor.replaceSel(selected)
            

            This works for any number of columns, and only on lines in the current selection. It makes the columns as narrow as possible. I’m not really sure how you would line up things after a certain column point though.

            1 Reply Last reply Reply Quote 4
            • guy038G
              guy038
              last edited by guy038

              Hello, @cipher-1024, and All,

              I’m thinking about an other solution, which still use the TextFX plugin but which avoids this [ hideous :-D ] Python Script !

              • First, use the following regex S/R :

              SEARCH \x20+

              REPLACE \x60

              Note : I, specially, chose the Unicode Grave Accent character ( U+0060 ) , as a dummy character, because it is, both, rarely used in programming languages, ( AFAIK ! ) and part of all character encodings, as belonging to the international ASCII encoding ( from Unicode U+0000 to U+007F )

              • Copy a single ` ( Grave Accent ) in the clipboard, hitting the Ctrl + C shortcut ( IMPORTANT )

              • Now, do a normal selection of the text, which is to be aligned

              • Click on the menu choice TextFX > TextFX Edit > Line up multiples lines by (Clipboard Character)

              • Finally, use the regex, below, to delete the dummy Grave Accent character ` and add some space characters between columns, with a possible delimiter character !

              SEARCH \x60

              REPLACE \x20\x20\x20

              OR, for instance :

              SEARCH \x60

              REPLACE \x20\x20|\x20\x20

              Cheers,

              guy038

              1 Reply Last reply Reply Quote 2
              • PeterJonesP
                PeterJones
                last edited by PeterJones

                Other than “rarely used in programming languages,” I like that answer.

                Perl uses a pair of Grave Accents (aka “backticks”) as an often-used alternate for the qx// quote-like syntax for running a shell command and placing the command’s output in a string.

                SQL uses backticks for denoting identifiers, such as field names.

                Markdown uses it for embedding inline fixed width text, like:

                embedding `inline` fixed width text
                

                But if you know your text has no backticks, then it’s a great choice.

                If your data might have backticks, I would use U+001C (\x1c), the Field Separator FS character, which is a control code found in ASCII. (I won’t make the claim that it’s “rarely used” in text files or programming language source code… but I’ve never seen it intentionally used in such. :-) )

                I think this style of solution meets the original requirements of not requiring complicated S/R regex or precomputing, which is nice.

                1 Reply Last reply Reply Quote 2
                • guy038G
                  guy038
                  last edited by guy038

                  Hi, @PeterJones and All,

                  So, I strongly apologize ! My programming skills are weaker than most N++ users’s ones :-D.

                  BTW, Peter, just have a look to the link, below :

                  https://en.wikipedia.org/wiki/C0_and_C1_control_codes

                  it seems, that the C0 Control character ( \x1C ) rather refers to the File Separator control character ! Anyway, your idea, about using a Control character, is great ! And, if we follow the description notes, it would be logical to prefer the US Control character \x1F :-D

                  Cheers,

                  guy038

                  1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn
                    last edited by

                    IMO the ultimate solution to the question I originally posed is found HERE.

                    1 Reply Last reply Reply Quote 2
                    • artie-finkelsteinA
                      artie-finkelstein
                      last edited by

                      I didn’t check the date of the original posting but did immediately say "that’s a job for BetterMultiSelection. It was very satisfying to be able to figure out how to solve that problem. (It took me a few attempts, but that’s why Ctrl-Z exists)

                      Thank you to @Alan-Kilborn for a wonderful lesson. It really helped drive home @astrosofista’s examples.

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @artie-finkelstein
                        last edited by Alan Kilborn

                        @artie-finkelstein

                        …It really helped drive home @astrosofista’s examples

                        This was not my intention; perhaps you misunderstood.
                        I was linking directly to a posting, not the larger thread, for the awesome solution to the problem posed here in this thread.
                        The linked posting discusses using Ctrl+Delete, not any plugin.

                        Plugins (including Better Multiselection) are great, but even better is when something available natively is the solution to something. And the Ctrl+Delete technique is available natively.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors