Hello All, I wish to all of you a very Happy New Year! ------- Hello Kino, To return to what I wrote in the last year, I had a question that I forgot to ask you. In the macro you wrote, and I copied, there were these lines: foreach $found in $founds if $found.text.documentContentType == 'body' # it may be, for example, a table cell $range = Range.new $found.location + $sel.location, 0 $start = TextSelection.new $sel.text, $range $paraStarts.appendValue $start end end The two lines: $range = Range.new $found.location + $sel.location, 0 $start = TextSelection.new $sel.text, $range above, can I understand that they are somehow equivalent of "SetSelect (x, y)" in Classic Nisus Writer macro...? On Dec 31, 2010, at 12:55 PM, Kino wrote: >> >> if ! $sels.firstValue.length # if there is no selection... >> $paraStarts = $doc.text.findAll '^', 'E', '-am' >> end > > In that construction, the next foreach loop will be executed even when > > $paraStarts = $doc.text.findAll '^', 'E', '-am' > > has been done. Oh, I am ashamed, that is true! > > Then, we can do something like this. > > # begin macro > > $prefix = Cast to String '' > $suffix = Cast to String "\t" > > $doc = Document.active > $sels = $doc.textSelections > > $paraStarts = Array.new > if ! $sels.firstValue.length > $sels = $doc.text.findAll '^(?=\p{Any})', 'E', '-am' > foreach $sel in $sels > $paraStarts.appendValue $sel.location > end > else > foreach $sel in $sels > $sel.range = $sel.range.unionRange > $sel.text.rangeOfParagraphAtIndex($sel.location) I find these two commands, "$range.unionRange", and "$text.rangeOfParagraphAtIndex" really very clever. NWP macro language is astonishingly well equipped with many intelligent and useful commands. But it would take long time to master them all...! > $founds = $sel.subtext.findAll '^', 'E' > foreach $found in $founds > if $found.text.documentContentType == 'body' > $paraStarts.appendValue $found.location + $sel.location > end > end > end > end > > Select Start > > foreach $i, $start in reversed $paraStarts > $doc.text.insertAtIndex $start, $suffix > $doc.text.insertAtIndex $start, $i + 1 > $doc.text.insertAtIndex $start, $prefix > end > > # end macro Thank you very much for this very useful macro! I will try other macros of yours. Best regard, Nobumi Iyanaga Tokyo, Japan