Reply to topic  [ 14 posts ] 
Working on multiple documents 
Author Message

Joined: 2005-02-07 17:55:03
Posts: 10
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


2007-11-09 13:28:24
Profile WWW
Official Nisus Person
User avatar

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


2007-11-09 15:21:18
Profile WWW

Joined: 2005-02-07 17:55:03
Posts: 10
Post 
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


2007-11-09 17:13:40
Profile WWW
Official Nisus Person
User avatar

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

Quote:
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.


2007-11-09 19:22:33
Profile WWW

Joined: 2005-02-07 17:55:03
Posts: 10
Post 
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


2007-11-10 00:19:15
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Post 
Quote:
Here's a macro that takes the PowerFind Pro expressions as entered into the Find window and applies them to all open documents:
Code:
# 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


2007-11-10 08:58:18
Profile
Official Nisus Person
User avatar

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



2007-11-11 15:49:49
Profile WWW

Joined: 2006-12-14 09:09:51
Posts: 42
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


2007-11-12 07:07:16
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
That's a good idea Dirk, thanks.


2007-11-12 14:11:19
Profile WWW

Joined: 2006-06-29 07:56:30
Posts: 81
Location: Hudson River Valley, NY
Post 
Quote:
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:
 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.



2007-11-12 17:52:26
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
That's exactly right Steve. Thanks for reminding me, I had forgotten about that option. Now the macro is complete I think!


2007-11-12 18:42:25
Profile WWW

Joined: 2004-06-02 08:27:02
Posts: 19
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


2007-11-14 06:46:00
Profile

Joined: 2005-02-07 17:55:03
Posts: 10
Post 
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
==========================================


2007-11-16 11:09:52
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
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:
Find $findExpr, '*r'


Quote:
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:
$count = Find $findExpr, '*r'
If $count > 0
    Exit
End


2007-11-16 13:42:34
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users and 6 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:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software