Repeating a selection?

Get help using and writing Nisus Writer Pro macros.
Post Reply
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Repeating a selection?

Post by Ctein »

Dear Folks,

I'm new to NWP, long-time user of NW Classic; I'm not used to writing in NWP. Here's my problem:

I want to do repeated search/replaces on a body of selected text. The problem I'm running into is that after one search/replace, the selection changes from the original one to the material replaced. Is there any way to maintain a selection or reselect the old material automatically.

For example, the following macro is supposed to take a basic text file (breaks at the end of each line, double breaks between paragraphs) and turn it into unbroken paragraphs separated by breaks and tabs. It fails because after line 1, because the selected material becomes the double-~'s, not the original selection.

#Combines selected lines into normal paragraphs
Find and Replace '\n\n', '~~', 'Esa' #replaces double CR's with double-~
Find and Replace '\n', ' ', 'Esa' #concatenates lines
Find and Replace '~~', '\n\t', 'Esa' #restores double CR's as para breaks with indents
Find and Replace ' ', ' ', 'Esa' #removes duplicate spaces

A work-around would be to cut the selection, paste it into a new doc window, run the s/r all's on that entire document, select it, cut it, close the window and paste it back into the original. But that's a kludge (and woudn't work on noncontiguous selections) -- I'm hoping there's something more elegant.

Thanks!

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 »

Unfortunately we don't have this option, but it's been filed as a feature request. You may find the discussion in this thread useful.
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Post by Ctein »

Dear Martin,

Thanks for the quick response.

That script you pointed me at is a lot uglier than even my way of handling it. I think I'll stick with the cut-and-paste approach.

But...

I've hit an oddity. The folllowing macro works fine when I invoke it from the menus. But if I assign a key combo to it and use the key combo to run it, the "Close" command attempts to close ALL the open documents, not just the temporary one. What am I missing, here?

Thanks!

pax / Ctein


#begin macro

#Combines selected lines into normal paragraphs

Cut #excises selection and puts it in a new temporary document
New
Paste
Find and Replace '\n\n', '~~', 'Ea' #replaces double CR's with double-~
Find and Replace '\n', ' ', 'Ea' #concatenates lines
Find and Replace '~~', '\n\n', 'Ea' #restores double CR's
Find and Replace ' ', ' ', 'Ea' #removes duplicate spaces
Select All #cuts out revised text, closes temporary document and pastes the text into its original location
Cut
Close
Paste

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

Post by martin »

On OSX if you hold Command + Option when you choose the Close menu (or click the red circular close button) all open document windows will be closed. I bet you've assigned your macro's keyboard shortcut to be Command + Option + something. When the macro gets to the Close command, the Command and Option keys are still down, so it interprets it as a request to Close all documents.

I'll file an issue report, but in the meantime you'll have to use a shortcut that doesn't use the Option modifier key.
Ctein
Posts: 10
Joined: 2005-02-07 17:55:03
Contact:

Post by Ctein »

Dear Martin,

Hah! That was it! Used shift-splat-R instead of option-splat-R and the macro behaves as I'd expect it to. Thanks!

pax / Ctein
Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

alternative macro?

Post by Dirk_Barends »

perhaps an alternative for your 'Form Paragraphs' macro is this:

Code: Select all

Find and Replace '(.) *\n(.)', '\1 \2', 'aEs' #concatenates lines
Post Reply