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?
-
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?
-
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
#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
andfold.at.else
which can be changed by a scripting plugin. Thefold.comment
option does affect theregion
comment folding and the value set is1
to 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.