• Login
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.
  • A
    Alan Kilborn
    last edited by May 11, 2019, 12:34 PM

    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?

    M 1 Reply Last reply May 11, 2019, 12:51 PM Reply Quote 0
    • M
      Meta Chuh moderator @Alan Kilborn
      last edited by Meta Chuh May 11, 2019, 2:24 PM May 11, 2019, 12:51 PM

      @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
      • G
        guy038
        last edited by guy038 May 11, 2019, 2:24 PM May 11, 2019, 2:12 PM

        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

        A 1 Reply Last reply May 11, 2019, 4:03 PM Reply Quote 4
        • A
          Alan Kilborn @guy038
          last edited by May 11, 2019, 4:03 PM

          @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.

          M 1 Reply Last reply May 11, 2019, 4:24 PM Reply Quote 4
          • M
            Meta Chuh moderator @Alan Kilborn
            last edited by Meta Chuh May 11, 2019, 4:26 PM May 11, 2019, 4:24 PM

            @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 ;-)

            A 1 Reply Last reply May 11, 2019, 7:02 PM Reply Quote 2
            • A
              Alan Kilborn @Meta Chuh
              last edited by Alan Kilborn May 11, 2019, 7:04 PM May 11, 2019, 7:02 PM

              @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
              • G
                guy038
                last edited by guy038 May 12, 2019, 10:14 AM May 11, 2019, 9:56 PM

                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
                • A
                  Alan Kilborn
                  last edited by May 12, 2019, 12:13 AM

                  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”?

                  :)

                  D 1 Reply Last reply Dec 26, 2022, 8:59 PM Reply Quote 3
                  • D
                    donho @Alan Kilborn
                    last edited by Dec 26, 2022, 8:59 PM

                    @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 Dec 27, 2022, 2:46 AM
                    • A
                      Alan Kilborn
                      last edited by Dec 27, 2022, 2:47 AM

                      @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