Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    #region support for languages

    Help wanted · · · – – – · · ·
    3
    4
    359
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Noreh AD
      Noreh AD last edited by Noreh AD

      I managed to have #region (collapsing) work in a user defined language. Inspected the userDefineLang.xml and 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.xml and 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 langs.xml again.

      So if there’s a way to “hack” this functionality, it’d be great.

      Ekopalypse R 2 Replies Last reply Reply Quote 0
      • Ekopalypse
        Ekopalypse @Noreh AD last edited by

        @noreh-ad

        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.

        1 Reply Last reply Reply Quote 0
        • R
          rdipardo @Noreh AD last edited by

          @noreh-ad,

          The purpose of langs.xml is 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.preprocessor that “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 Notepad++.exe.

          1 Reply Last reply Reply Quote 3
          • Noreh AD
            Noreh AD last edited by

            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 (// #region and // #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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors