m4: Improved cleardivert
1
1 17.6 Solution for 'cleardivert'
1 ===============================
1
1 The 'cleardivert' macro (⇒Cleardivert) cannot, as it stands, be
1 called without arguments to clear all pending diversions. That is
1 because using undivert with an empty string for an argument is different
1 than using it with no arguments at all. Compare the earlier definition
1 with one that takes the number of arguments into account:
1
1 define(`cleardivert',
1 `pushdef(`_n', divnum)divert(`-1')undivert($@)divert(_n)popdef(`_n')')
1 =>
1 divert(`1')one
1 divert
1 =>
1 cleardivert
1 =>
1 undivert
1 =>one
1 =>
1 define(`cleardivert',
1 `pushdef(`_num', divnum)divert(`-1')ifelse(`$#', `0',
1 `undivert`'', `undivert($@)')divert(_num)popdef(`_num')')
1 =>
1 divert(`2')two
1 divert
1 =>
1 cleardivert
1 =>
1 undivert
1 =>
1