Community
    • Login

    Delete lines with PythonScript

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 679 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.
    • Brian HigdonB
      Brian Higdon
      last edited by

      Hello,
      I am using PythonScript and want to delete the whole line. Right now, I am using this:
      editor.rereplace(r’^.: “”.$', ‘’)
      and I am left with empty lines.
      I can manually go to:
      edit>line operations > remove empty lines.
      but I do not see that option in the documentation PythonScript.

      I have tried.
      editor.deleteLine(‘^.: “”.$’)
      and this
      editor.replaceWholeLine (r’^.: “”.$', ‘’)

      What setting or regex syntax do I need to include?

      Any help would be grateful.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Brian Higdon
        last edited by Alan Kilborn

        @Brian-Higdon said in Delete lines with PythonScript:

        I am using PythonScript and want to delete the whole line

        editor.deleteLine(line), where line is the line number you wish to delete.

        If you want to do it with rereplace, you need a correct pattern to match the line(s) to delete. I can’t tell from your posting what that is. But if you are “left with empty lines” then it probably means you didn’t include the line-ending in your pattern with \R and indeed I don’t see that in your pattern.

        Maybe your “remove empty lines” comment is leading…about what you want to do… so let’s proceed with that:

        You can execute that command in code with notepad.menuCommand(MENUCOMMAND.EDIT_REMOVEEMPTYLINES)

        With that as the basis of understanding, you could also do it with editor.rereplace(r'^\R', '')

        Oh, wait…I think the empty lines only comes into it after you’ve done your rereplace and it didn’t do what you wanted.

        I’m so confused… :-(

        Brian HigdonB 1 Reply Last reply Reply Quote 3
        • Brian HigdonB
          Brian Higdon @Alan Kilborn
          last edited by Brian Higdon

          @Alan-Kilborn Thank you for getting back to me so quickly.

          Yes, you are correct on my regex string. Adding \R did what I needed it to do.

          editor.rereplace(r’^.: “”.$\R’, ‘’)

          You are not confused; I confusingly wrote my question.

          The issue is solved.
          Thank you.

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