Space around lists, quotations, etc.

Everything related to our flagship word processor.
martin
Official Nisus Person
Posts: 4610
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-14 15:19:09

adryan wrote:
2019-08-14 14:16:16
Thanks heaps for that, Martin.
I'm always happy to help! :)
The only caveat is that the selection must commence with a Paragraph Start
How about the macro allows for the selection to be anywhere in a list paragraph? It's easy enough to expand the selection (or insertion point) using the menu Format > Lists > Select Next in Style. The first time that command is used it will expand the current selection to include all contiguous text using the same list style. It's only subsequent command invocations that will jump to the next set of paragraphs in that list style.

I'll attach a macro file that does all of this, in case it's useful for anyone.
Attachments
List Paragraphs, Add Spacing.nwm
(6.22 KiB) Downloaded 62 times

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

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-14 23:35:44

G'day, Martin et al

That’s good, Martin, except that it only works for Lists, by which I mean lists that employ a List Style. I myself frequently use lists that are not subject to a List Style. And it won’t work for quotation blocks and the like.

However, I think that removing the first “^” from the previous macro code gives us everything we want; viz, any text block, Style-agnostic, with or without initial Paragraph Start or final paragraph return.

Code: Select all

$doc = Document.active
$selection = $doc.textSelection
Find ".", 'Es'
Set Paragraph Spacing Before 12
$doc.setSelection($selection)
Find "^.", 'EsrW'
Set Paragraph Spacing After 12
Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

xiamenese
Posts: 440
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Space around lists, quotations, etc.

Post by xiamenese » 2019-08-15 00:43:55

This is all very interesting. In the past I’ve done such padding manually, which is time consuming. I’ll try the macro later, but looking at it, I have one suggestion: would it be possible to modify it so that the amount of padding could be set at run-time rather than being a given amount (12pt) coded in the macro?

:)

Mark

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

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-15 02:02:32

G’day, Mark et al

Code: Select all

$padding_before = Prompt Input 'Enter number of points of padding you want before the block'
$padding_after = Prompt Input 'Enter number of points of padding you want after the block'

$doc = Document.active
$selection = $doc.textSelection
Find ".", 'Es'
Set Paragraph Spacing Before $padding_before
$doc.setSelection($selection)
Find "^.", 'EsrW'
Set Paragraph Spacing After $padding_after
Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4610
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-15 08:22:24

Thanks Adrian and Mark for the additional refinements and discussion!
That’s good, Martin, except that it only works for Lists
That's true, and it's certainly a limitation that prevents using the macro more generally without list styles. Though if people are working exclusively with list styles, then not requiring the user to select the target paragraphs can be a great convenience. Whenever possible I prefer to keep my hands on the keyboard. This macro allows for such usage, eg: use a keyboard shortcut to activate it, instead of grabbing the mouse to select the paragraphs.
padding could be set at run-time rather than being a given amount (12pt) coded in the macro?
For Adrian's interactive macro how about we reduce the two prompts into one? As a user I always prefer fewer interruptions. We can get both values from the user via a single alert if we ask the user to place a comma between the before/after spacing amounts. Something like:

Code: Select all

$padding = Prompt Input ...
$padding.find( @String[(?<before>\d+\.?\d*)\s*,\s*(?<after>\d+\.?\d*)], 'E¢' )
That uses named regex captures and Nisus Writer's ¢ option to automatically convert the matched spacing numbers into variables.

Remixing the last few macros is of course possible. It's easy enough to create a macro that automatically selects the current list paragraphs, rather than requiring the user to select them upfront. I actually think it's not too hard to determine the user's intent from the initial selection. If the user has the selection (or insertion point) in a single paragraph with a list style applied, then probably the user wants the macro to automatically work on all proximate list paragraphs; on the other hand if there's a selection encompassing multiple paragraphs then probably the macro should operate strictly just on those selected paragraphs.

Here's a macro that takes all this into account and is hopefully One Macro to Rule Them All, at least for this task.
Attachments
Paragraph Spacing Setter.nwm
(7.57 KiB) Downloaded 68 times

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

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-15 14:15:31

G'day, Martin et al

Seems to work well. A worthwhile addition to the macro collection, Martin. Thanks for that.

While you’re in the business of second-guessing the user’s intentions, though, I don’t suppose you could tweak the macro just that teensy-weensy little bit more so it automatically and contextually interpolates the inevitable dreaded Missing List Item, by any chance?

Great job!

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4610
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-16 07:22:42

I'm glad the macro is useful, thanks Adrian! I'd be happy to tweak it more for your needs, but I wasn't sure what you meant by this:
adryan wrote:
2019-08-15 14:15:31
I don’t suppose you could tweak the macro just that teensy-weensy little bit more so it automatically and contextually interpolates the inevitable dreaded Missing List Item, by any chance?
What's the dreaded "Missing List Item"? What exactly do you want the macro to do differently?

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

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-16 12:33:32

G'day, Martin et al

Sorry, Martin, it was meant as a joke, playing on your "One Macro to Rule Them All" appellation and the fact that you were second-guessing the user's intention on the basis of how many paragraphs they selected in a List. A compliment, really, on the macro’s wide-ranging utility.

As for the Missing List Item, it could have been anything from a loaf of bread in a shopping list to closing the hatch in a submarine's pre-submersal checklist.

Although I have no doubt that you could indeed enhance your macro to supply a remedy for such inadvertent admissions, perhaps you'd prefer to leave it as an Exercise for the Reader!

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4610
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-18 10:43:00

Ahhh, I'm sorry for missing the joke, and making you ruin it with an explanation. Your hypothetical Missing List Item macro would be awesome 🔮 I'm pretty sure I need that every time I'm grocery shopping haha.

Post Reply