Community
    • Login

    How do I create a custom fold in PowerShell

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 313 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.
    • David A. StewartD
      David A. Stewart
      last edited by

      Is there a way to add a custom collapse option for PowerShell function Param() sections in the config file(s) for .psm1 files?

      PeterJonesP mpheathM 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @David A. Stewart
        last edited by PeterJones

        @David-A-Stewart ,

        In general, where things fold is a function of the underlying lexer (from the Lexilla library that Notepad++ uses), and there isn’t customization available for that.

        I think you could use one of the scripting plugins like PythonScript to add a custom fold point using a notification-on-change callback, and some of the commands, but I don’t know how stable custom folds are when Notepad++/Lexilla is also trying to control folding.

        PeterJonesP David A. StewartD 2 Replies Last reply Reply Quote 2
        • PeterJonesP
          PeterJones @PeterJones
          last edited by

          moderator note: I re-created your post under a different name; something about the previous title used is triggering a weird forum bug. Sorry to all the people who see, but cannot read, multiple copies with a similar name. I will try to clean up the database.

          update: I think I’ve cleaned up the database; sorry for any who were confused by the extra empty/unavailble posts

          1 Reply Last reply Reply Quote 2
          • David A. StewartD
            David A. Stewart @PeterJones
            last edited by

            @PeterJones Thanks, so it sounds like a feature request is my best bet, do you agree?

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @David A. Stewart
              last edited by

              @David-A-Stewart ,

              so it sounds like a feature request is my best bet

              Notepad++ uses a library called Lexilla to handle the lexing (syntax highlighting and folding and the like), so you’d have to check the Lexilla Issues list and see if such a request already exists, and if not, put it in there; once the feature is in Lexilla, then Notepad++ would have to update to the most recent version of Lexilla for a future release. Good luck.

              David A. StewartD 1 Reply Last reply Reply Quote 3
              • mpheathM
                mpheath @David A. Stewart
                last edited by mpheath

                @David-A-Stewart You could use #region and #endregion to do explicit folding in Powershell. These are case-sensitive so must be lowercase to be recognized by the Powershell lexer.

                example1 :

                function Test-Remainder {
                    param(
                        [Parameter(Mandatory, Position=0)]
                        [string]$Value,
                
                    [Parameter(Position=1, ValueFromRemainingArguments)]
                        [string[]]$Remaining
                    )
                
                    "Found $($Remaining.Count) elements"
                
                    for ($i = 0; $i -lt $Remaining.Count; $i++) {
                        "${i}: $($Remaining[$i])"
                    }
                }
                Test-Remainder first one,two
                

                can be edited to :

                function Test-Remainder {
                    #region
                    param(
                        [Parameter(Mandatory, Position=0)]
                        [string]$Value,
                
                    [Parameter(Position=1, ValueFromRemainingArguments)]
                        [string[]]$Remaining
                    )
                    #endregion
                
                    "Found $($Remaining.Count) elements"
                
                    for ($i = 0; $i -lt $Remaining.Count; $i++) {
                        "${i}: $($Remaining[$i])"
                    }
                }
                Test-Remainder first one,two
                

                There are no other explicit comments in the Powershell lexer like some lexers have, like #{ and #} to cause extra folding.

                The folding options of the Powershell lexer are fold.comment, fold.compact and fold.at.else which can be changed by a scripting plugin. The fold.comment option does affect the region comment folding and the value set is 1 to allow comment folding.

                David A. StewartD 1 Reply Last reply Reply Quote 0
                • David A. StewartD
                  David A. Stewart @mpheath
                  last edited by

                  @mpheath Thanks, that is what I have been doing so far, but it’s a band-aid, I do appreciate taking the time to respond. I have not dug into the Notepad++ options too much, except where I use them to write scripts.

                  1 Reply Last reply Reply Quote 0
                  • David A. StewartD
                    David A. Stewart @PeterJones
                    last edited by

                    @PeterJones Thanks, I’ll look into that.

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