Need some help on creating a Macro that would create lines between items on a list.
For example if I have a bullet list :
•word
*word2
*word3
and I want to create empty lines after list items such as
•word
*word2
*word3
How would I do this with a Macro?
Thanks,
David
Create lines between list items
Re: Create lines between list items
Hello David,
Let me first say, that if it were up to me, I wouldn't add empty lines into a list. It goes against the logic of a document to do that, and using empty paragraphs for formatting is poor formatting style. With a bullet list you can sort of get away with this, but if the list is a numbered list it will reset your numbering to "1" for each list item. How about just increasing the "space after" on the list items? I would use a paragraph style—with a name like "Bullet list with space"—and attach the list style and the extra large "space after" to that style.
Apart from that, writing a macro to do what you want would consist of the following steps:
Now for the second step you would like to do this:
But this will typically add empty lines before and after the list as well. So you precede this line with a line that selects only the returns that are completely within the list:
Now at that point, I would have expected Nisus to end with the empty lines selected, but unfortunately this is not the case. Basically Nisus does not preserve selections on a find/replace in a non-contiguous selection. So at that point you have two options: work around this, or skip using the GUI Find command. I tend to favor the latter option. But this does get a bit ugly, because you either need to turn off the list style one line at a time, or calculate the location of the inserted bits (counting the shifted selections) so you can select them at the end.
Like I said, I would just use "space after".
Let me first say, that if it were up to me, I wouldn't add empty lines into a list. It goes against the logic of a document to do that, and using empty paragraphs for formatting is poor formatting style. With a bullet list you can sort of get away with this, but if the list is a numbered list it will reset your numbering to "1" for each list item. How about just increasing the "space after" on the list items? I would use a paragraph style—with a name like "Bullet list with space"—and attach the list style and the extra large "space after" to that style.
Apart from that, writing a macro to do what you want would consist of the following steps:
- Select the bullet list
- Add empty lines
- Turn off the list style on the empty lines (to get rid of the bullets)
Code: Select all
$doc = Document.active
$bulletList = $doc.styleWithName "Bullet List"
Find All $bulletList
Code: Select all
Find And Replace '^', '\n', 'Eas'
Code: Select all
Find All in Selection '\n.', 'Eas'
Find And Replace '^', '\n', 'Eas'
Like I said, I would just use "space after".

philip
Re: Create lines between list items
One keeps learning new things…
Apparently, if you just insert a newline in a list—as opposed to pressing return, or using find/replace to insert it—you get an empty line without a list item. At which point the macro becomes much shorter. Here is my version:
And here as a macro:
Apparently, if you just insert a newline in a list—as opposed to pressing return, or using find/replace to insert it—you get an empty line without a list item. At which point the macro becomes much shorter. Here is my version:
Code: Select all
$doc = Document.active
$bulletList = $doc.styleWithName "Bullet List"
$bulletListSels = $doc.text.findAll $bulletList
$emptyLine = Cast to String "\n"
foreach $listSel in reversed $bulletListSels
$i = $i = $listSel.text.rangeOfParagraphAtIndex($listSel.bound - 1).location
while $i > $listSel.location
$listSel.text.insertAtIndex $i, $emptyLine
$i = $listSel.text.rangeOfParagraphAtIndex($i - 1).location
end
end
- Attachments
-
Add Empty Lines to List.nwm
- (3.81 KiB) Downloaded 885 times
philip
Re: Create lines between list items
And as they say, there's more than one way to do it.
One can use the macro language ListItem object, and then it comes out like this:
One can use the macro language ListItem object, and then it comes out like this:
Code: Select all
$doc = Document.active
$bulletList = $doc.styleWithName "Bullet List"
$bulletListSels = $doc.text.findAll $bulletList
$emptyLine = Cast to String "\n"
foreach $listSel in reversed $bulletListSels
foreach $item in reversed ListItem.itemsIn($listSel)
$loc = $item.enclosingTextRange.location
if $loc > $listSel.location
$item.enclosingText.insertAtIndex $loc, $emptyLine
end
end
end
philip
-
- Posts: 28
- Joined: 2014-07-18 18:32:13
Re: Create lines between list items
Hi Phillip,
Thank You. The main reason behind this Macro Request is that I get a lot of requirements in the form of a bullet list and my responses to each item in the list follows each one. Since I usually respond with 2-4 lines to each list item , I was trying to create the space necessary between each item.
Your Macro does just that. Thank You
The only other variation of the Macro you provided that I would need help as well would be the following.
Have the ability in the Macro to custom create 2, 3. 5, 5 lines of space.
Also use the Macro on paragraphs to create space between paragraphs as well .
Again, Thank You for your help. I appreciate it.
David
Thank You. The main reason behind this Macro Request is that I get a lot of requirements in the form of a bullet list and my responses to each item in the list follows each one. Since I usually respond with 2-4 lines to each list item , I was trying to create the space necessary between each item.
Your Macro does just that. Thank You
The only other variation of the Macro you provided that I would need help as well would be the following.
Have the ability in the Macro to custom create 2, 3. 5, 5 lines of space.
Also use the Macro on paragraphs to create space between paragraphs as well .
Again, Thank You for your help. I appreciate it.
David
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Create lines between list items
Just one tip:
That will replace all letter a's in the selection with xyz, while keeping the existing selection intact (multipart or not).
You should be able to have Nisus Writer preserve your multi-part selection after a Replace All by using the "S" option. For example:phspaelti wrote:I would have expected Nisus to end with the empty lines selected, but unfortunately this is not the case. Basically Nisus does not preserve selections on a find/replace in a non-contiguous selection.
Code: Select all
Find and Replace 'a', 'xyz', 'EasS'