#region support for languages
I managed to have #region (collapsing) work in a user defined language. Inspected the
userDefineLang.xmland found the following three lines:
<Keywords name="Folders in comment, open">#region</Keywords> <Keywords name="Folders in comment, middle"></Keywords> <Keywords name="Folders in comment, close">#endregion</Keywords>
Is there any way to add these to the
langs.xmland modify an existing language? I’d like to have the region functionality in some languages.
I came across another question (XAML Regions Not Supported) about regions, but it’s old and doesn’t answer my question.
Updating Notepad++/scintilla and having my modifications overwritten is not a real problem. I can just write a script that will run after an update and make the necessary changes in the
So if there’s a way to “hack” this functionality, it’d be great.
Unfortunately the general answer is rather no, the only reasonable way to achieve additional folding with existing lexers (languages) is to add this to the lexer code. Apart from that, it might be possible to “hack” something, but then you need to know which lexer you are talking about.
The purpose of
langs.xmlis configuring the editing component (to distinguish from the lexing component). That includes mapping file extensions to a programming language, listing what keywords are recognized, what characters to insert when you press the “Toggle Comment” key combo, etc. The editor may pass some of that information as input to a builtin lexer module. But that module already has an internal algorithm for code folding, and the recognized tokens are hard-coded. Most languages have fixed grammar and syntax rules, so a lexer programmer doesn’t usually leave room for a variety of folding tokens. The UDL lexer is obviously more flexible, because all the “grammar” is provided by you in the form of XML.
You can have limited control over a builtin lexer by knowing what properties it defines and setting them to a value or 1 (active) or 0 (inactive). Some editors using the same lexing component as N++ provide a means of setting those properties in config files — SciTE and Geany are examples — but N++ sets every lexer’s properties at compile time. You need a plugin like PythonScript to change them dynamically.
Supposing you wanted the C# lexer to fold between
#region . . . #endregion, there’s a builtin property called
fold.preprocessorthat “Includes C#'s explicit #region and #endregion folding directives”: https://www.scintilla.org/SciTEDoc.html#property-fold.preprocessor. Looking at N++'s code, you’ll see this property is already turned on for a bunch of C-like languages, C# included.
If you wanted another lexer to do that, such a property has to be already coded and exposed to the editor. If it’s not been coded yet, the only why to “modify” it is revising the C++ code, building a new lexer library, and a new
That’s a bummer. And modifying the source code for something like this seems like a hassle for me. So I’ll probably ignore it :)
In VS Code (might need extensions though), for example, regions that are in comments (
// #endregion) are supported (in languages like JS, PHP). It’d be nice to have something similar in Notepad++ too.
I usually use VS Code when I’m working on a project, but for quick modifications, I prefer Notepad++. So I definitely want to see Notepad++ improve.