Author Topic: Highlighting all occurences of text or regular expression with one of 7 colors  (Read 19296 times)

Ruhh

  • Junior Community Member
  • Posts: 4
  • Hero Points: 2
Description
This module implements commands for highlighting all occurrences of current word, selected text or regular expression with one of 7 predefined colors. Tested in SlickEdit 15.

This is a re-implementation of my old CodeWright macro. I use multiple highlights when analyzing huge log files generated by our system.

Commands
'highlight_textN' commands, where N is from 1 to 7, highlight all occurrences of current word or selected text with color N. Selected text can not span more than current line. If cursor is on existing highlight then that highlight is cleared.

'highlight_reN' commands, where N is from 1 to 7, prompt user for a Perl regular expression and highlight all occurrences with color N.

'highlight_text_clear_all' command clears all highlights created with 'highlight_textN' or 'highlight_reN' commands.

'highlight_text_bind_keys' command binds 'highlight_textN', 'highlight_reN' and 'highlight_text_clear_all' commands all at once. Default bindings are Ctrl-1 to Ctrl-7, Ctrl-Shift-1 to Ctrl-Shift-7 and Ctrl-0 keys respectively. Customize this command to your taste.

By default searching for text to highlight is case-insensitive and not restricted to whole words. Two commands 'highlight_text_toggle_case_sensitive' and 'highlight_text_toggle_whole_word' toggle the flags.

Installation
  • Put attached highlight_text.e into local folder and load with F12 or Macro->Load Module.
  • Run 'highlight_text_bind_keys' command to bind keys.

Customization
Predefined colors are stored in 's_colors' array. You can change them to your taste. It is trivial to add more colors: add a color entry into 's_colors' and then add new 'highlight_textN'/'highlight_reN' commands.

Acknowledgements
Thanks to marksun for SymHighlight macro which I used as a starting point.

taiwuchiang

  • New Community Member
  • Posts: 2
  • Hero Points: 0
I just upgraded to V17 and seems the macro doesn't work for V17 anymore. It was working fine on V16 but during the upgrade process the new version complained a compiler error for a line in the macro file.
Anybody knows what have been changed in the macro language in the new V17 and possibly a fix for it? I used this highlight macro a lot and can't live without it. Thanks.

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
I just downloaded it  - it loaded ok in V17.  Have you tried loading it manually?

Do you remember what the specific error message was or what line number?

tangb4c

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
Nice work!
It don't works at V17. Solution like this:
replace all occurrences of VSARG2_READ_ONLY in the highlight_text.e with VSARG2_READ_ONLY|VSARG2_MARK

end solution.

some tips:
I add a function in highlight_text.e. like this:
Code: [Select]
static int g_highlight_index = 0;
_command void highlight_text() name_info (','VSARG2_READ_ONLY|VSARG2_MARK |VSARG2_REQUIRES_EDITORCTL|VSARG2_LINEHEX)
{
   highlightCurrentText (++g_highlight_index%g_highlightInfo._length());
}
To bind a key(like F7) to highlight_text, you could highlight selected texts with cycle color.


tangb4c

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
perverted verification code,god daamn it !!!
 >:( >:( >:(
« Last Edit: October 10, 2012, 10:04:12 AM by tangb4c »

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
I wonder if there is a way to make it Highlight all occurrences of selected word, just like Visual Studio does. I double click a work and it highlights all of the occurrences of that word.
 

chandlerzhang

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
I wonder if there is a way to make it Highlight all occurrences of selected word, just like Visual Studio does. I double click a work and it highlights all of the occurrences of that word.

try _command void quick_mark_all_occurences() name_info(','VSARG2_MARK|VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
     if (_select_type()!='') {
      begin_select();
      _deselect();
   }
   
   _str cw = cur_word(auto sc);
   mark_all_occurences(cw, /* search_text */
                       'WHP,XSC',/* search_options */
                       VSSEARCHRANGE_CURRENT_PROC, /* search_range */
                       0,/* mfflags */
                       0,/* grep_id */
                       1,/* show_hilite */
                       0,/* list_all */
                       0,/* show_bookmarks */
                       1);/* scroll_markup */
}

try this and bind this command to double-click.

stsimmer

  • Community Member
  • Posts: 16
  • Hero Points: 0
Hi, anybody know is it work with SlickEdit Pro 2019 (v24.0.1.0 64-bit) on Linux?

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Did you run the macro 'symtagload' ?
There is a Readme file that notes this.

stsimmer

  • Community Member
  • Posts: 16
  • Hero Points: 0
I do next:
1.Download highlight_text.e file
2. Put it near user.cfg.xml, in folder /home/<my_user_name>/.slickedit/24.0.1/...
3. Open and replace all occurrences of VSARG2_READ_ONLY in the highlight_text.e with VSARG2_READ_ONLY|VSARG2_MARK,
    add function highlight_text()... as described previously.
4. Save all, reopen my SlickEdit Pro 2019 (v24.0.1.0 64-bit) Linux
5.From menu Macro->Load module take new version of highlight_text.e
   And recived error …
“Unable to load module '/home/stas/.slickedit/24.0.1/highlight_text.e'.  Incorrect version”
Is it possible to fix?