REMOVE EMPTY LINES does not macro

2014-03-31
2014-04-06
  • Clyfton Hayes III

    I need to remove empty lines as a part of preparing a file for release.
    When I create a macro, EDIT > LINE OPERATIONS > REMOVE EMPTY LINES works just fine.
    But when I run the macro, it skips the REMOVE EMPTY LINES part.

     
  • Loreia2

    Loreia2 - 2014-04-01

    Hi Clyfton,

    macros only record Scintilla operations, not editor actions.
    But what is the difference anyway, running either would give you the same result. So why not use "remove empty lines" menu option?

    BR,
    Loreia

     
    • Clyfton Hayes III

      I don't see another Remove Empty Lines ... only the one under EDIT > LINE OPERATIONS. Please be more specific. If you are talking about TextFX - I used that a long time back then all of the sudden TextFX wasn't included in Notepad++ any more ... then time passed and TextFX was back again. I'm afraid if I incorporate TextFX into my macro again it will eventually disappear again and I may not notice it is gone and I will end up releasing broken code.
      Also, TextFX does weird things ... like still leave a blank line at the beginning and end of the document, whereas Remove Empty Lines does not.
      I also tried a regular expression replace of \r\r still but it leaves blank lines at the beginning and end of the file.
      It seems quite silly to me that EDIT functions cannot be included in a macro for a file editor.

       
      Last edit: Clyfton Hayes III 2014-04-01
  • Loreia2

    Loreia2 - 2014-04-01

    Hi Clyfton,

    I was referring to the same Edit menu / Line operations / Remove empty lines options that you mentioned. Why do you need to clone this option with a macro? Perhaps as part of more complex Macro?

    BR,
    Loreia

     
    • Clyfton Hayes III

      I am confused by your responses.
      I created a macro with many steps. One of the steps was to delete empty lines. But when I run the macro, all the other steps work except for deleting the empty lines. I do not know how else to explain it.

       
  • AZJIO

    AZJIO - 2014-04-01

    @Clyfton Hayes III
    Add in a macro still option:
    1.
    Find what:(\r\n|\r|\n){2,}
    Replace with:\1
    2.
    Find what:\A[\r\n]+|[\r\n]+\z
    Replace with:

    macro successfully recorded these actions. Maybe it will help you.

     
    Last edit: AZJIO 2014-04-01
    • Clyfton Hayes III

      Thanks. You are a regular expression genius. It works. I don't know how it works but it works.

       
  • Loreia2

    Loreia2 - 2014-04-02

    Hi Clyfton,

    I am confused by your responses.
    I created a macro with many steps. One of the steps was to delete empty lines. But when I run the macro, all the other steps work except for deleting the empty lines. I do not know how else to explain it.

    That is all I wanted to know.
    In that case, you can emulate "Remove empty lines" by using regular expression replacement.

    Start replace dialog (Ctrl + H)
    Find what: (\R)\R+
    Replace with: \1

    Tick Regular expression mode, and hit Replace all.

    BR,
    Loreia

     
    • Clyfton Hayes III

      Thank you. That works. However it leaves a blank line at the beginning and end of the file ... which won't work for me. Somehow the "Remove empty lines" function was more thorough and did not leave empty lines at the start and finish.

       
  • Loreia2

    Loreia2 - 2014-04-03

    Hi Clyfton,

    this is what I got after a quick Google search:

    Start replace dialog (Ctrl + H)
    Find what: ^(?:[\t ]*(?:\r?\n|\r))+
    Replace with: <nothing>

    Tick Regular expression mode, and hit Replace all.
    It should remove all empty lines (including the ones that contain white space characters only)

    BR,
    Loreia

     
    • Clyfton Hayes III

      Thanks. That still left a blank line at the end :(

       
  • AZJIO

    AZJIO - 2014-04-04

    ^\R|\R(?=\R)|\R\z
    link

     
    Last edit: AZJIO 2014-04-04
    • Clyfton Hayes III

      Perfect ! Thanks !

       
  • THEVENOT Guy

    THEVENOT Guy - 2014-04-06

    Hi Clyfton, Loreia2, AZJIO and All

    It's still possible to shorten this S/R, about the suppression of all the empty lines of a file !

    A) First syntax :

    SEARCH : ^\R|(\R)+

    REPLACE : \1

    B) Second syntax ( Can't do shorter !!! ) :

    SEARCH : ^\R

    REPLACE : Nothing

    Notes :

    • If your text is quite important, with a lot of empty lines, the second S/R may take more time, because it deletes every single EOL character, individually !

    • It's usually said that the \R form stands for any kind of EOL ( The Windows \r\n characters, the Unix/OSX \n character or the Old Mac \r character ). But, to be exact, \R represents any character of the set
      \r\n|[\n\v\f\r\x{2028}\x{2029}]

    Enjoy our loved editor :-)

    Cheers,

    guy038

     
    Last edit: THEVENOT Guy 2014-04-06