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

      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