Searching with attributes

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 229
Joined: 2007-04-12 14:59:36

Searching with attributes

Post by js » 2010-05-15 02:57:37

This is a Macro which finds all paragraphs containing a selected word:

Code: Select all

$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?

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Searching with attributes

Post by Kino » 2010-05-15 06:04:24

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: Select all

$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.

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

Re: Searching with attributes

Post by martin » 2010-05-17 14:47:04

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.
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: Select all

$exp = Read Selection
Find All $exp, 'u-i'
Menu 'Select:Select Paragraph'

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Searching with attributes

Post by js » 2010-05-24 09:32:33

Thank you, Kino and Martin.
I think that "Select:Select Paragraph" can do selections of discontiguous paragraphs would be worthwhile to be documented.

Post Reply