Community
    • Login

    Other thoughts regarding the "ReWrap Text to (Clipboard or 72) width" of the old "TextFX" plugin

    Scheduled Pinned Locked Moved General Discussion
    16 Posts 4 Posters 665 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 Offline
      guy038
      last edited by

      Hi, @mpheath and All,

      Ah… I understand. Thus, I’ve decided to conduct a second round of tests. This time :

      • The files New_LF_ANSI.txt and New_CRLF_UTF-8.txt were copied from ORG_LF_ANSI.txt as Regex_LF_ANSI.txt and Regex_CRLF_UTF-8.txt

      • The files Lua_LF_ANSI.txt and Lua_CRLF_UTF-8.txt were copied from ORG_LF_ANSI.txt as Lua_2_LF_ANSI.txt and Lua_2_CRLF_UTF-8.txt

      Then, I stopped and restarted N++ : thus, no more change history feature !

      Finally, regarding these new created files :

      • I ran the regex replacement, followed by a Trim trailing Space operation, on files Regex_LF_ANSI.txt and Regex_CRLF_UTF-8.txt

      • I ran your Lua script on files Lua_2_LF_ANSI.txt and Lua_2_CRLF_UTF-8.txt

      So, these four files showed an orange change history color. As you can see on the screenshots, the regex process acted on all lines, but some empty line endings, and your lua script just acted on lines which need wrapping !

      Regex process :

      2227cacc-b95f-4715-9de6-41295fb2754d-image.jpeg

      Lua process :

      7b25d2ab-cc71-4e82-9fe3-dc3c4f3cd4fa-image.jpeg


      However, the comparisons between the regex process and the Lua process shows the same number of differences ( 3 for ANSI files and 5 for UTF-8 files )

      • Between ANSI files :

      7299ef9e-d2d0-46f5-9d1c-a9a4a69473a4-image.jpeg

      7e206be6-1745-46b2-9751-5fdd94e5a2a6-image.jpeg

      • Between UTF-8 files

      bd94b573-9462-4640-99f2-ed0ecbec9ced-image.jpeg

      785051c7-9e8b-476c-8024-9cb249e18ded-image.jpeg

      Best Regards,

      guy038

      mpheathM 1 Reply Last reply Reply Quote 1
      • mpheathM Offline
        mpheath @guy038
        last edited by

        @guy038 The testing looks better.

        If the Change History -> Show in text option is checked then can see changes to a character for more detail. No need to retest and repost images to show the indicators.

        A change of the regex pattern to:

        Find:

        (?-s)^(?=.{79}).{1,78}\K\x20(?!\R)
        

        Replace:

        \r\n
        

        and then press the Replace All button.

        It does replace less as it does not capture and so only the \x20 space is matched. Unfortunately, it will read the line to length of 79 and then read the line again if line is 79 to continue the pattern so might be slower then your previous tested pattern. The (?=.{79}) is needed to ensure shorter lines are not matched for wrapping. The (?!\R) is probably optional to have in the pattern as it is limited to detecting trailing spaces. Since the pattern uses \K, then the Replace button is not expected to function properly to step through the replacements.

        The text comparison in my testing shows the regex patterns achieve equal results which seems to be fortunate. That test was done on license.txt.

        1 Reply Last reply Reply Quote 0
        • guy038G Offline
          guy038
          last edited by guy038

          Hi, @mpheath and All,

          @mpheath, from your advice, I finally chose the following process :

          • First, run a Edit > Blank Operations > TAB to Space option

          • Then run the regex replacement below, where C represents the maximum number of chars after you want a line-break :

            • SEARCH [\x20\r\n]*\z|(?-s)^(?=.{C+1,}).{1,C}\K(?:\x20*\R|\x20+)

            • REPLACE \r\n for Windows files    or    \n for Unix files

          • Finally, run a Edit > Blank operations > Trim Trailing Space option

          Remarks :

          • I began the regex with [\x20\r\n]*\z which will replace possible mixed range of spaces and new lines, at the very end of current file, with a single line-ending

          • I used the (?-s)^(?=.{C+1,}) ( instead of the (?-s)^(?=.{C+1}) as it seems slightly faster within huge files !

          • Compare to your regex, I still wanted to consider all spaces, possibly followed with a line-break. So, the part .{1,C}\K(?:\x20*\R|\x20+)

          • Note that the final Trim Trailing Space action is necessary because of this specific case with a splitting after column 40

          12345678901234567890123456789012345     ABCDE
          
          12345678901234567890123456789012345     
          ABCDE
          

          Now, let’s try it out with a concrete example :

          • Double-click on https://www.gutenberg.org/cache/epub/2701/pg2701.txt => The text of the novel Moby Dick or The Whale should appear

          • Go to the second occurrence of the string CHAPTER 1. Loomings.

          • Select from this line to the line END OF THE PROJECT GUTENBERG EBOOK MOBY DICK; OR, THE WHALE, excluded

          • Paste it in a N++ new tab and name it Moby_ORG.txt

          So, the Moby.ORG.txt file should begin and end with :

          
          Call me Ishmael. Some years ago—never mind how long precisely—having
          little or no money in my purse, and nothing particular to interest me
          on shore, I thought I would sail about a little and see the watery part
          of the world. It is a way I have of driving off the spleen and
          regulating the circulation. Whenever I find myself growing grim about
          ...
          ...
          ...
          ...
          unharming sharks, they glided by as if with padlocks on their mouths;
          the savage sea-hawks sailed with sheathed beaks. On the second day, a
          sail drew near, nearer, and picked me up at last. It was the
          devious-cruising Rachel, that in her retracing search after her missing
          children, only found another orphan.
          

          In other words :

          • Line 1 EMPTY
          • Line 2 FIRST line of text
          • Line 20,707 LAST line of text
          • Line 20,708 = \z

          As this file seems already wrapped to 71 chars, I decided to do, FIRST, an intelligent un-wrapping !

          • I verified that there was no tabulation, nor any trailing space in the Moby_ORG.txt file

          • Then I noticed that 43 lines began with one or two space characters, without any real utility. So, I ran the Edit > Blanck operations > Trim Trailing Space option

          • To get a correct un-wrapping process, we need to use the following regex S/R :

            • SEARCH (?-s).+\K\R(?=.+) ( Do not insert a ^ character between the parts (?-s) and .+ ) of this regex ! )

            • REPLACE \x20

          • Finally, I saved the changes and renamed the Moby_ORG.txt as Moby_To_Wrap.txt

          So, the Moby_To_Wrap.txt file begins and ends as below :

          Call me Ishmael. Some years ago—never mind how long precisely—having little ...
          
          There now is your insular city of the Manhattoes, belted round by wharves as ...
          
          Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears Hook ...
          ...
          ...
          ...
          ...
          “AND I ONLY AM ESCAPED ALONE TO TELL THEE” Job.
          
          The drama’s done. Why then here does any one step forth?—Because one ...
          
          It so chanced, that after the Parsee’s disappearance, I was he whom ...
          

          In other words :

          • Line 1 EMPTY
          • Line 2 FIRST line of text
          • Line 4,884 LAST line of text
          • Line 4,885 = \z

          The second line of your script is always :

          local maxLineLength = 78
          

          And the Settings > Preferences... Margins/Border/Edge > Vertival Edge Settings only contains the 78 value

          Then I copied the Moby_ORG.txt file three times, as Moby_Regex.txt, Moby_Lua.txt and Moby_Ctrl-I.txt and I applied :

          • Your script against the Moby_Lua.txt file,

          • The Edit > Line Operations > Slipt Lines option against the Moby_Ctrl-I.txt

          • The following regex S/R against the Moby_Regex.txt

            • SEARCH [\x20\r\n]*\z|(?-s)^(?=.{79,}).{1,78}\K(?:\x20*\R|\x20+)

            • REPLACE \r\n


          Upon comparison, it turns out that these three files are completely different ! Compared to the Moby_Regex.txt file , I noticed that your Moby_Lua.txt sometimes grasps :

          More than it should, as, for example, in the lines :

          “Who-e debel you?”—he at last said—“you no speak-e, dam-me, I kill-e.” And so saying with a wrapping after 84 chars

          a1299916-7d59-4c0b-a524-c5edf237ba4e-image.jpeg

          “Oh, I don’t mind ’em, sir,” said Archy; “I knew it all before now. Didn’t I hear ’em with a wrapping after 85 chars

          f376a0b5-7d95-4f82-80f8-54c71394606e-image.jpeg

          Less than it should, as, for example, in lines :

          • the Stoics to enable you to grin and bear it. But even this wears off in, with a wrapping after 72 chars

          130645ce-362a-43a6-bf62-c511f338cdac-image.jpeg

          • knowingly, would thereby render yourself liable to a criminal, with a wrapping after 61 chars

          eb346fc2-0eb6-445c-bc6f-1d4ef581b4e9-image.jpeg

          Not important, though. Just in case you would work on your script a little more !


          Now, using this long text ( the Moby_To Rewrap.txt file ), I confirm that the regex, below, exactly mimics the Ctrl + I feature :

          SEARCH (?-s)^(?=.{78})(?:.{1,76}\x20|.{77})\K

          REPLACE \r\n for Windows files    or    \n for Unix files

          However, note that the Edit > Line Operations > Split lines operation leaves a trailing space on all lines of a paragrah but the last one !


          I think that further investigation would be useless and I’ll personally just use the method, shown at the beginning of this post, when I need to wrap any text !

          Best Regards,

          guy038

          Oh, I almost forgot something important :

          When you select some text or all contents of a file and execute the Edit > Line Operations > Split Lines option :

          • The View > Word wrap must be OFF

          • The View > Show Symbol must be OFF

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA Offline
            Alan Kilborn @guy038
            last edited by

            @guy038 said:

            just use the method, shown at the beginning of this post, when I need to wrap any text

            For clarity for future readers of this thread, which method is this one?

            When you select some text or all contents of a file and execute the Edit > Line Operations > Split Lines option :

            The View > Word wrap must be OFF

            The View > Show Symbol must be OFF

            And, because I’m currently away from my Notepad++ and can’t try it myself, why are these "must be OFF"s?

            1 Reply Last reply Reply Quote 0
            • guy038G Offline
              guy038
              last edited by guy038

              Hello, @alan-kilborn,

              You said :

              For clarity for future readers of this thread, which method is this one?

              I was referring to these steps :

              • First, run a Edit > Blank Operations > TAB to Space option

              • Then run the regex replacement below, where C represents the maximum number of chars after you want a line-break :

                • SEARCH [\x20\r\n]*\z|(?-s)^(?=.{C+1,}).{1,C}\K(?:\x20*\R|\x20+)

                • REPLACE \r\n for Windows files    or    \n for Unix files

              • Finally, run a Edit > Blank operations > Trim Trailing Space option


              You then said :

              And, because I’m currently away from my Notepad++ and can’t try it myself, why are these "must be OFF"s?

              I must apologize because I was mistaken ! I did some other tests and it happens that the status of the View > Word wrap does not matter

              But I confirm that showing the line-endings chars breaks the correct spliting of text when using the Edit > Line Operations > Split Lines option

              STR :

              • In Settings > Preferences... > Margins/Border/Edge > Vertical Edge Settings insert the value 78 , ONLY

              • For clarity, just uncheck the View > Word wrap option and the View > Show Symbol option

              • Paste the beginning of the License.txt file, below, in a new tab :

              COPYING -- Describes the terms under which Notepad++ is distributed.
              A copy of the GNU GPL is appended to this file.
              
              IMPORTANT NOTEPAD++ LICENSE TERMS
              
              Copyright (C)2021 Don HO <don.h@free.fr>.  This program is free software; you may redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; Version 3 with the clarifications and exceptions described below. This guarantees your right to use, modify, and redistribute this software under certain conditions.
              
              This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
              
              ******************************************************************
              
              
              GNU GENERAL PUBLIC LICENSE
              Version 3, 29 June 2007
              
              Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
              
              Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
              
              Preamble
              The GNU General Public License is a free, copyleft license for software and other kinds of works.
              
              The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
              
              • Now, in the new tab, select all this text with Ctrl + A

              • Run the Edit > Line Operations > Slipt Lines or Ctrl + I option

              => You should get the text below :

              COPYING -- Describes the terms under which Notepad++ is distributed.
              A copy of the GNU GPL is appended to this file.
              
              IMPORTANT NOTEPAD++ LICENSE TERMS
              
              Copyright (C)2021 Don HO <don.h@free.fr>.  This program is free software; 
              you may redistribute and/or modify it under the terms of the GNU General 
              Public License as published by the Free Software Foundation; Version 3 with 
              the clarifications and exceptions described below. This guarantees your 
              right to use, modify, and redistribute this software under certain 
              conditions.
              
              This program is distributed in the hope that it will be useful, but WITHOUT 
              ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
              FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
              more details.
              
              ******************************************************************
              
              
              GNU GENERAL PUBLIC LICENSE
              Version 3, 29 June 2007
              
              Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
              
              Everyone is permitted to copy and distribute verbatim copies of this license 
              document, but changing it is not allowed.
              
              Preamble
              The GNU General Public License is a free, copyleft license for software and 
              other kinds of works.
              
              The licenses for most software and other practical works are designed to 
              take away your freedom to share and change the works. By contrast, the GNU 
              General Public License is intended to guarantee your freedom to share and 
              change all versions of a program--to make sure it remains free software for 
              all its users. We, the Free Software Foundation, use the GNU General Public 
              License for most of our software; it applies also to any other work released 
              this way by its authors. You can apply it to your programs, too.
              
              • Now, undo, with Ctrl + Z, the last action in order to return to the unwrapped text again

              • Click on the ¶ icon or run the View > Show Symbols > Show All Characters option

              • RE-select all contents of the new tab

              • Run again the Edit > Line Operations > Slipt Lines or Ctrl + I option

              => This time, you should get this text :

              COPYING -- Describes the terms under which Notepad++ is distributed.
              A copy of the GNU GPL is appended to this file.
              
              IMPORTANT NOTEPAD++ LICENSE TERMS
              
              Copyright (C)2021 Don HO <don.h@free.fr>.  This program is free software; 
              you may redistribute and/or modify it under the terms of the GNU 
              General 
              Public License as published by the Free Software Foundation; Version 3 
              with 
              the clarifications and exceptions described below. This guarantees your 
              right to use, modify, and redistribute this software under certain 
              conditions.
              
              This program is distributed in the hope that it will be useful, but WITHOUT 
              ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
              FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
              for 
              more details.
              
              ******************************************************************
              
              
              GNU GENERAL PUBLIC LICENSE
              Version 3, 29 June 2007
              
              Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
              
              Everyone is permitted to copy and distribute verbatim copies of this license 
              document, but changing it is not allowed.
              
              Preamble
              The GNU General Public License is a free, copyleft license for software and 
              other kinds of works.
              
              The licenses for most software and other practical works are designed to 
              take away your freedom to share and change the works. By contrast, the 
              GNU 
              General Public License is intended to guarantee your freedom to share 
              and 
              change all versions of a program--to make sure it remains free software 
              for 
              all its users. We, the Free Software Foundation, use the GNU General 
              Public 
              License for most of our software; it applies also to any other work 
              released 
              this way by its authors. You can apply it to your programs, too.
              

              And, obviously, these two texts are quite different !

              Test done with a portable N++ v8.9.8 - 64 bits installation !

              Best Regards

              guy038

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

                @guy038 said:

                I confirm that showing the line-endings chars breaks the correct spliting of text when using the Edit > Line Operations > Split Lines option

                So then this is a Notepad++ bug, correct?

                CoisesC 1 Reply Last reply Reply Quote 0
                • guy038G Offline
                  guy038
                  last edited by

                  Hi, @alan-kilborn and All,

                  I suppose so ! But have you checked this behavior for yourself ?

                  BR

                  guy038

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • CoisesC Offline
                    Coises @Alan Kilborn
                    last edited by Coises

                    @Alan-Kilborn said:

                    So then this is a Notepad++ bug, correct?

                    Considering that Notepad++ just uses Scintilla’s SCI_LINESSPLIT, it’s more of a Scintilla bug, if that project would consider it a bug. The documentation says that function finds split points “in a similar manner to line wrapping”; line wrapping also treats line endings as part of the line when they are visible.

                    However, I suppose Notepad++ could temporarily turn off showing line endings before doing the split.

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

                      Hi, @alan-kilborn, @coises and All,

                      From the scintilla description, below :

                      SCI_LINESSPLIT(pixels pixelWidth)
                      Split a range of lines indicated by the target into lines that are at most pixelWidth wide. Splitting occurs on word boundaries wherever possible in a similar manner to line wrapping. When pixelWidth is 0 then the width of the window is used.
                      
                      • I made a try putting ONLY the 0 value ( instead of 78 ) In Settings > Preferences... > Margins/Border/Edge > Vertical Edge Settings. Well, it happens that for any value ≤ 2, the spliting occurs after 2 characters

                      • I also tested with, for example, the value 220, which was larger than my physical screen. However, even in this case, the spliting occurs after 220 chars and not at the window’s width !

                      Of course, for these additional tests, line-endings were not enabled !


                      Oh, my God : I forgot to test with the Settings > Preferences... > Margins/Border/Edge > Vertical Edge Settings window completely empty ! Well, in this specific case, the spliting does occur at the window’s width and takes in account the possible increase or decrease in the ZOOM factor !

                      BR

                      guy038

                      1 Reply Last reply Reply Quote 0
                      • Alan KilbornA Offline
                        Alan Kilborn @guy038
                        last edited by

                        @guy038 said:

                        But have you checked this behavior for yourself ?

                        I have not; I’ve been away from my PC.

                        If it’s a bug, either Scintilla or Notepad++, it seems like it should be reported and made official?

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors