Page 1 of 1

Repeating a selection?

Posted: 2007-11-09 13:40:52
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.


pax / Ctein

Posted: 2007-11-09 14:51:16
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.

Posted: 2007-11-09 16:36:08
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.


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?


pax / Ctein

#begin macro

#Combines selected lines into normal paragraphs

Cut #excises selection and puts it in a new temporary document
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

#end macro

Posted: 2007-11-09 17:12:55
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.

Posted: 2007-11-09 23:48:29
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

alternative macro?

Posted: 2007-11-10 12:07:38
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