Comments without increasing macro size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Comments without increasing macro size

#31 Post by penpen » 24 May 2014 03:09

Updated my above post to include the workaround to avoid, that single digits are interpreted as handle numbers.
Applied some minor changes, too.

penpen

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Comments without increasing macro size

#32 Post by Ed Dyreen » 24 Jan 2016 16:48

So a solution, for properly embedding comments in macro's.

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
Comments go into %==% which can appear anywhere in the code.
But A double colon can not be part of the comment, :?

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.
I could not find a construct or context where that extra '^<nul ' introduced some unexpected/different behaviors.

Post Reply