I think I found a bug

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

I think I found a bug

Post by loulesko »

When I type the follwing on my macro

Find All ‘.+’, 'EuaW'

And use any of the Gray colors for the attribute, it fails to find it. All the other colors are fine and it works in the Find window, juts not in a macro.

best
Lou
User avatar
Hamid
Posts: 777
Joined: 2007-01-17 03:25:42

Re: I think I found a bug

Post by Hamid »

Dark Gray works fine for me but Gray and Light Gray can't be found.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: I think I found a bug

Post by martin »

Hi Lou,

Since the find works in the normal Find & Replace window, my first guess is that your macro has undesired attributes applied that you're not aware of. To be sure on this point, select all your macro text and then:

1. Choose the menu Format > Remove Attributes & Styles.
2. Choose the menu Format > Paragraph Style > Remove Style (this step is necessary because step 1 will introduce the Normal style if such a style exists).
3. Now apply text coloring to your find expression.

Let me know how it goes.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: I think I found a bug

Post by phspaelti »

I can confirm Lou's problem, and whatever the value of Martin's remedy, it isn't applicable here. Here are the steps for reproducing the problem. Let's first try a case that works:

1. Open the find box
2. Enter '.+' as the find expression
3. Apply a text color (let's use "Red")
4. Test the find
---> It works. Red text is found.
5. Macroize the find expression
6. Test the macro
---> It works. Red text is found

If the same steps are repeated with "Gray" the macro just doesn't work.
philip
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: I think I found a bug

Post by loulesko »

Hi Martin,

I followed your post to the letter and the macro still did not find the gray color. I also re-did phspaelti's method and got the same result as he did.

best
Lou
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: I think I found a bug

Post by phspaelti »

Here's is where I think the problem lies. When I open the macro and check the color of the find string, for "normal" colors the format menu will show the correct color checked. So if the find expression has the text color "Red" then "Red" will be checked. But with "Gray" even if apply and save "Gray" as the text color, next time I open the file the "Gray" is unchecked. Apparently NW cannot find the right color again. The text string looks gray, but it's attribute is not correctly identified as the "Gray" of the format menu. Presumably the bug is in the saving of the color attribute "Gray".
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: I think I found a bug

Post by martin »

Thanks for the investigation, that's exactly the cause of the problem. When saving color information to RTF the color can shift ever so slightly (likely imperceivably), so attribute sensitive matching cannot occur. I'll file a few bugs on this.

For what it's worth, if both the macro and target file have both been saved to RTF and reopened, the attribute sensitive matching should work.
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: I think I found a bug

Post by loulesko »

Awesome. Thanks for everyone's diligence.

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

Re: I think I found a bug

Post by Kino »

It's too late for the fair but I have been following the thread with great interest. Personally I have seldom used the attribute sensitive find/replace. One of the reasons is that I often fail in getting it to work: it is not always easy for me to apply appropriate attributes on the find expression and remove those which are not.

So I began to think over how to simplify the process and, with help from Martin (thank you! I wrongly imputed the misbehaviour of an earlier version of the macro to NW Pro and sent a feedback), I could write a macro below which picks up character attributes from the selection (or insertion point) and applies them on the find expression.

If the find field is empty, Anything (PowerFind bubble) or its PowerFind Pro equivalent \p{Any}+ will be inserted.

Not having such a special character, Normal Find will use \p{Any}+ too with the find mode set to PowerFind Pro.

There is no ideal behaviour for such a macro. Someone may want to find text in superscript and blue regardless of font. Someone else may want to limit the target to text in a specific language. You can add any commands at the end of the macro so that it fits your needs.

Note that it does not use selected text for find but uses its character attributes only.

Code: Select all

### Use Selection for Find Attributes ###

# This macro picks up character attributes from the selection
# (or insertion point) and applies them on the find expression.
# Note that it does not use selected text for find but
# uses its character attributes only.

# If the find field is empty, Anything (PowerFind bubble) or
# its PowerFind Pro equivalent \p{Any}+ will be inserted.

# Not having such a special character, Normal Find will use
# \p{Any}+ too with the find mode set to PowerFind Pro.

# There is no ideal behaviour for such a macro. Someone would
# want to find text in Times Italic regardless of font size.
# Some one else would want to find text in superscript and blue.
# You can add any commands at the end of the macro to make it
# fit your needs.

Require Pro Version 1.2
$sel = TextSelection.active
if $sel == undefined
	'No selection (or insertion point) found, exit...'
end

Set Find Shown false
Menu ':Edit:Copy:Copy Character Attributes'
$find = Read Find Expression
$replace = Read Replace Expression
$options = Read Find Options

if $find == ''  # if the find field is empty...
	if $options.find 'e', '-i'  # if the find mode is set to PowerFind...
		$anything = '{\rtf1 \mac \ansicpg10000 {\*\nisusfindcell '  # construct RTF code corresponding to Anything
		$anything &= '{\*\nisusfindcellident wild.anything}{\nisusfindcellname Anything}'
		$anything &= '{\nisusfindcellregex (?:.|\\\'5cn)+}}{\nisusfindcelltext (?:.|\\\'5cn)+}}'
		$find = Decode RTF $anything  # make it RTF
		Find and Replace $find, $replace, '*!'
	else  # PowerFind Pro or Normal Find
		$find = Cast to String '\p{Any}+'  # remove style attributes inherited from the macro file
		Find and Replace $find, $replace, '*E!'
	end
end

Set Find Shown true

Menu ':Format:Language:Any Language'
Menu ':Edit:Paste:Paste Character Attributes'
# Menu ':Format:Font:Any Font'  # optional (remove # at the line start to enable it)

### end of macro ###
Formatted macro file:
http://www2.odn.ne.jp/alt-quinon/files/ ... es_nwm.zip

Edit: Near the end of the macro, I added

Code: Select all

Menu ':Format:Language:Any Language'
because I noticed that, without it, the macro does not work in one of my documents (formatted e-text).
Post Reply