(m4.info)Changecom


Next: Changeword Prev: Changequote Up: Input Control
Enter node , (file) or (file)node

8.3 Changing the comment delimiters
===================================

The default comment delimiters can be changed with the builtin macro
'changecom':

 -- Builtin: changecom ([START], [END = '<NL>'])
     This sets START as the new begin-comment delimiter and END as the
     new end-comment delimiter.  If both arguments are missing, or START
     is void, then comments are disabled.  Otherwise, if END is missing
     or void, the default end-comment delimiter of newline is used.  The
     comment delimiters can be of any length.

     The expansion of 'changecom' is void.

     define(`comment', `COMMENT')
     =>
     # A normal comment
     =># A normal comment
     changecom(`/*', `*/')
     =>
     # Not a comment anymore
     =># Not a COMMENT anymore
     But: /* this is a comment now */ while this is not a comment
     =>But: /* this is a comment now */ while this is not a COMMENT

   Note how comments are copied to the output, much as if they were
quoted strings.  If you want the text inside a comment expanded, quote
the begin-comment delimiter.

   Calling 'changecom' without any arguments, or with START as the empty
string, will effectively disable the commenting mechanism.  To restore
the original comment start of '#', you must explicitly ask for it.  If
START is not empty, then an empty END will use the default end-comment
delimiter of newline, as otherwise, it would be impossible to end a
comment.  However, this is not portable, as some other 'm4'
implementations preserve the previous non-empty delimiters instead.

     define(`comment', `COMMENT')
     =>
     changecom
     =>
     # Not a comment anymore
     =># Not a COMMENT anymore
     changecom(`#', `')
     =>
     # comment again
     =># comment again

   The comment strings can safely contain eight-bit characters.  If no
single character is appropriate, START and END can be of any length.
Other implementations cap the delimiter length to five characters, but
GNU has no inherent limit.

   Comments are recognized in preference to macros.  However, this is
not compatible with other implementations, where macros and even quoting
takes precedence over comments, so it may change in a future release.
For portability, this means that START should not begin with a letter,
digit, or '_' (underscore), and that neither the start-quote nor the
start-comment string should be a prefix of the other.

     define(`hi', `HI')
     =>
     define(`hi1hi2', `hello')
     =>
     changecom(`q', `Q')
     =>
     q hi Q hi
     =>q hi Q HI
     changecom(`1', `2')
     =>
     hi1hi2
     =>hello
     hi 1hi2
     =>HI 1hi2

   Comments are recognized in preference to argument collection.  In
particular, if START is a single '(', then argument collection is
effectively disabled.  For portability with other implementations, it is
a good idea to avoid '(', ',', and ')' as the first character in START.

     define(`echo', `$#:$*:$@:')
     =>
     define(`hi', `HI')
     =>
     changecom(`(',`)')
     =>
     echo(hi)
     =>0:::(hi)
     changecom
     =>
     changecom(`((', `))')
     =>
     echo(hi)
     =>1:HI:HI:
     echo((hi))
     =>0:::((hi))
     changecom(`,', `)')
     =>
     echo(hi,hi)bye)
     =>1:HI,hi)bye:HI,hi)bye:
     changecom
     =>
     echo(hi,`,`'hi',hi)
     =>3:HI,,HI,HI:HI,,`'hi,HI:
     echo(hi,`,`'hi',hi`'changecom(`,,', `hi'))
     =>3:HI,,`'hi,HI:HI,,`'hi,HI:

   It is an error if the end of file occurs within a comment.

     changecom(`/*', `*/')
     =>
     /*dangling comment
     ^D
     error->m4:stdin:2: ERROR: end of file in comment


automatically generated by info2www version 1.2.2.9