nisus.com
https://www.nisus.com/forum/

Create lines between list items
https://www.nisus.com/forum/viewtopic.php?f=17&t=6449
Page 1 of 1

Author:  davidrcalvert [ 2016-08-17 16:11:57 ]
Post subject:  Create lines between list items

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

Author:  phspaelti [ 2016-08-17 17:57:28 ]
Post subject:  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:
  1. Select the bullet list
  2. Add empty lines
  3. Turn off the list style on the empty lines (to get rid of the bullets)

The first step can be done using a find by style:
Code:
$doc = Document.active
$bulletList = $doc.styleWithName "Bullet List"
Find All $bulletList


Now for the second step you would like to do this:
Code:
Find And Replace '^', '\n', 'Eas'

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:
Code:
Find All in Selection '\n.', 'Eas'
Find And Replace '^', '\n', 'Eas'


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". :wink:

Author:  phspaelti [ 2016-08-17 19:23:47 ]
Post subject:  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:
Code:
$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


And here as a macro:

Attachments:
Add Empty Lines to List.nwm [3.81 KiB]
Downloaded 71 times

Author:  phspaelti [ 2016-08-17 19:42:46 ]
Post subject:  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:
Code:
$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

Author:  davidrcalvert [ 2016-08-20 14:43:24 ]
Post subject:  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

Author:  martin [ 2016-09-21 15:58:49 ]
Post subject:  Re: Create lines between list items

Just one tip:
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.

You should be able to have Nisus Writer preserve your multi-part selection after a Replace All by using the "S" option. For example:
Code:
Find and Replace 'a', 'xyz', 'EasS'

That will replace all letter a's in the selection with xyz, while keeping the existing selection intact (multipart or not).

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/