pashi icon indicating copy to clipboard operation
pashi copied to clipboard

Add option to restart line numbering between files

Open delphidabbler opened this issue 3 years ago • 5 comments

Currently, when two or more files are concatenated, line numbers continue. It would be useful if line numbering could be restarted between files.

We also need to consider whether or not to number the separator lines between files at all.

delphidabbler avatar Aug 29 '22 13:08 delphidabbler

With regard to inhibiting numbering of separator lines see issue ~~#48~~ #62.

delphidabbler avatar Oct 20 '22 21:10 delphidabbler

RE

We also need to consider whether or not to number the separator lines between files at all.

AND

With regard to inhibiting numbering of separator lines see issue ~~#48~~ #62.

How about a new Boolean --separator-line-numbering option that enables / disables numbering of separator lines? The default would be off and it would be ignored if --line-numbering is off.

delphidabbler avatar Oct 23 '22 10:10 delphidabbler

How about a new Boolean --separator-line-numbering option that enables / disables numbering of separator lines? The default would be off and it would be ignored if --line-numbering is off.

The separator-line-numbering proposal has been split out into its own issue (#62) and won't be considered further here.

This issue will concentrate only on its original topic, i.e. on options to restart line numbering between files.

delphidabbler avatar Oct 23 '22 12:10 delphidabbler

It's worth considering if the existing --line-number-start command can be extended.

Presently the command takes a single parameter, the number on which to start numbering lines. This number is incremented by one for each line and continues being incremented across each file.

Here are some ideas for parameters that might make the command usable to reset line numbering:

  1. X (where X is a number in range 1...9999): X is the number on which to start numbering the 1st file. Numbers increase across all files without resetting. This is the current usage of the command, except that 0 is now permitted as the lowest line number instead of 1.

  2. *X (where X is a number in range 0...9999): All files are numbered starting from line X. Numbers reset to X at the start of the next file.

  3. [X1,X2,..,Xn] (where all Xs are numbers in range 0..9999): A comma separated, non-empty, list of line numbers. Numbering of the 1st file starts at X1, the 2nd file at X2, etc. If there are fewer numbers in the list than files then the last value, Xn, is used for all files for which no number is specified. If there are too many numbers in the list then excess list entries are ignored.

  4. X+Y (where X is a number in the range 0..9999 and Y is a number in the range 1..1000): Files are numbered starting from line X + (N - 1) × Y, where N is the number of the file, starting at 1. So, if X=1 and Y=100, file 1 starts numbering at 1, file 2 starts at 101, file 3 starts at 201, and so on.

  5. X^Y (where X is a number in range 0..9999 & Y is a number in range 1..3): The first file is numbered starting from line X. Files after the first are numbered starting from line Z × 10^Y + X, where Z is the smallest number such that L < Z × 10^Y and L is the greatest line number in the previous file. For e.g. if L=349, X=1 and Y=2 then Z is chosen so that 349 < Z × 100. The smallest Z satisfying this condition is Z=4, so the starting line for the file is 4 × 100 + 1 = 401. If L=249 then Z=3 and the next starting line is 301, or if L=500 then Z=6 and the next line is 601.

Any of the above parameters can be followed by /X, where X is the gap between adjacent line numbers, in the range 1..100. If /X is omitted then X is taken to be 1. As a simple example, the parameter 10/10 starts lines numbering from 10 and increments in steps of 10 without resetting between files - shades of BASIC! A more complex example would be [10,1010,2010]/10 will number file 1 from 10 in steps of 10, file 2 from 1010 in steps of 10 and file 3 from 2010 in steps of 10.

The default parameter is 1/1 (= 1) which is functionally the same as the current default.

delphidabbler avatar Oct 23 '22 13:10 delphidabbler

A more complex example would be [10,1010,2010]/10 will number file 1 from 10 in steps of 10, file 2 from 1010 in steps of 10 and file 3 from 2010 in steps of 10.

Could we also support different line steps for each file by using something like [10/10,1020/20,2000/100] to number file 1 from 10 in steps of 10, file 2 from 1020 in steps of 20 and file 3 from 2000 in steps of 100?

delphidabbler avatar Oct 25 '22 16:10 delphidabbler