Reply to topic  [ 6 posts ] 
Create lines between list items 
Author Message

Joined: 2014-07-18 18:32:13
Posts: 28
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


2016-08-17 16:11:57
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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:

_________________
philip


2016-08-17 17:57:28
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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 69 times

_________________
philip
2016-08-17 19:23:47
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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

_________________
philip


2016-08-17 19:42:46
Profile

Joined: 2014-07-18 18:32:13
Posts: 28
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


2016-08-20 14:43:24
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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).


2016-09-21 15:58:49
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software