How to add support for batch language functions in Scintilla/Notepad++ (?)

155 views
Skip to first unread message

techto...@outlook.com

unread,
Jan 27, 2016, 8:56:59 AM1/27/16
to scintilla-interest
(I'm just cut-n-pasting from the posts I made already in the Notepad++ Community Forum, AND in the scite Google group. I think I've finally found the right place to post this issue).

Functions in batch language are not really a feature of the language–all that is provided are the mechanisms to make functions hackishly work. Those mechanisms are: batch file labels, and the ‘exit /b’ statement. Since batch does not have “real” functions, the outlining functionality of Notepad++ is not available for .bat files. I.e., Notepad++ does not recognize the patterns of use of the label and ‘exit /b’ mechanisms that define functions. Opening the function list window, though, lists the labels in a batch file.

I would like to enable outlining of batch file functions. Newer versions of the Windows command shell allow returning from a ‘call’ via ‘exit /b’ (or ‘goto:eof’). I would like to enable outlining in batch files as in other languages with functions. But how to do it? Modify a source file and recompile? Modify or add a config file? (I have not looked at the source much, as I thought it would be easier to just ask here first). Check out the detail below and please let me know if you can direct me to the code or config file to change/add or if you guys want to do it, power to ya. Thanks.

************

A function in batch language looks like this:

: <label>
:: A double colon can be a comment instead of using ‘REM’. (I use the double colon and have this enabled via Notepad++ config file settings).
:: Body of function.
exit /b <exit code>

where “label” is the function name, and where “exit code” is a signed integer in the range –2,147,483,647 to 2,147,483,647 or an environment variable in the form: %var_name% set to the value of a signed integer in that range.

For example:

:DoSomething
echo.Hello world!
set /a exit_code = 0
exit /b %exit_code%

The function is called thusly (within the same batch file):

call :DoSomething

or, if DoSomething is in another batch file:

call otherbatchfile.bat :DoSomething

(Note: batch language is not case sensitive, though I use camel case for function names).

Arguments can be passed to functions also:

:DoSomethingElse
set var1=%~1
set var2=%~2
echo.%var1% %var2%!
set /a exit_code = 0
exit /b %exit_code%

call :DoSomethingElse “Hello” “World”

KHMan

unread,
Jan 27, 2016, 9:04:27 AM1/27/16
to scintilla...@googlegroups.com
On 1/27/2016 9:05 PM, techto...@outlook.com wrote:
> [snip]
> I would like to enable outlining of batch file functions. Newer versions of the Windows command shell allow returning from a ‘call’ via ‘exit /b’ (or ‘goto:eof’). I would like to enable outlining in batch files as in other languages with functions. But how to do it? Modify a source file and recompile? Modify or add a config file? (I have not looked at the source much, as I thought it would be easier to just ask here first). Check out the detail below and please let me know if you can direct me to the code or config file to change/add or if you guys want to do it, power to ya. Thanks.

This is probably the right place.

There is already some styling for labels. But what do you mean by
"outlining"? Folding? If folding, then you need to add some C++
code in scintilla/lexers/LexBatch.cxx. Contribute/discuss here and
improvements will filter down to all editors using Scintilla.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

techto...@outlook.com

unread,
Jan 27, 2016, 5:10:10 PM1/27/16
to scintilla-interest
On Wednesday, January 27, 2016 at 8:04:27 AM UTC-6, KHMan wrote:

>This is probably the right place.
Great.

>There is already some styling for labels. But what do you mean by
>"outlining"? Folding? If folding, then you need to add some C++
>code in scintilla/lexers/LexBatch.cxx. Contribute/discuss here and
>improvements will filter down to all editors using Scintilla.

Yes, by "outlining" I mean folding. I've noted that opening the function list window in Notepad++ lists the labels in a batch file. Again, though, I don't know if the developers would want to support batch file functions since it's pretty much just up to any particular developer to use the provided mechanisms in batch language to implement functions. Most people just use batch for linear lists of commands in scripts rather than for structured coding. Perhaps there should be "batch" and "structured batch" as supported languages in Scintilla--that sounds lucrative. I was wondering, first of all, whether modifying Scintilla is something I'd have to do or if the developers would do it. I'm not an open source developer. You have indicated that the way to implement this is indeed to modify the source code, which sets the direction going forward on this.

KHMan

unread,
Jan 27, 2016, 7:36:02 PM1/27/16
to scintilla...@googlegroups.com
On 1/28/2016 6:10 AM, techto...@outlook.com wrote:
> On Wednesday, January 27, 2016 at 8:04:27 AM UTC-6, KHMan wrote:
>
> >This is probably the right place.
>
> Great.
>
> >There is already some styling for labels. But what do you
> mean by
> >"outlining"? Folding? If folding, then you need to add some C++
> >code in scintilla/lexers/LexBatch.cxx. Contribute/discuss
> here and
> >improvements will filter down to all editors using Scintilla.
>
> Yes, by "outlining" I mean folding. I've noted that opening
> the function list window in Notepad++ lists the labels in a
> batch file.
[snip snip]

Sounds like a Notepad++ feature (I have Notepad++ installed
occasionally but use SciTE). A Scintilla lexer does styling and
folding only, and you can check this with SciTE as the baseline
editor (this is what I use/do as an occasional lexer contributor.)

I think the IDE-like features are in the Notepad++ codebase.
Nothing like this in SciTE. The folks at Notepad++ are quick to
point language styling requests or bugs to Scintilla, but it looks
like in this case they may have jumped the gun...

Andreas Tscharner

unread,
Mar 7, 2016, 7:50:18 AM3/7/16
to scintilla...@googlegroups.com
On 27.01.2016 15:04, KHMan wrote:

[snip]
> "outlining"? Folding? If folding, then you need to add some C++ code in
> scintilla/lexers/LexBatch.cxx. Contribute/discuss here and improvements
> will filter down to all editors using Scintilla.

On the Scintilla Documentation page
(http://www.scintilla.org/ScintillaDoc.html) at the top there seem to be
at least three links that deal with folding:

* A detailed description of how to write a lexer, including a discussion
of folding.
* How to implement folding.
* Beginner's Guide to lexing and folding.

Best regards
Andreas
--
Andreas Tscharner <sterne...@gmail.com>
----------------------------------------------------------------------
"Intruder on level one. All Aliens please proceed to level one."
-- Call in "Alien: Resurrection"

KHMan

unread,
Mar 7, 2016, 8:58:49 AM3/7/16
to scintilla...@googlegroups.com
On 3/7/2016 8:50 PM, Andreas Tscharner wrote:
> On 27.01.2016 15:04, KHMan wrote:
>
> [snip]
>> "outlining"? Folding? If folding, then you need to add some C++
>> code in
>> scintilla/lexers/LexBatch.cxx. Contribute/discuss here and
>> improvements
>> will filter down to all editors using Scintilla.
>
> On the Scintilla Documentation page
> (http://www.scintilla.org/ScintillaDoc.html) at the top there seem
> to be at least three links that deal with folding:
>
> * A detailed description of how to write a lexer, including a
> discussion of folding.
> * How to implement folding.
> * Beginner's Guide to lexing and folding.

This discussion is from January 2016. Any reason why you are
resurrecting an old thread? IMHO there is no point to resurrect an
old thread when the original poster has not pursued the
possibility of coding it himself.
Reply all
Reply to author
Forward
0 new messages