Space around lists, quotations, etc.

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

Re: Space around lists, quotations, etc.

Post by martin »

adryan wrote: 2019-08-14 14:16:16Thanks 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 656 times
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan »

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 (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Space around lists, quotations, etc.

Post by xiamenese »

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: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan »

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 (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin »

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 634 times
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan »

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 (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin »

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:31I 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: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan »

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 (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin »

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.
ToddO
Posts: 34
Joined: 2015-10-18 14:25:32

Re: Space around lists, quotations, etc.

Post by ToddO »

The macro is an awesome solution, but for me, the best way to handle this is in the use of styles. Some of you may want to keep a single paragraph style, but in the cases shown here, you have to go back to apply manual formatting. Even with the macro to speed that, it’s always been more fluid (for me) to leverage styles for this.

Until we get the opportunity to remove spacing between bullets by the simple checkbox, we need a workaround.

Mine is to set up three *paragraph* styles in Nisus:
  • List
  • List Continue
  • List Last
I then apply the following settings:
  • List — Spacing: 0pt Before, 0pt after, Based on: List Last, Next Style: List Continue, Shortcut: CMD-8
  • List Continue — Spacing: 0pt Before, 0pt after, Based on: List Last, Next Style: List Continue, Shortcut: None
  • List Last — Single line spacing, Bullet List, Based on: Normal, Next Style: Normal, Shortcut: Shift-CMD-8
I save these three styles to the style library, and then add them to whatever template I’m working on. This way:
  • I can just press CMD-8 to start a list, and on the last item, hit CMD-Shift-8 to end the list on the next Return.
  • List Last paragraph mirrors any spacing I have after a Normal paragraph and will automatically change to match.
  • List is set up to work with Normal paragraphs that have spacing after them, so having both the List and List Continue styles may look superfluous at first glance. The nice thing about using a separate style for both is when you want to switch your paragraphs from spaced block to indented style with no spacing — then you can set the spacing before List to 12 (or whatever you want) and you have that space back in all your lists.
  • If you do remove spacing after the Normal style, you will also need to add 12pt to the spacing after List Last, since you removed it from the Normal Style. These styles are set up to build on each other, so you may need to go back through the List and List Continue styles to remove that added space. (I’ve toyed with basing this on the List style, but it has almost always paid off to base everything on the List Last and Mirror the spacing I put in after Normal, and deal with this mild occasional pain.)
This approach also gives correct format for numbered lists if you go into the List Last paragraph style and change the list form bullet to numbered. (Though you may want to set up three other styles for numbered lists if you use both bullet and numbered — such as List Num, List Num Continue, and List Num Last.)

This will hopefully be of use to someone — it has helped me when reformatting documents to have this flexibility. You may find different setups will work better for your particular templates. I attached a file so that you can play with the approach (though you'll have to assign the Shortcut Keys.)
Attachments
List.zrtf
(3.33 KiB) Downloaded 560 times
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Space around lists, quotations, etc.

Post by xiamenese »

I have always done the same as @ToddO for quotes. I also have a "First" style with no indent which follows from any heading or title, and is itself followed by "Normal", so my "Quote last" is also followed by "First".

:)

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

Re: Space around lists, quotations, etc.

Post by adryan »

G’day, ToddO, Mark et al

As far as I can determine, setting spacing with Lists by using Paragraph Styles can come unstuck when you need to alter the sequence of List Items. If Items are inserted, deleted or moved such that the erstwhile last Item is no longer the last one, you have to change the Styles associated with both the previous last Item and the current last Item.

The trouble is that a List Item cannot recognize whether or not it is the last Item in a List and then adopt an appropriate Style, nor can a Style by itself recognize when its application is appropriate, other than by reference to a dictate from the Style definition of the previous paragraph. This latter dictate applies only at the time the next paragraph is created. The Style thus applied remains attached to the paragraph even if it is moved to a new position in which it immediately follows a paragraph with a different Next Style setting in its Style definition.

The situation with Lists is further complicated by their implementation in Nisus Writer. If you select a contiguous set of paragraphs and apply a List Style (by means of the Lists Palette, for example), the paragraphs are converted to a List, as expected. However, insertion of a new paragraph within the List or immediately thereafter does not add a new List Item (as one might expect) unless you first Remove Paragraph Styles from your List.

Furthermore, adding a Paragraph Style to a List Item (generally) leaves the List otherwise intact until one inserts a new paragraph immediately following the altered paragraph, at which time the List is disrupted, the new paragraph fails to become a List Item, and subsequent List Items are numbered afresh.

The underlying problem here seems to be that Paragraph Styles take precedence over List Styles. I don’t think this should be the case. When you’re working with a List, I think you should be able to add, delete and move List Items without having to worry about disintegration of the List. Insertion of a new paragraph after a List Item should result in another List Item, appropriately numbered if necessary. One should not have to specify this behavior in a Next Style setting in a Paragraph Style definition.

I think ToddO’s approach attempts to deal with these tricky issues, but, on balance, I really think a macro offers a better solution, particularly when one considers alteration of the sequence. If you’re going to be using a keyboard shortcut to apply a Style, you might just as well use a keyboard shortcut to invoke a macro and get a whole lot more work done in one fell swoop.

To this end, I think Martin’s macro, with slight modifications, offers the best approach. It is easily adjusted to deal with an ordered triple as input, so one can set paragraph spacing before, between and after paragraphs in a block. So there is no need to have a Style to set the paragraph spacing.

However, there is a need to have a Style to set other characteristics (such as font, italic, etc) as desired. Since these cannot be set in a List Style, they must be set in a Paragraph Style. But, as I have said, this then plays havoc with Lists.

In summary, I would like to see Lists implemented more along the lines I have suggested. Paragraph Styles should not override List Styles. One should not concern oneself whether a List Item is the first, the last or an intermediate one in a List. Martin’s macro (with minor modification) could then just take care of the spacing by means of a simple keyboard shortcut.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
Post Reply