Reply to topic  [ 4 posts ] 
Searching with attributes 
Author Message

Joined: 2007-04-12 14:59:36
Posts: 229
This is a Macro which finds all paragraphs containing a selected word:

Code:
$txt = Read Selection
Find "^.*$txt.*\n", 'Ea'


I wanted to modify it so that it finds only those paragraphs which have the same attributes as the search word. I thought I could just change 'Ea' to 'Eau'. But this does not work. Why is this?


2010-05-15 02:57:37
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
js wrote:
But this does not work. Why is this?

Because the find expression in your macro has adopted the attributes of your macro file. You need something like this:
Code:
$exp = Cast to String '^.*'
$exp &= Read Selection
$exp2 = Cast to String '.*\n'
$exp &= Cast to Attributed String $exp2
Find All $exp, 'Eu-i'

It does not always work fine. Even a corresponding manual operation fails at times. I just sent them a feedback.


2010-05-15 06:04:24
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Kino wrote:
Because the find expression in your macro has adopted the attributes of your macro file.

Yes, being very careful of the attributes is crucial. Beware any stray attributes, including the paragraph style. In most cases Normal tends to be applied.

Quote:
It does not always work fine. Even a corresponding manual operation fails at times. I just sent them a feedback.

I've seen Kino's feedback, and NWP can indeed fail to find all attribute-sensitive matches using js's expression. That said, there's more than one way to skin a cat. Alternative strategy:
Code:
$exp = Read Selection
Find All $exp, 'u-i'
Menu 'Select:Select Paragraph'


2010-05-17 14:47:04
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Thank you, Kino and Martin.
I think that "Select:Select Paragraph" can do selections of discontiguous paragraphs would be worthwhile to be documented.


2010-05-24 09:32:33
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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