* * SEQNUM.KEX * * Mark a box block and run this macro to fill the block with sequence numbers. * You can specify whether the numbers are left- or right-adjusted within the * block, whether they are padded with blanks or zeroes, the starting sequence * number and the increment value. If a sequence number is too large to fit in * the block then a string of asterisks is substituted to indicate an error. * * Works with: * * KEDIT for Windows 1.5 * KEDIT 5.0 for DOS * KEDIT 5.0 for OS/2 * * By default, numbers are left-adjusted, padded on the left with zeroes, the * first sequence number is one and numbers are incremented by one. To change * any of these defaults see below: * * Original author: Kent Downs, MSG, 8/96 * ***** Modify the items below to adjust the number formatting ***** * Set this to 0 to right-adjust numbers LeftAdjustNumbers = 1 * Set this to 0 to pad with blanks PadWithZeroes = 1 * Set this to the desired starting sequence number FirstSeqNumber = 1 * Set this to the desired sequence number increment value IncrementValue = 1 ***** Modify the items above to adjust the number formatting ***** if block.1() = "NONE" then do "emsg SEQNUM Error 1: You forgot to mark a box block" exit 1 end if block.1() \= "BOX" then do "emsg SEQNUM Error 2: Only box blocks are supported" exit 2 end if block.6() \= fileid.1() then do "emsg SEQNUM Error 3: Block must be in the current file" exit 3 end "preserve" "autosave off" "sos blockstart" ResetBlock = 0 if version.1() = "KEDIT/WINDOWS" then do if block.7() = "SELECTION" then do ResetBlock = 1 "mark persistent" end end LeftBlockCol = block.3() RightBlockCol = block.5() BlockWidth = RightBlockCol - LeftBlockCol + 1 counter = FirstSeqNumber if PadWithZeroes = 1 then PadChar = "0" else PadChar = " " * Loop through each line of the box block do forever if line.1() > block.4() then leave * The numbers will need to be padded so that no text is shifted when we * insert them if length(counter) = BlockWidth then NumberPad = "" else if length(counter) < BlockWidth then NumberPad = copies(PadChar, BlockWidth - length(counter)) if LeftAdjustNumbers then LineNum = NumberPad || counter else LineNum = counter || NumberPad line = curline.3() if LeftBlockCol = 1 then do front = "" back = substr(line, RightBlockCol + 1) end else do front = substr(line, 1, LeftBlockCol - 1) back = substr(line, RightBlockCol + 1) end * Replace the current line with a new one containing the line number if length(counter) > BlockWidth then do * Error - box is not wide enough to accommodate the sequence number "replace" front || copies("*", BlockWidth) || back end else "replace" front || LineNum || back "down 1" counter = counter + IncrementValue end "top" "restore" if ResetBlock then "reset block"