Community
    • Login

    "} else {" as a new section

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 Posters 770 Views 2 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.
    • Bert NieuwenampsenB Offline
      Bert Nieuwenampsen
      last edited by

      I’m building an if statement in PowerShell like this:

      if (blabla) {
      
      } else { 
      
      }
      

      If I do it like this, it does recognize different sections:

      if (blabla) {
      
      } 
      else 
      { 
      
      }
      

      screenshot:
      b59c5b39-2387-48a4-a195-ed4b5dc61461-image.png

      The problem is that Notepad++ sees it as one block, so I can’t collapse and expand the if and else separately.
      Can I adjust this somewhere in Notepad++?

      Regards,
      Bert

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @Bert Nieuwenampsen
        last edited by PeterJones

        @Bert-Nieuwenampsen said in "} else {" as a new section:

        Can I adjust this somewhere in Notepad++?

        Notepad++ uses the Lexilla IP by Scintilla for syntax highlighting and folding. Apparently, the PowerShell lexer has a property called fold.at.else, but Notepad++ doesn’t currently set that option. If Notepad++ were to set that true on PowerShell documents (by setting that property in setPowerShellLexer()), then it would allow folding at } else { for PowerShell.

        So if someone (you) were to follow the instructions in our Feature Request FAQ, and make an official request, it could be turned on, or a preference could be added to allow the user to toggle it. Then, if the developer thought it was a good idea, it might eventually be added to Notepad++.

        Until that happens, you could use the PythonScript plugin to toggle that setting:

        bb4ef35e-f36b-4ac3-a885-50a5637b20ea-image.png
        vs
        fa016149-1177-4813-a3aa-c9961a2295f5-image.png

        To be able to automatically do that, you could edit (or create) your user startup.py to include

        from Npp import editor, notepad, LANGTYPE, NOTIFICATION
        def cb_pwshFoldAtElse(args):
            if notepad.getCurrentLang() == LANGTYPE.POWERSHELL:
                editor.setProperty("fold.at.else", 1)
        notepad.callback(cb_pwshFoldAtElse, [NOTIFICATION.BUFFERACTIVATED])
        

        (For more on PythonScript and the user startup.py, and the need to set ATSTARTUP instead of LAZY for my instructions to work, see our FAQ: How to install and run a script in PythonScript)

        1 Reply Last reply Reply Quote 5

        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