Community
    • Login

    Delete lines with PythonScript

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 1.1k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          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