Next: , Previous: , Up: Registers   [Contents][Index]


5.8.3 Auto-increment

Registers can also be incremented or decremented by a configured amount at the time they are interpolated. The value of the increment is specified with a third argument to the nr request, and a special interpolation syntax is used to alter and then retrieve the register’s value. Together, these features are called auto-increment.51

Request: .nr ident value incr

Set register ident to value and its auto-incrementation amount to to incr. The \R escape sequence doesn’t support an incr argument.

Auto-incrementation is not completely automatic; the \n escape sequence in its basic form never alters the value of a register. To apply auto-incrementation to a register, interpolate it with ‘\ną’.

Escape sequence: \n+i
Escape sequence: \n-i
Escape sequence: \n+(id
Escape sequence: \n-(id
Escape sequence: \n+[ident]
Escape sequence: \n-[ident]

Increment or decrement ident (one-character name i, two-character name id) by the register’s auto-incrementation value and then interpolate the new register value. If ident has no auto-incrementation value, interpolate as with \n.

.nr a 0 1
.nr xx 0 5
.nr foo 0 -2
\n+a, \n+a, \n+a, \n+a, \n+a
.br
\n-(xx, \n-(xx, \n-(xx, \n-(xx, \n-(xx
.br
\n+[foo], \n+[foo], \n+[foo], \n+[foo], \n+[foo]
    ⇒ 1, 2, 3, 4, 5
    ⇒ -5, -10, -15, -20, -25
    ⇒ -2, -4, -6, -8, -10

To change the increment value without changing the value of a register, assign the register’s value to itself by interpolating it, and specify the desired increment normally. Apply an increment of ‘0’ to disable auto-incrementation of the register.


Next: , Previous: , Up: Registers   [Contents][Index]