Brown
University
Women Writers Project
Research and Encoding
Training Materials |
wwp-search-and-insert-count is a command for inserting an incrementing count into a file. That is, it inserts a "01" on the first match, a "02" on the second match, and an "87" on the eighty-seventh match. (Actually, it inserts whatever number of leading zeroes are required, so if the last match was number 4,570 then it would insert "0001" for the first match.)
This is intended primarily for the n= of PB in renovation texts, but is a general-purpose command that will handle any straight positive sequence.
For example, you might want to assign unique id=s to every line of a poem. I.e., if you have
<l>I met him in a swamp down in Dagobah</l>
<l>Where it bubbles all the time</l>
<l>Like a giant carbonated soda</l>
<l>S-O-D-A, soda</l>
...
<l>The long-term contract I had to sign</l>
<l>Says I'll be making these movies 'til the end of time</l>
<l>With my Yoda</l>
<l>Yo-Yo-Yo-Yo Yoda</l>
<l>Yo-Yo-Yo-Yo Yoda</l>
you might want
<l id="Yoda01">I met him in a swamp down in Dagobah</l>
<l id="Yoda02">Where it bubbles all the time</l>
<l id="Yoda03">Like a giant carbonated soda</l>
<l id="Yoda04">S-O-D-A, soda</l>
...
<l id="Yoda47">The long-term contract I had to sign</l>
<l id="Yoda48">Says I'll be making these movies till the end of time</l>
<l id="Yoda49">With my Yoda</l>
<l id="Yoda50">Yo-Yo-Yo-Yo Yoda</l>
<l id="Yoda51">Yo-Yo-Yo-Yo Yoda</l>
The program, called wwp-search-and-insert-count, works by inserting the count into the null subexpression of a regexp. So, in order to turn
<pb/>
<pb/>
<pb/>
...
<pb/>
into
<pb n="01"/>
<pb n="02"/>
<pb n="03"/>
...
<pb n="87"/>
you have to first issue a regular search and replace command to change them to
<pb n=""/>
<pb n=""/>
<pb n=""/>
...
<pb n=""/>
Then issue M-x wwp-search-and-insert-count; you will be prompted for
a regular expresion. Enter
<pb n="\(\)"/>
or some such (you have to be careful that your regexp will not be too
specific and miss, e.g., '<pb id="duck" n=""/>', nor be too general
and catch an n="" that is not on a PB). The sequence "\(\)" defines a
subexpression which is null. That's where wwp-search-and-insert-count
will put the count.
Like any global change command, this one is potentially dangerous. It knows nothing about sequencing errors, for example. It is up to you to make sure ahead of time that the elements you want to change are will all match, are the only ones that will match, and are in the right order. Three things to help you with this:
Note: as currently written, not only must there be a null
subexpression in the regular expression, but it must be the first
subexpression. Thus,
<pb\( id="...."\)? n="\(\)"/>
won't work, although
<pb n="\(\)"\( id="...."\)?/>
will, I think. If this restriction turns out to be a major problem, I
can probably remove it.
If you want to really screw up a file royally, use
e\(\)
as the regular expression.