How to fold code in a specific manner?
Hi there, automation engineer here with limited coding experience. I am working with some DeltaV .fhx files and I’m interested in viewing them in notepad++ with certain parts of the code already folded, either by tweaking npp settings or running a script/macro/plug-in at startup that will do this for me after opening.
- The “collapse level” function doesn’t work as expected (similar elements are not on the same level)
The solution in my head is a script I can loop through the code looking for a specific string of text (e.g. “ACTION NAME=”*"" where * is a wildcard), then fold / collapse the NEXT fold point in the code. Is this possible?
Any help would be greatly appreciated!
P.S. What is the difference in folding and collapsing?
Ekopalypse last edited by
Have you tried to create a UDL (User Defined Language) for it?
There is no difference between folding and collapsing, except that collapsing/expanding is called folding. At least as far as I know.
PeterJones last edited by
If the ACTION NAME is at various levels, but you just want to show those and fold any below those, I am not sure whether UDL would be able to help, because I don’t think we could define the next level down only relative to the ACTION NAME match.
It be helpful to show a small example (maybe 10-20 lines), which shows how it can be at different levels… and maybe even have you show a screenshot with applying JSON interpretation in Notepad++ and manually fold what you want it to be.
But since you’re willing to accept scripting, you might want to look at my “save folding” script from earlier this year, which shows the concepts involved in saving or loading folds – and thus shows you how to collapse or un-collapse a given block. You might then be able to adapt those ideas to search for your own keywords (like ACTION NAME) to decide whether a given level is folded or not.
After you’ve given that a go, if you’re having trouble, you could share your version of the script, along with sample data that fails, and we might be able to give a hint as to what’s going wrong.
@PeterJones thanks so much for your detailed response. I’ll take a look at the post you linked to and put some thought into how I can tailor it to meet my needs.
@Ekopalypse thanks for the suggestion. Unfortunately the file structure is what I would call a little “wonky”, with similar elements existing on different levels, so I don’t think defining a UDL alone won’t get me there. In any case I appreciate your response!