Updated my above post to include the workaround to avoid, that single digits are interpreted as handle numbers.
Applied some minor changes, too.
penpen
Comments without increasing macro size
Moderator: DosItHelp
Re: Comments without increasing macro size
So a solution, for properly embedding comments in macro's.
quite old and tested, as is this topic.
Comments go into %==% which can appear anywhere in the code.
But A double colon can not be part of the comment,
quite old and tested, as is this topic.
Code: Select all
@echo off &set $lf=^
:: end of linefeed definition
set ^"$c1=%%~#^<nul ^^"
set ^"$n1c=^^^%$lf%%$lf%^%$lf%%$lf%^<nul ^^"
%==%for %%# in ("") do set ^"printText=for %%? in (1,2) do if %%?==2 (setlocal enableDelayedExpansion%$n1c%
%$c1%
%= =%echo.^^^!*:~1^^^!%$n1c%
%$c1%
%==%endlocal^&endlocal)else setlocal disableDelayedExpansion^&set *="
( %printText% Hello World ^! )
( %printText% How are you today ? )
pause
But A double colon can not be part of the comment,
I could not find a construct or context where that extra '^<nul ' introduced some unexpected/different behaviors.Liviu wrote:Ed Dyreen wrote:I prefer penpen's solution, so I can just use \n without any conditions.
That's a nifty craft of penpen's, no argument there. But if you want to "just use \n without any conditions" then you have to append that '^<nul ' to the '\n' macro definition itself. I can't say I followed every bit and lead, so I may well be missing something, but I don't know that it's been established beyond doubt that there is no construct or context where that extra '^<nul ' could possibly introduce some unexpected/different behaviors. In fact, you were the first one to point such a suspect case http://www.dostips.com/forum/viewtopic.php?p=32592#p32592 earlier in this very thread.