Community
    • Login

    Need help in enabling batch language outlining

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 4 Posters 12.7k Views
    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.
    • Jim DaileyJ
      Jim Dailey
      last edited by

      I believe the built-in languages are a Scintilla component (Scintilla is the actual editor within NPP).
      Support for syntax highlighting of batch files is there. Go to “Settings”->“Style Configurator…” and select “Batch” in the “Language:” box. The “Style:” box contains the various elements of the language that you can configure; LABEL is one of those elements.

      I suspect that you mean something other than syntax highlighting when you use the term “outlining”. Perhaps you want to enable folding of functions and if-else statements. I’m pretty sure to do that you’ll have to define your own language.using “Language”->“Define your language…”.

      Batch labels show up in “View”->“Function List” tool as functions. That might give you part of whatever it is you desire.

      1 Reply Last reply Reply Quote 0
      • TechTony2016T
        TechTony2016
        last edited by

        Yes, when I said “outlining”, I meant that I want to be able to fold/expand source code based upon the functions in the batch file (as is the capability in other languages). The syntax highlighting for batch is adequate.

        “View->Function List” lists the labels in a the batch file. So, that’s at least a start toward changing the source code to recognize that ‘exit /b’ denotes the end of a function. Since defining functions that way is completely optional (and there are other ways, like using ‘goto:eof’), I have a feeling the Scintilla and Notepad++ developers may not be interested in changing the code to support that (?), and I may be on my own to modify and recompile the source code.

        Defining a whole new language in Notepad++ (and that has its own limitations) when batch is already supported, seems like the wrong approach (?) and I have a feeling that the capability does not exist in the user-defined language facility (?) to define the end of a function as ‘exit /b’ so that source code can be folded on functions.

        More suggestions from anyone appreciated.

        1 Reply Last reply Reply Quote 0
        • Jim DaileyJ
          Jim Dailey
          last edited by

          If you define your own language, you can do some pretty interesting things. In my GAWK language definition, for example, I have 3 different settings for comments: “#” for normal ones that are somewhat subdued in appearance, “##” for ones describing a function that stand out more, and “#!” for things I really need to see (something temporarily commented out or maybe something I plan to delete later).

          I made a small test language. On the Folder & Default tab, in the Folding in code 1 style: Open: box I put:

          :Function (
          

          and in the Close: box I put

              EndFunction )
          

          That allows me to fold on “(”…“)” and “:Function<whatever>”…“EndFunction”

          So this is how my batch file would look:

          :FunctionStart
          if !%1 == ! (
              echo.
              echo Supply at least one argument!
              echo.
          )
          else (
              gawk -f %1
          )
          exit /b 0
          rem EndFunction
          

          I can fold the if, else, and the entire function. I could have used “exit” instead of EndFunction, but I imagine you might want multiple exit points. I suppose you could always goto a single exit point, though. And if you did that, you wouldn’t need the “REM EndFunction” line after every function.

          1 Reply Last reply Reply Quote 0
          • TechTony2016T
            TechTony2016
            last edited by

            Jim, your post prompted me to play-around with Notepad++'s user-defined language facilities. As my needs for syntax highlighting are modest, and my need for code-folding is much more important, I have found, that the user-defined-language capability of Notepad++ can *almost * satisfy my needs for working with batch files. The problem is that there is no option on the “Folder & Default” tab to “force at beginning of line” (as there is on the “Comment & Number” tab). Without that, colons beyond the first character of a line (standard batch labels and calling of functions) get a fold glyph in the fold margin. I don’t want to have to aberrate function names to facilitate folding, I want a colon in the first column to be the open fold trigger. ‘exit’ works fine as a folding close indicator.

            I’ve copied the keywords for batch language from langs.model.xml and used those in the “Keywords Lists” tab, to good success. If all I got were keywords and folding, I’d be a happy camper. Alas, the folding definition facilities in Notepad++ are not as comprehensive as comment definition facilities, so it looks like the Notepad++'s user-defined language capability is not going to work. (Read: Feature Request!).

            Noteworthy: Defining line comments as text preceded with a double colon, nicely overrides the single colon so the folding behaves correctly. I.e., comments are correctly distinguished from labels.

            1 Reply Last reply Reply Quote 0
            • TechTony2016T
              TechTony2016
              last edited by

              I have found that using the “Comment & Number” tab to define functions almost solves my problem. I specify “Comment line style” with just the open indicator as ‘::’, and specify the “Comment style” open/close indicators as ‘:’/‘exit /b’. The problem introduced, is that a function defined immediately after a line comment, is not recognized. E.g.:

              :: Line comment
              :func_name
              exit /b

              'func_name does not get a folding glyph in the fold margin.

              I know, I’m now trying to trick Notepad++ into doing what I want it to do.

              1 Reply Last reply Reply Quote 0
              • TechTony2016T
                TechTony2016
                last edited by

                That last attempt (described in my last post) won’t work: It turns the whole function into a comment, meaning no syntax highlighting. Duh! My bad.). I could use that when I need code folding, and then switch to syntax highlighting mode (by selecting a different user-defined language)–sounds like a temporary solution for now.

                1 Reply Last reply Reply Quote 0
                • TechTony2016T
                  TechTony2016
                  last edited by

                  Best solution so far using Notepad++ user-defined language capability (hardly perfect or complete, but useable):

                  Ignore case: checked
                  Ext: bat

                  Folder & Default
                  Folder & Default.Folding in code 1 style.Open: :
                  Folder & Default.Folding in code 1 style.Close: exit /b

                  Comment & Number
                  Allow preceeding whitespace: checked
                  Allow folding of comments: checked
                  Comment & Number.Comment line style.Open: :: echo call

                  Operators & Delimiters
                  Operators 1
                  = % ! & * :~ :% :! :break :loop :end

                  Keywords Lists
                  rem set if else exist errorlevel for in do break call copy chcp cd chdir choice cls country ctty date del erase dir echo exit goto loadfix loadhigh mkdir md move path pause prompt rename ren rmdir rd shift time type ver verify vol com con lpt nul defined not errorlevel cmdextversion setlocal endlocal

                  1 Reply Last reply Reply Quote 0
                  • Jim DaileyJ
                    Jim Dailey
                    last edited by

                    Glad you were able to get something usable working.

                    1 Reply Last reply Reply Quote 0
                    • TechTony2016T
                      TechTony2016
                      last edited by

                      It didn’t work out so well (what I posted last time), so I started instrumenting my batch code more so that it does, the concept being the same though. (E.g., using %{% and %}% to establish the function body).

                      1 Reply Last reply Reply Quote 0
                      • lee jeongwooL
                        lee jeongwoo
                        last edited by lee jeongwoo

                        Thank you for great ideas

                        I could make some my language but got a Problem.

                        I set

                        1. comment line: #
                        2. folder: #{ and #}

                        I expect both comment line and folder work, but its not.
                        Just a comment line works and folder do nothing.
                        Does anybody has a experience?

                        lee jeongwooL 1 Reply Last reply Reply Quote 0
                        • lee jeongwooL
                          lee jeongwoo @lee jeongwoo
                          last edited by

                          @lee-jeongwoo

                          => I did it wrong way.
                          Comment Line Folding works, Not just folding

                          Claudia FrankC 1 Reply Last reply Reply Quote 0
                          • Claudia FrankC
                            Claudia Frank @lee jeongwoo
                            last edited by

                            Hello @lee-jeongwoo,

                            you need to make it unique. At the moment # is a comment and should be also identified
                            as a folding char. What about using ## as comment?

                            Cheers
                            Claudia

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors