Author Topic: activating colors set by _StreamMarkerSetTextColor  (Read 5953 times)

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
activating colors set by _StreamMarkerSetTextColor
« on: September 21, 2010, 02:30:11 am »
I'm having an interesting issue where something used to work with a previous version of SlickEdit but stopped working with 15.  I have a macro that does color highlighting of registers that alias each other in an aliased register set.  The part that finds register aliases and highlights them works fine, however the colors aren't working.  All registers are highlighted in gray, but if I do a normal ctrl-f search after running my macro, suddenly the colors are "activated" and the grey highlights change to the proper colors.  So obviously the macro that is called when you search via ctrl-f is doing something that my macro needs to be doing, but I am not sure what that is

I have the following code:
Code: [Select]
static void FindRegister(_str search_string, _str search_options, int markerType, int color )
{
    top( );

    _str searchStrAsRegex = _escape_re_chars( search_string, 'U' );
    searchStrAsRegex = searchStrAsRegex :+ "(?!\\[)";

    int status = find( searchStrAsRegex, search_options );
    if( !status )
    {
        for( ;; )
        {
            int offset = match_length('S');
            int bmpIndex = 0;
            markerIndices[ numMarkerIndices ] =
                _StreamMarkerAdd( p_window_id, offset, match_length(), true, bmpIndex, markerType, null );
            _StreamMarkerSetTextColor( markerIndices[ numMarkerIndices ], color );
            ++numMarkerIndices;
           
            if( repeat_search( ) )
            {
                break;
            }
        }
    }
}

Any ideas what I might be missing?

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #1 on: September 21, 2010, 08:25:40 am »
Have you debugged and verified that the value of "color" is correct?  Maybe the marker color wasn't successfully allocated.

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #2 on: September 30, 2010, 07:26:28 am »
Sorry for the delay, I thought I had email notification on.

Thanks a lot for the reply.  Yes, the value of color looks correct.  I tried displaying the value in a popup, and like I said, if I do a proper ctrl-f search after running my macro, the correct colors suddenly show up on all the things my macro highlighted.

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #3 on: September 30, 2010, 03:22:46 pm »
Hm, that sounds like your macro is piggybacking on a markertype used internally by SE.  In that case, probably SE has changed when it activates that marker, probably to fix a bug somewhere.  Can your macro use an independent dedicated markertype instead?

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #4 on: October 01, 2010, 01:03:19 am »
I was using _MarkerTypeAlloc( ) to allocate the types for each register type.  Is that the wrong way to do it?

Code: [Select]
s_qwMarkerType = _MarkerTypeAlloc( );
s_dwMarkerType = _MarkerTypeAlloc( );
s_sMarkerType = _MarkerTypeAlloc( );
s_rMarkerType = _MarkerTypeAlloc( );
s_qwRegColor = _AllocColor( );
s_dwRegColor = _AllocColor( );
s_sRegColor = _AllocColor( );
s_rRegColor = _AllocColor( );
_default_color( s_qwRegColor, 0xffffff, 0x0000ff, F_BOLD );
_default_color( s_dwRegColor, 0xffffff, 0xff0000, F_BOLD );
_default_color( s_sRegColor, 0xffffff, 0x00ff00, F_BOLD );
_default_color( s_rRegColor, 0xffffff, 0xff00ff, F_BOLD );

and then
Code: [Select]
markerIndices[ numMarkerIndices ] =
    _StreamMarkerAdd( p_window_id, offset, match_length(), true, bmpIndex, markerType, null );
_StreamMarkerSetTextColor( markerIndices[ numMarkerIndices ], color );

finally, doing the actual search with this copied function
Code: [Select]
// had to copy this from some builtin macro because my search depends on it
static _str get_quick_search_word(int &start_col)
{
word := "";
if( select_active2() )
{
if( !_begin_select_compare()&&!_end_select_compare() )
{
/* get text out of selection */
last_col := 0;
buf_id   := 0;
_get_selinfo(start_col,last_col,buf_id);
if( _select_type('','I') ) ++last_col;
if( _select_type()=='LINE' )
{
_str line;
get_line(line);
word=line;
start_col=0;
}
else
{
word=_expand_tabsc(start_col,last_col-start_col);
}
_deselect();
}
else
{
deselect();
word=cur_word(start_col,'',1);
}
}
else
{
word=cur_word(start_col,'',1);
}
return word;
}


chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #5 on: October 02, 2010, 04:33:40 am »
I was using _MarkerTypeAlloc( ) to allocate the types for each register type.  Is that the wrong way to do it?
That looks good.

and then
Code: [Select]
markerIndices[ numMarkerIndices ] =
    _StreamMarkerAdd( p_window_id, offset, match_length(), true, bmpIndex, markerType, null );
_StreamMarkerSetTextColor( markerIndices[ numMarkerIndices ], color );
The snippet is too short.  What is the surrounding code?

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #6 on: October 02, 2010, 06:13:58 am »
Code: [Select]
static void SearchAndHighlight(_str search_string, _str search_options, int markerType, int color )
{
// hope you saved your position before this
top( );
)
_str searchStrAsRegex = _escape_re_chars( search_string, 'U' );
// make sure d12 never matches d12[0].  If we want d12[0], the PERL script will specifically output it.  This may cause
// problems if there is some addressing syntax that uses something like r13[r14]
searchStrAsRegex = searchStrAsRegex :+ "(?!\\[)";

int status = find( searchStrAsRegex, search_options );
if( !status )
{
for( ;; )
{
int offset = match_length('S');
int bmpIndex = 0 /*find_index('_execpt.bmp',PICTURE_TYPE)*/;
markerIndices[ numMarkerIndices ] =
_StreamMarkerAdd( p_window_id, offset, match_length(), true, bmpIndex, markerType, null );
_StreamMarkerSetTextColor( markerIndices[ numMarkerIndices ], color );
++numMarkerIndices;
           
if( repeat_search( ) )
{
break;
}
}
}
}

and the search params are set from
Code: [Select]
_str search_options = make_search_options( VSSEARCHFLAG_WORD | VSSEARCHFLAG_FINDHILIGHT | VSSEARCHFLAG_UNIXRE, true );

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #7 on: October 02, 2010, 06:50:51 am »
A couple things:
1.  It's still not clear what is the value of markerType, in this snippet it is still a parameter.
2.  numMarkerIndices is not initialized, so I wouldn't expect the function to work on the 2nd, 3rd, 4th, etc invocations.

It would be a lot easier to take look if you can share the macro source.
Steps for how to reproduce the problem would also help.

I've written several macros that do this successfully, and I've posted most of them in the User Macros forum.  They might be useful as reference samples.  I'm happy to help debug your macro, but I think sharing the full source would make it a lot easier.

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #8 on: October 02, 2010, 08:37:24 am »
attached.  Thanks again for taking a look!

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #9 on: October 02, 2010, 07:02:24 pm »
Thanks, I've fixed the problems.

The main fix is to remove the VSSEARCHFLAG_FINDHIGHLIGHT option.
There were some other fixes as well.
I've attached a fixed copy of the macro.

Here are the observations I made:
  • The NeonAsmHighlight() function invokes a *nix shell and external perl script, and I didn't have a sample source file anyway.  So I added a TestHighlight() function so I could verify my fixes.
  • The macro was using VSSEARCHFLAG_FINDHILIGHT as a search option.  That tells SlickEdit to color the matches using the SlickEdit Find color.  That conflicts with the fact that the macro is trying to use its own colors.  I bet that a fix was made in SE to ensure that the built in Find Highlight gets precedence over custom colors.  Since the macro was accidentally double coloring everything, that fix exposed the bug in the macro.
  • The macro should be calling search instead of find, so I made that change as well.  The former is for use by macros, the latter is intended for direct use by the user.
  • The markerIndices array is unnecessary.  It was only used to change the color of the stream markers right before removing them, but that's superfluous because removing them, well, removes them.  So I've removed the markerIndices array.
  • The marker types weren't being allocated correctly, they were being leaked and SE would eventually run out of marker types, at which point coloring in general would go awry.  I've fixed that, but it was the largest change in the file -- you can diff the before/after files to see the change.
  • Note:  The macro uses defexit, but that function is undocumented.  From other forum discussions I was under the impression the editor doesn't actually support it.  The defexit implementation calls MarkerTypeFree, but the documentation and Symbol Coloring both think the function name should be _MarkerTypeFree (prefixed with an underscore).  However, it compiles.  However, as far as I can tell defexit is never called (not while unloading, not while re-loading, and not when exiting the editor).  I've left it in there, but added a comment that it is never called.
  • Apology:  The indentation in the file is inconsistent, and I couldn't figure out what it's really supposed to be, so I just went with Adaptive Formatting's guess.
« Last Edit: October 04, 2010, 04:26:12 am by chrisant »

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #10 on: October 04, 2010, 01:07:43 am »
Thanks very much for correcting my macro, but it still isn't working for me.  If we're using the same macro and it works for you, I have to wonder if there is some color setting somewhere that I have messed with.  On second thought, thats unlikely as I just created new settings the other day. 

In order to get colors to work this time, I have to go to the asm listing with the grey highlights and hit ctrl-z.  I discovered this accidentally when trying to undo a change in my macro.  Basically if I hit ctrl-z in _any_ file window, the highlights in the asm window suddenly start showing the correct colors.  Otherwise they are still grey. 

Not sure if this is useful info, but I am on SlickEdit Version 15.0.1.3
Build Date: August 04, 2010
Emulation: Visual Studio
OS: Windows XP
OS Version: 5.01.2600  Service Pack 3
Project Type: Other
Language: .txt (Plain Text)


chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #11 on: October 04, 2010, 04:25:25 am »
Um, sorry about that:  Look closely at the macro I had posted.  I removed the VSSEARCHFLAG_FINDHIGHLIGHT from the TestHighlight() function, but not from the NeonAsmHighlight() function.  Since there was no way for me to test NeonAsmHighlight(), I didn't notice.

Does the TestHighlight() function work when you run that?  I expect it will.  You can either make the VSSEARCHFLAG_FINDHIGHLIGHT fix to the macro yourself, or download the updated copy from my earlier post.  :)

okonomiyonda

  • Junior Community Member
  • Posts: 8
  • Hero Points: 1
Re: activating colors set by _StreamMarkerSetTextColor
« Reply #12 on: October 04, 2010, 04:51:31 am »
ah yeah, that would be my inability to spell.  When I went to remove the VSSEARCHFLAG_FINDHILIGHT flag, I did a search for highlight and hilite, but not hilight.  Sorry about that!  Well as you probably already know, its working perfectly.  Thanks again for the help ( and patience )