Author Topic: Highlighting of matches of current word  (Read 8181 times)

schmave

  • Community Member
  • Posts: 8
  • Hero Points: 0
Highlighting of matches of current word
« on: October 25, 2007, 03:30:26 am »
I implemented a feature that I like from IDA Pro and Eclipse that I don't think is available in SlickEdit: when the cursor is on a word, all matches of that word in the current buffer are highlighted. The attached file has one command, toggle_auto_highlighting, that toggles this feature. I find this feature very useful when reading code, and a little annoying when writing code, so it's nice to be able to turn it on and off easily.

One note: it relies on a function, mark_all_occurences [sic], in tbfind.e that includes a message statement saying how many matches it found. I think it is best to comment this out. Unfortunately, it can't be controlled by arguments to the function.

Hope some people find this helpful. Let me know if you have problems with it or suggestions!
« Last Edit: October 25, 2007, 09:04:20 pm by schmave »

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1292
  • Hero Points: 129
Re: Highlighting of matches of current word
« Reply #1 on: October 25, 2007, 01:00:33 pm »
There is a built-in quick_highlight command which also does the same in the 2007 version.  Toggle off on the same command is a nice addition on your version though. 

And while we are on the subject, we'll play a quick Did you know? (hopefully Lisa won't mind too much).  There are some other highlight-related commands for manual creation, highlight_selection (create highlight for selected area).  You can use the clear_highlight command to remove all highlights in the buffer, or you can use remove_highlight (delete (all) highlights under current cursor position if exists) and remove_highlight_in_selection (delete (all) highlights that overlap current selection).

Lisa

  • Senior Community Member
  • Posts: 238
  • Hero Points: 23
  • User-friendly geek-speak translator extraordinaire
Re: Highlighting of matches of current word
« Reply #2 on: October 25, 2007, 01:55:41 pm »
And while we are on the subject, we'll play a quick Did you know? (hopefully Lisa won't mind too much). 

Lee's bill is adding up. I charge $1 for every tip that doesn't go through the proper channels.  ;D

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Highlighting of matches of current word
« Reply #3 on: October 25, 2007, 02:05:05 pm »
Uh oh Lee...Lisa just got all westfall on you.

http://www.urbandictionary.com/define.php?term=westfall

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 288
Re: Highlighting of matches of current word
« Reply #4 on: October 25, 2007, 02:55:50 pm »
:D :D :D

schmave

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Highlighting of matches of current word
« Reply #5 on: October 25, 2007, 05:12:02 pm »
Yes, what I wrote is similar to quick-highlight, but instead of highlighting all occurrences of the current word once and leaving them highlighted, it clears the highlights automatically when you move the cursor off of a word and highlights a new word if you move your cursor onto a new word.

One question: Both the quick-highlight command and my usage of the mark_all_occurences function cause the search string to be replaced by the text that was highlighted (so that repeat_search will find the next occurrence of the highlighted word, not the original search text). However, both quick-highlight and my highlight_callback call save_search and restore_search in appropriate places (I've verified this with some debug say statements). Any ideas on how to track this down and fix it? Thanks!

schmave

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Highlighting of matches of current word
« Reply #6 on: October 25, 2007, 05:27:59 pm »
Whoops! I lied about quick_highlight trying to save the search state. It does call save_search, but not restore_search. The code I'm using to save and restore the search state comes from the code that highlights matching parentheses, which does work in that case. Any suggestions would still be appreciated. Thanks again.

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1292
  • Hero Points: 129
Re: Highlighting of matches of current word
« Reply #7 on: October 25, 2007, 06:42:31 pm »
quick_highlight is much the same as quick_search, so find-next should go the next occurrence of the highlighted word.  mark_all_occurences also does this for you, but it sounds like that is not what your wanting.  There are several Slick-C globals vars which are used for the current search state for when you call find-next, and the search parameters are restored from these globals:

Code: [Select]
restore_search(old_search_string,old_search_flags,old_word_re,old_search_reserved,old_search_flags2);
You should be able to make a temporary copy in your macro of these vars and restore them after you call mark_all_occurences to keep the previous search settings.

schmave

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Highlighting of matches of current word
« Reply #8 on: October 25, 2007, 09:04:53 pm »
Cool, that did the trick. I updated the original attachment in case anyone wants it.