Working on multiple documents

Everything related to our flagship word processor.
Post Reply
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Working on multiple documents

Post by Ctein »

Dear Folks,

I'm new to NWP, long-time user of NW Classic. I made heavy use of multiple-document operations in NW Classic, such as search/replace on all open docs, save-all, and save-all-changed. I can't find similar functionality in NWP.

Am I missing something, or does NWP lack these seriously-useful operations?

If the latter, is there a way to write a macro that works across multiple documents?

pax / Ctein
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

There are no built-in Save All or Find in all open document commands. However here's a macro that saves all your open documents:

Code: Select all

# We iterate through all open documents, stopping when we get back to the first document.
$firstPath = ''
While 1
	# do whatever we want to the document
	Save
	
	# check if we’ve got all the way back to the first document
	$savedPath = Document Property 'file path'
	If '' == $firstPath
		$firstPath = $savedPath
	Elsif $savedPath == $firstPath
		Exit
	End
	
	# move to the next open document
	Window:Next Window
End
Searching in all open document would be trickier, but one could manage it. What form the macro takes would depend on how you imagine the results should be presented. Should all found instances simply be selected in the open documents? Do you want a printout of the results?
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Post by Ctein »

Dear Martin,

Thanks! If I assign a hot key to that macro, it'll work well enough. Save All and Save All Changed really need to be built into the next version, though.

I'm less interested in simple searches than search and replaces. I work on multiple documents at one time and I'm frequently doing garbage cleanup and reformatting on all of them. Having to step through them manually to make sure they're all in comparable states is a real pain.

I gotta say, based on only a few weeks experience, that I'm not a satisfied customer. Nisus Writer Pro is considerably less useful to me than Classic. Were Classic compatible with my new MacIntel, I'd have not bought this program. It's missing a lot of the useful global scope capabilities of NWC, it lacks a simple macro recorder, and it doesn't feel anything like Nisus. A whole new learning curve and not a better one, in my opinion. I'm not sure I'm any better off than I'd have been with Microsoft Word.

I've recommended NWC to people; I can't do the same for NWP. Hopefully Version 2 will be a lot better. I'd like to stay with you folks.

pax / Ctein
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

Ctein wrote:I'm less interested in simple searches than search and replaces.
Here's a macro that takes the PowerFind Pro expressions as entered into the Find window and applies them to all open documents:

Code: Select all

# gather the find and replace expressions
$findExpr = Read Find Expression
$replaceExpr = Read Replace Expression

# We iterate through all open documents, stopping when we get back to the first document. 
$firstPath = '' 
While 1 
   # do whatever we want to the document 
   Find and Replace $findExpr, $replaceExpr, 'Ea'
    
   # check if we’ve got all the way back to the first document 
   $savedPath = Document Property 'file path' 
   If '' == $firstPath 
      $firstPath = $savedPath 
   Elsif $savedPath == $firstPath 
      Exit 
   End 
    
   # move to the next open document 
   Window:Next Window 
End
There's one thing to watch out for: there's currently no way to get the options that are set in the Find window. This means the options have to be hardcoded into the macro.
I gotta say, based on only a few weeks experience, that I'm not a satisfied customer. Nisus Writer Pro is considerably less useful to me than Classic.
Before you judge NWP too harshly, it might be best to keep in mind that Nisus Writer Classic 6.5 took more than 10 years of development. Nisus Writer on OSX has been around less than half of that.
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Post by Ctein »

Dear Martin,

Thanks! I can divine the general form from your two examples, if they don't do everything I need.

I've been a satisfied Nisus user since the days of the Powerbook 100. What is that; fifteen years? Something like that. I actually stopped at v6.0; I ran into some sort of init conflict which impacted the performance of 6.5 and never got around to straightening it out.

I've written well over a million published words and god knows how much email with Nisus Classic. You could say I'm a happy Nisus camper.

Or, at least, I was. I'll withhold final judgment until the next version.

pax / Ctein
js
Posts: 259
Joined: 2007-04-12 14:59:36

Post by js »

Here's a macro that takes the PowerFind Pro expressions as entered into the Find window and applies them to all open documents:

Code: Select all

# gather the find and replace expressions
$findExpr = Read Find Expression
$replaceExpr = Read Replace Expression

# We iterate through all open documents, stopping when we get back to the first document. 
$firstPath = '' 
While 1 
   # do whatever we want to the document 
   Find and Replace $findExpr, $replaceExpr, 'Ea'
    
   # check if we’ve got all the way back to the first document 
   $savedPath = Document Property 'file path' 
   If '' == $firstPath 
      $firstPath = $savedPath 
   Elsif $savedPath == $firstPath 
      Exit 
   End 
    
   # move to the next open document 
   Window:Next Window 
End
There's one thing to watch out for: there's currently no way to get the options that are set in the Find window. This means the options have to be hardcoded into the macro.
Also, to work flawlessly this very useful macro or it's user should make sure that
a) the find window is out of the way before execution
b) all documents should have been saved at least once
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

js is almost completely correct. Only the topmost document window needs to have been saved. The reason is that the macro uses the first document's file path to determine when to stop looping through the open windows. New documents that have never been saved do not have a file path.

Here's an updated macro that ensures both of js' conditions have been met:

Code: Select all

$firstPath = ''

# warn the user that the active document must have been saved at least once
$savedPath = Document Property 'file path' 
If '' == $savedPath
   Prompt 'The top document must be saved.', 'For this macro to work properly, the topmost document must have been saved at least once. You will now be prompted to save this document.'
   Save
   $savedPath = Document Property 'file path' 
   If '' == $savedPath
     Exit
   End
End
$firstPath = $savedPath

# gather the find and replace expressions 
Set Find Shown false
$findExpr = Read Find Expression 
$replaceExpr = Read Replace Expression 

# We iterate through all open documents, stopping when we get back to the first document.
While 1 
   Window:Next Window
   
   # do whatever we want to the document 
   Find and Replace $findExpr, $replaceExpr, '*a' 
    
   # check if we’ve got all the way back to the first document 
   $savedPath = Document Property 'file path' 
   If $savedPath == $firstPath 
      Exit 
   End
End
Last edited by martin on 2007-11-12 18:44:03, edited 1 time in total.
Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

thanks!

Post by Dirk_Barends »

now this is time saving macro that brings back some of the special functionality of the Nisus 'Classic' (3-6), that I really missed since NWE. Great!
You should put this macro in the macro repository, so that others can find it easy too?

Dirk
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

That's a good idea Dirk, thanks.
ssampler
Posts: 85
Joined: 2006-06-29 07:56:30
Location: Hudson River Valley, NY

Post by ssampler »

There's one thing to watch out for: there's currently no way to get the options that are set in the Find window. This means the options have to be hardcoded into the macro.
Martin, the Nisus Macro Reference States (p 11) that the option * in 'Find and Replace' will "Use options currently set in Find & Replace dialog. You can still add additional options as you like." True? If so, how would the revised 'Find and Replace' statement look? Like this?

Code: Select all

 Find and Replace $findExpr, $replaceExpr, '*a'
'

-Steve

Update: Edited to match Martin's version in the corrected script above.
Last edited by ssampler on 2007-11-14 15:26:05, edited 3 times in total.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

That's exactly right Steve. Thanks for reminding me, I had forgotten about that option. Now the macro is complete I think!
GBeurlen
Posts: 19
Joined: 2004-06-02 08:27:02

Working on multiple documents

Post by GBeurlen »

martin wrote: Here's a macro that takes the PowerFind Pro expressions as entered into the Find window and applies them to all open documents:
Hi Martin,

this is a very useful macro. Thank you very much.

Regards,

G. Beurlen
Rio de Janeiro RJ Brazil
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Post by Ctein »

Dear Martin and Steve,

Thanks so much. This provides me with a great template for building all sorts of global scope macros. I made really heavy use of global options in NWC for sorting and maintaining my correspondence. I'm getting a lot of them back, now.

Two last (I hope) questions:

1) What's the macro command or option for doing a "find previous" instead of the default "find next"? Probably in the manual, but I missed it (like I missed the * option).

2) I'd like to modify the macro template to halt on the first found item. IOW, something that does

"IF {item found} THEN [exit the macro and give scope to the window with the found item} ELSE {continue the macro's search for items}".

Not hard, but while I can read Perl adequately I can't really write it without LOTS of trial and error (mostly error).

Thanks!

pax / Ctein
==========================================
-- Ctein's Online Gallery http://ctein.com
-- Digital Restorations http://photo-repair.com
==========================================
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

Ctein wrote:1) What's the macro command or option for doing a "find previous" instead of the default "find next"? Probably in the manual, but I missed it (like I missed the * option).
The option for find previous is "r" for reverse or "b" for backwards, either one, eg:

Code: Select all

Find $findExpr, '*r'
2) I'd like to modify the macro template to halt on the first found item. IOW, something that does
The find/replace commands all return the number of matches made, so this would suffice:

Code: Select all

$count = Find $findExpr, '*r'
If $count > 0
    Exit
End
Post Reply