nisus.com
https://www.nisus.com/forum/

I think I found a bug
https://www.nisus.com/forum/viewtopic.php?f=17&t=3372
Page 1 of 1

Author:  loulesko [ 2009-04-05 23:26:01 ]
Post subject:  I think I found a bug

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

Author:  Hamid [ 2009-04-06 00:30:13 ]
Post subject:  Re: I think I found a bug

Dark Gray works fine for me but Gray and Light Gray can't be found.

Author:  martin [ 2009-04-06 09:48:10 ]
Post subject:  Re: I think I found a bug

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.

Author:  phspaelti [ 2009-04-06 17:21:11 ]
Post subject:  Re: I think I found a bug

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.

Author:  loulesko [ 2009-04-06 17:39:54 ]
Post subject:  Re: I think I found a bug

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

Author:  phspaelti [ 2009-04-06 18:17:48 ]
Post subject:  Re: I think I found a bug

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

Author:  martin [ 2009-04-06 21:31:10 ]
Post subject:  Re: I think I found a bug

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.

Author:  loulesko [ 2009-04-08 00:21:21 ]
Post subject:  Re: I think I found a bug

Awesome. Thanks for everyone's diligence.

Lou

Author:  Kino [ 2009-04-08 05:16:17 ]
Post subject:  Re: I think I found a bug

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:
### 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/NWPro/find/UseSelectionForFindAttributes_nwm.zip

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

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/