"} else {" as a new section
-
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:
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 -
@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 insetPowerShellLexer()
), 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:
vs
To be able to automatically do that, you could edit (or create) your user
startup.py
to includefrom 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)