groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] extending a macro (prepending commands)


From: Keith MARSHALL
Subject: Re: [Groff] extending a macro (prepending commands)
Date: Thu, 24 Nov 2005 14:10:21 +0000

Gaius Mulley wrote:
> What is the best way to prepend commands to an existing macro.
> For example, say, in -ms how can one easily define a new `.LP'
> do some work and then call the original old `.LP' safely..
>
> Here is my example code and I'm puzzled at the infinite recursion
> when LP is invoked.
>
> [sample doc source snipped]

Hi Gaius,

The way you have done this looks about right.  I wonder if you are
being bitten by the internal workings of `s.tmac', for in reality
`LP' is defined as address@hidden', and then `LP' is made an alias for this;
furthermore, this alias is reasserted, at various points in a
variety of other `ms' macro invocations.  In fact, because of the
way the alias is initialised, it may refer to a one-time setup
macro, at the time you redefine it; your redefinition would then
put `ms' into an infinite initialisation logic loop.

This seems to produce the required behaviour:

--------8<---------------------------
.mso s.tmac
.pl 20            \" keep output on screen with `nroff -c'
.rn @LP address@hidden
.de @LP
.tm This is my LP extension.
address@hidden
..
.LP
Here is some text.
.LP
And here is some more.
--------8<---------------------------

BTW, keeping your example exactly as is, I reproduce your infinite
recursion, but if I add a `.SH' say, before the first `.LP', then I
see the behaviour I expected, except that the extended behaviour isn't
invoked; `.SH' implicitly reasserts `.als LP @LP', so overriding the
redefinition, which I would suggest confirms the initialisation loop
theory.  Redefining the address@hidden' macro, as above, gives expected 
behaviour,
including invocation of the extension, in either case.

Also note that you don't need to `.rm @LP' after the `.rn' -- it
doesn't exist at this point anyway.
 
HTH.

Regards,
Keith.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]