How do I create a custom fold in PowerShell
-
Is there a way to add a custom collapse option for PowerShell function Param() sections in the config file(s) for .psm1 files?
-
@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.
-
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
-
@PeterJones Thanks, so it sounds like a feature request is my best bet, do you agree?
-
@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-Stewart You could use
#regionand#endregionto 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,twocan 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,twoThere 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.compactandfold.at.elsewhich can be changed by a scripting plugin. Thefold.commentoption does affect theregioncomment folding and the value set is1to allow comment folding. -
@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.
-
@PeterJones Thanks, I’ll look into that.
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