Here it is:
Code: Select all
@echo off
set "/:=goto :/%%"
%/:%
multi
line
comment
%:/%
echo not commented 1
%/:%
another
multi
line
comment
%:/%
echo not commented 2
It uses one 'feature' of GOTO - you can put a single symbol (if it is not : ) in front of the label and the GOTO will still be able to find it (hope this is not something working only on my machine).Though the leading % in the closing comment can be skipped (and also the one at the end in the closing comment) it triggers my OCD with it's lack of symetry .Also when ':' is the last symbol in the variable name substring or replacement are not started when the variable is used.
This looks almost like the comments in the "serious" programming languages. Even all kind of brackets can be used:
Code: Select all
@echo off
set "(:=goto :)%%"
echo not commented 1
%(:%
multi
line
comment
%:)%
set "[:=goto :]%%"
%[:%
another
multi
line
comment
%:]%
echo not commented 2
This gives me a feeling of a something closed...
The negative conditional comment also can be improved a little bit (in case multi line comment in a brackets context is needed):
Code: Select all
@echo off
rem[||([
multi line
comment
])
echo not commented 1
rem/||(/
another
comment
/)
echo not commented 2
It also can be shorterened with a macros (and thus both techniques could be alligned with similar symbols):
Code: Select all
@echo off
::comment macros
set "[=rem/||(" & set "]=)"
for /f %%a in ('echo comment tests') do (
echo not commented 1
%[%
multi
line
comment
%]%
echo not commented 2
)
Code: Select all
@echo off
::comment macros
set "(=rem/||(" & set ")=)"
for /f %%a in ('echo comment tests') do (
echo not commented 1
%(%
multi
line
comment
%)%
echo not commented 2
)
Of course it is a matter of a personal taste , may be it's only me who find these more pleasing.
And the final result:
Code: Select all
@echo off
::GOTO comment macro
set "[:=goto :]%%"
::brackets comment macros
set "[=rem/||(" & set "]=)"
::testing
echo not commented 1
%[:%
multi
line
comment outside of brackets
%:]%
echo not commented 2
%[:%
second multi
line
comment outside of brackets
%:]%
::GOTO macro cannot be used inside for
for %%a in (first second) do (
echo first not commented line of the %%a execution
%[%
multi line
comment
%]%
echo second not commented line of the %%a execution
)