Community
    • Login

    "} else {" as a new section

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 Posters 192 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.
    • Bert NieuwenampsenB
      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
        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
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors