Reply to topic  [ 6 posts ] 
Repeating a selection? 
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'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


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

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


2007-11-09 14:51:16
Profile WWW

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


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

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


2007-11-09 17:12:55
Profile WWW

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


2007-11-09 23:48:29
Profile WWW

Joined: 2006-12-14 09:09:51
Posts: 42
perhaps an alternative for your 'Form Paragraphs' macro is this:
Code:
Find and Replace '(.) *\n(.)', '\1 \2', 'aEs' #concatenates lines


2007-11-10 12:07:38
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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