Community
    • Login

    "Remove Unnecessary Blank and EOL" ?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 4 Posters 2.5k 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.
    • Alan KilbornA
      Alan Kilborn
      last edited by

      I’ve been trying to pin down what the Remove Unnecessary Blank and EOL menu item does, exactly. It seems like this is close, but not quite:

      Find (\h*\R)+
      Replace with single space
      Wrap around on
      (regex mode of course)

      Anybody know EXACTLY what this command does?

      Meta ChuhM 1 Reply Last reply Reply Quote 0
      • Meta ChuhM
        Meta Chuh moderator @Alan Kilborn
        last edited by Meta Chuh

        @Alan-Kilborn

        the menu item “Remove Unnecessary Blank and EOL” has id IDM_EDIT_TRIMALL (see Notepad_plus.rc)

        from NppCommands.cpp it calls doTrim(lineTail); and doTrim(lineHeader); as two passes (see Notepad_plus.cpp)

        doTrim(lineHeader); search string:

        env._str2Search = TEXT("^[	 ]+");
        

        doTrim(lineTail); search string:

        env._str2Search = TEXT("[	 ]+$");
        

        replace string for both:

        env._str4Replace = TEXT("");
        
        1 Reply Last reply Reply Quote 3
        • guy038G
          guy038
          last edited by guy038

          Hello, @alan-kilborn, @meta-chuh, and All,

          After some tests, I deduced that the Edit > Blank Operations > Remove Unnecessary Blank and EOL operation is equivalent to the two regex S/R, below, run consecutively !

          • First, all leading and trailing tabulation and/or space character(s) are deleted, with the regex :

            • SEARCH ^[\t\x20]+|[\t\x20]+$

            • REPLACE Leave EMPTY

          • Secondly, any line-break ( Windows, Unix, or Mac ) is changed into a single space character, with the regex :

            • SEARCH \R

            • REPLACE \x20


          Notes :

          • This option and the regexes preserve the space and/or tabulation characters, when located between words or strings

          • The two S/R cannot be run simultaneously ! Indeed, if the previous match was, for instance, a line-break ( \R ), so changed into space, then a ^[\t\x20]+ match cannot occur anymore as the assertion ^ cannot be found :-((

          Best Regards,

          guy038

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

            @Meta-Chuh and @guy038

            Thanks for your inputs!

            @guy038 said:

            The two S/R cannot be run simultaneously !

            Well, say one wanted to recreate the Remove Unnecessary… functionality in a single regex operation. One could simply record a macro with @guy038 's two replacement operations…then when the user runs a single operation (the macro), two operations are done.

            I’m pointing this out because I often combine multiple regex replacement operations into a macro so that it appears to be a single simple operation, and other readers might not know that you can do this.

            Meta ChuhM 1 Reply Last reply Reply Quote 4
            • Meta ChuhM
              Meta Chuh moderator @Alan Kilborn
              last edited by Meta Chuh

              @Alan-Kilborn

              … and other readers might not know that you can do this.

              after this sentence part, i’m not sure anymore if, by asking the question:

              Anybody know EXACTLY what this command does?

              you wanted to know, what the command does programmatically for yourself, or if you wanted to know what it does at all, from a user perspective.

              for you, i guess the answer was suitable, but for normal users, the answer would be rather explaining what it does:

              Remove Unnecessary Blank and EOL removes all indentation, empty lines, and merges the whole file into one single line.

              (not quite accurate, but probably being the more understandable explanation, than to say: it removes all leading/trailing white spaces and line feeds of every line of a document)

              please keep me informed for who you intended this info to be for, as i am confused … again ;-)

              Alan KilbornA 1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @Meta Chuh
                last edited by Alan Kilborn

                @Meta-Chuh said:

                please keep me informed for who you intended this info to be for

                Hmmm, well it started out one way (Remove Unnecessary…) and then went almost a totally different way (a maybe enlightening technique for making multiple replacement operations appear like one action via macro record). Two really different things. That’s all.

                Often posters here (myself included I guess) bend over backwards trying to help someone with a complicated regex replacement that might be made much simpler with a multistep replacement. Because macros can be named, and simple replacements can’t (unlike with other text editors) but can be when they are recorded in a macro, I’m going to think better of and make more use of this kind of thing in the future. Maybe not revolutionary, but I for one haven’t been thinking this way in the (distant) past. It’s been more of a recent-past fetish (wrong word but can’t think of better ATM!) of mine.

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

                  Hi, @alan-kilborn, @meta-chuh, and All,

                  UPDATED on 05 12 2019 : I made the regex, below, more accurate as I changed the \h syntax by the more strict one [\t\x20]

                  When run consecutively, my two previous regexes do simulate the Remove Unnecessary Blank and EOL option !

                  Of course, Alan, my initial goal was to find an unique regex S/R ! So, I thought again about this problem and, after additional tests, I finally found out a solution :

                  SEARCH [\t\x20]*\R[\t\x20]*

                  REPLACE \x20

                  Thus, from the search regex, it’s easy to transpose it in natural speech :

                  The Remove Unnecessary Blank and EOL option replaces any kind of line-break, possibly surrounded by, either, tabulation and/or space character(s), with a single space character ;-))


                  Indeed, Alan, it’s valuable to remember that multiple regex S/R can be recorded, one after another, in a single macro ! It’s just that, most of the time, I simply re-invent the regular expression(s), necessary for my current work, if the overall regex(es) is/are not so complicated, of course ;-))

                  Cheers,

                  guy038

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

                    So, thanks everyone for contributing. I think it has now officially been beaten to death. I’ll mark as SOLVED now…

                    But…

                    I have one final question, and this one is for @donho (and of course will never be answered, and really is rhetorical anyway), and this is: What gives you the right to decree that these things are “unnecessary”?

                    :)

                    donhoD 1 Reply Last reply Reply Quote 3
                    • donhoD
                      donho @Alan Kilborn
                      last edited by

                      @Alan-Kilborn said in “Remove Unnecessary Blank and EOL” ?:

                      I have one final question, and this one is for @donho (and of course will never be answered, and really is rhetorical anyway), and this is: What gives you the right to decree that these things are “unnecessary”?

                      Oups sorry, I just saw your question (by googling “Remove Unnecessary Blank and EOL”).

                      As I mentioned, I agree it’s named very badly. Do we have a better naming? Any suggestion?

                      1 Reply Last reply Reply Quote 2
                      • PeterJonesP PeterJones unlocked this topic on
                      • Alan KilbornA
                        Alan Kilborn
                        last edited by

                        @donho said in “Remove Unnecessary Blank and EOL” ?:

                        I agree it’s named very badly. Do we have a better naming? Any suggestion?

                        Not a great one. But see HERE.

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