Numbering paragraphs: possible?

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

Post by martin »

Anne Cuneo wrote:Hamid: Wow! You are right, the straight quotes went curly, I hadn't noticed.
For non-Perl macros this should not make a difference. Straight and curly quotes are equivalent. However, you must take care to save the macro as a "Nisus Macro", not a "Nisus Perl Macro".
Dirk_Barends wrote:Now if I could make this macro to work on selected text only, it would be a good replacement for the old Number Renumber Lines (Perl) macro.
Perhaps Martin knows how to do that?
The following macro should do the trick:

Code: Select all

# calculate the selection endpoint so we can stop there
$bound = Selection Location
$selLen = Selection Length
$bound += $selLen

# keep searching for the start of a paragraph
$count = 0 
$isContinue = 1
While $isContinue
	$isContinue = Find ‘^(?:\d+\.?\s*)?’, ‘E-W’
	If $isContinue
		$foundLoc = Selection Location
		$foundLen = Selection Length
		If $foundLoc >= $bound
			# we’ve left the original selection
			$isContinue = 0
		Else
			# number the paragraph
			$count += 1
			Insert Text “$count. ”
			
			# adjust boundary to account for replacement
			$delta = Selection Length
			$delta -= $foundLen
			$bound += $delta

			Select End
		End
	End
End 
Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

Line Numbering Macro

Post by Dirk_Barends »

Thank you very much Martin, this macro seems to work well!
Another candidate for the Nisus Writer Pro Macro Repository?

Dirk Barends
Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

Anne Cuneo wrote:
Thanks Martin, but I think there still is a problem, when I want to apply the Macro, il tells me there is an error in the first line. Am I missing something here?

Did you save it as a Nisus Macro? As for example:
Number Lines.nwm
It took some time, I had other things to do urgently in between, but I finally tried Martin's edited macro as Nisus macro (not pearl), and it works. I am really relieved! Now I can stop worrying that I'll forget a paragraph in my translation. Thanks everybody!

I didn't try to fix the curly quotes problem - but as I don't need this now, I'll just file it for further use .
Thanks again!

PS. And for literature lovers, look out for the film I just translated and needed the paragraph numbering for, about Max Frisch, by Mathias von Gunten - fascinating!
Anne
Post Reply