Macro to insert inputted string before digit(s):digit(s)

Get help using and writing Nisus Writer Pro macros.
Post Reply
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Macro to insert inputted string before digit(s):digit(s)

Post by NisusUser »

Hi, everybody.

I'm working on Bible verse references in some files and need to insert book abbreviations before digits identifying chapter[colon]verse.

I'm wondering if someone would be so kind as to make a macro for me that would would work on selected text and …

… allow me to input the string I'd like before the "digit(s):digit(s) items. In one file or selection it will be something like "Gen." or "Gen" or even "Ge". It'd be something different in another selection.

Info:
  • There are always one of two things before the "digit(s):digit(s)" string: either (1) a return, or (2) a line break. I.e., any "digit(s):digit(s)" found in the selection that do not follow either a return or a line break should not have the abbreviation appended (see "Ecclesiastes 12:13" below which should not become "Ecclesiastes Gen 12:13").
  • The sets of digits on either side of the colon could be 1, 2 or 3 digits long, e.g., "119:1", "119:28", "119:150".
  • The macro would ask me what to use as an abbreviation. I'd input "Gen" or some other abbreviation.
Some text here[return]
1:2 A comment is made here. Then something else is said about 10:15,[line break, aka soft return]49:12. Later there is a comment about Ecclesiastes 12:13.
The result would be (except the bold would not be there, of course; I used it to show what's been added – the bold text plus a space after the abbreviation) …
Some text here[return]
Gen 1:2 A comment is made here. Then something else is said about Gen 10:15,[line break, aka soft return]Gen 49:12. Later there is a comment about Ecclesiastes 12:13.
Thank you!
credneb
Posts: 187
Joined: 2007-03-28 07:30:34

Re: Macro to insert inputted string before digit(s):digit(s)

Post by credneb »

If understood correctly, you want to:

(1) type "12:3 and some text and then 13:4 15:123 and some text and then maybe 45:3."
(2) select "12:3 and some text and then 13:4 15:123" and apply the macro, which must prompt you for the book ref, to get
(3) Gen 12:3 and some text and then Gen 13:4 (line break) Gen 15:123
(4) then select 45:3, apply the macro and get Ecc 45.3

which seems like a lot of work and error-prone considering needing to type the digit(s):digit(s), saving only typing the book reference, and then selecting the bits of text.

I would suggest changing the work flow by using the glossary function. Create a glossary abbreviation for each book with the desired expansion. So maybe
gg -> GEN
ec -> ECC
The glossary expansions can be defined with the formatting desired, so GEN could be bold, italic, or whatever. All of your returns and breaks would be inserted where you want when you type.

You then type "gg 12:3 and some text and then gg 13:4 (line break) gg 15:123 and some text and then maybe ecc 45:3" getting

GEN 12:3 and some text and then GEN 13:4 (line break) GEN 15:123 and some text and then maybe ECC 45:3.
in real time. You can insert the line breaks wherever wanted. And you'll know immediately if the book references are correct.

Hope this isn't too far off base.

Cliff
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Macro to insert inputted string before digit(s):digit(s)

Post by adryan »

G'day, NisusUser et al

There is a big problem here, in that the second verse reference in your example (viz, "10:15") is not preceded by either a paragraph return or a soft return, and yet it seems from the transformed text you cite that you still wanted it preceded by your chosen text string.

If this is in fact an error and you really want what you specified in your Info list, I have devised a Macro that does it. I can post it here if you need it.

If it is not an error, you may need to have a list of all the books you do cite and then exclude those verse references preceded by members of the list when you insert your new string. This would require a much more complicated Macro than my humble offering.

I am assuming that you already have lots of verse references in your document that you now want to go back and amplify with relevant book designations. If this is not the case and you are starting from scratch, Cliff's idea of amending your workflow is a good one.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to insert inputted string before digit(s):digit(s)

Post by NisusUser »

Actually, I think I confused you. Sorry!
The text is already typed in. I want to find like this (using PowerFind):
PowerFind search. Range: "In Selection". Typed in "Gen"
PowerFind search. Range: "In Selection". Typed in "Gen"
Screen Shot 2022-11-19 at 17.56.53_500.png (28.49 KiB) Viewed 2328 times
Issues with this:
(1) Rather than have to change the "Replace" field to "Gen" or whatever other abbreviation each time, I'd like the macro to throw up a dialog for me to type in the abbreviation (depending on what file/section I've selected). For each selection it would only ask for the abbreviation once.
(2) I would like it to handle returns and soft returns. (I don't know how to tell PowerFind to find either a return or a soft return.)
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to insert inputted string before digit(s):digit(s)

Post by NisusUser »

adryan wrote: 2022-11-19 14:45:30 G'day, NisusUser et al

There is a big problem here, in that the second verse reference in your example (viz, "10:15") is not preceded by either a paragraph return or a soft return, and yet it seems from the transformed text you cite that you still wanted it preceded by your chosen text string.

If this is in fact an error […]
You are correct. That's an error. I decided not to automate the conversion of those not-after-a-return[soft return] references. Some of them already have another book name abbreviation in front of them.

Sorry about that.
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Macro to insert inputted string before digit(s):digit(s)

Post by adryan »

G’day, NisusUser et al

Thanks for clarifying that.

Here’s a Macro that I hope does the trick for you.

Insert Book Designation.nwm
(5.17 KiB) Downloaded 140 times

It assumes that the selection includes the (soft or hard) return immediately preceding the first verse reference you wish to amplify. It also assumes you want a space between the book designation and the verse reference (which means you don’t need to include it in your book designation string).

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to insert inputted string before digit(s):digit(s)

Post by NisusUser »

adryan wrote: 2022-11-19 15:09:06
Here’s a Macro that I hope does the trick for you.

Insert Book Designation.nwm
It works great! Thank you, Adrian!
Post Reply