Author Topic: Occurrences highlighting  (Read 31240 times)

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Occurrences highlighting
« on: July 23, 2008, 01:37:48 pm »
With this patch the editor will highlight (draw a red box aroud) all occurences in the current document of the selected text.
The feature is selectabel/deselectable throught the editor settings dialog.

screenshot attached

patch id: 002525.


[attachment deleted by admin]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #1 on: July 23, 2008, 02:22:26 pm »
I'm not quite happy yet because of two things:
1. it triggers from UpdateUI which means it adds a lot of overhead to typing and even moving the mouse
2. on a second thought, there's only one thing


Other than that: Great! Works nicely. I'll have a look if I find something better to hook it into.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Occurrences highlighting
« Reply #2 on: July 23, 2008, 02:25:44 pm »
Very nice feature !!
Is it possible to highlight only whole words with same case ?

Dje

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Occurrences highlighting
« Reply #3 on: July 23, 2008, 02:33:07 pm »
very nice. I think once Thomas has found a better cpu relaxing idea, and the case issue is solved this is a very nice addition :-)

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #4 on: July 23, 2008, 02:56:13 pm »
Bah... UpdateUI is the official event for selection changes, and there's nothing else. But it's possible to do a quick range test at the beginning, and return without searching through all the text, that should eleminate the overhead almost entirely. Just compiling.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #5 on: July 23, 2008, 03:05:39 pm »
Works fine. No measurable difference between with feature or without when editing and scrolling, and such.

It does eat some CPU while doing the highlighting (around 24-25% on my system, on files 200+ kB), but I guess it's obvious that this isn't free :)

Commit? :)

EDIT:
Wait a second,...
Quote
when the case issue is solved
I think that's an implementation feature, not an issue. But sure, it could be customized. I personally would like to be able to highlight multiple words too, for example.
But... that's only tweaking on details... in principle, it works nicely :)
« Last Edit: July 23, 2008, 03:10:30 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Occurrences highlighting
« Reply #6 on: July 23, 2008, 03:10:00 pm »
Commit? :)

It'd be a nice feature addition. I'm going ahead with the commit. :)
Be a part of the solution, not a part of the problem.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #7 on: July 23, 2008, 03:11:00 pm »
Eh, how are you going ahead, if you don't have the code? :P
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Occurrences highlighting
« Reply #8 on: July 23, 2008, 03:13:43 pm »
Eh, how are you going ahead, if you don't have the code? :P

It's in Berlios. ;)
Be a part of the solution, not a part of the problem.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Occurrences highlighting
« Reply #9 on: July 23, 2008, 03:22:04 pm »
go ahead and commit  8)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Occurrences highlighting
« Reply #10 on: July 23, 2008, 03:35:47 pm »
go ahead and commit  8)
Already done and working nice over here... Cool stuff! 8)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: Occurrences highlighting
« Reply #11 on: July 23, 2008, 05:39:32 pm »
I am glad that you like it.

I dont' believe that the patch to reduce CPU consumption works yet!
If you select old_a the highlight occurences feature only marks the compare operation but no assignment to old_a.
With other words: the static variables old_a and old_b have to get assigned the "current" value of a and b which will be "old" in the next run!

regards daniel

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #12 on: July 23, 2008, 05:46:11 pm »
You're right, one line got lost on the merge... committing that one. Thanks :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: Occurrences highlighting
« Reply #13 on: July 24, 2008, 03:11:47 pm »
Hi,

Dje asked to highlight only words with same case.
I use cb for c++ and vhdl development. VHDL is not not case sensitive, c++ is case sensitive.

Would it not be nice to store some info about the language together with the lexer configuration?
Example for c/c++ configuration:
Code
<LanguageAttributes
  LineComment="//"
  StreamCommentStart="/*"
  StreamCommentEnd="*/"
  BoxCommentStart="/* "
  BoxCommentMid=" * "
  BoxCommentEnd=" */"
  CaseSensitive="1"/>
And define an interface (like the colorset) to get these information during runtime.
(something like Manager::Get()->GetEditorManager()->GetLanguageAttributeSet()->GetCommentToken(lang) )

So we have not to change main.cpp from cb for every new language and the plugins/app can also get these information:
  • Occurrence highlighting likes to know if the language is case sensitive or not
  • Code Statistics only collects these infos about file comments in its config dialog
  • For the todo plugin it should be relatively easy to generate a dynamic line parser (boost::spirit) to find the todos not only in c/c++ files
  • Other things we don't know yet.

What do you think?

regards daniel


Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Occurrences highlighting
« Reply #14 on: July 24, 2008, 03:21:41 pm »
Hi !

I think it depends more on the user preferences, needs and context than on programming language.
That's why I think there should be check boxes in the editor configuration panel to set behaviour and store the options in default.conf.

I would also add that editors/IDE I used that had this feature used generally whole words and case sensitivity.

Dje

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Occurrences highlighting
« Reply #15 on: July 25, 2008, 05:17:18 pm »
This is a nice feature. I have one very minor (maybe even petty) issue as illustrated by the following sequence:
(1) Select a word -> Occurrences are highlighted
(2) Deselect the word -> Highlights are turned off
(3) Select the same word again - with no intervening selections -> Nothing happens
At step (3) it would seem that the Occurrences should be highlighted again, but to do this you must first select something else and then return to the original word.
Thanks for a nice feature!

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: Occurrences highlighting
« Reply #16 on: July 25, 2008, 05:34:26 pm »
Hi

Which revision do you have tested?

regards daniel

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Occurrences highlighting
« Reply #17 on: July 25, 2008, 08:58:05 pm »
Which revision do you have tested?

SVN 5162 on Windows XP.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Occurrences highlighting
« Reply #18 on: July 25, 2008, 09:37:58 pm »
I just added a patch to svn that should fix this issue.

For me it only occured if a word was reselected with a double-click.

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Occurrences highlighting
« Reply #19 on: July 25, 2008, 11:27:06 pm »
I just added a patch to svn that should fix this issue.
Yep. It works fine. Thanks.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #20 on: December 21, 2010, 11:03:28 am »
Anyone knows where I can found the source code for this plugin?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Occurrences highlighting
« Reply #21 on: December 21, 2010, 11:19:54 am »
This is not a plugin. It is in the main source of C::B
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #22 on: December 21, 2010, 11:24:01 am »
This is not a plugin. It is in the main source of C::B
But it was a plugin sometime (long time) ago, isn't it? Because I have a plugin version... :-p

Anyway, thx!

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #23 on: December 21, 2010, 11:32:45 am »
Sorry, my bad, I am looking for the "Occurence HighlightER" plugin from danselmi, which make highlights permanent for selected words...

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: Occurrences highlighting
« Reply #24 on: December 21, 2010, 12:55:14 pm »
I have no public repository for this small plugin. Sources are attached.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #25 on: December 21, 2010, 12:58:35 pm »
I have no public repository for this small plugin. Sources are attached.
Thank you very much... I find it really useful !!!!
« Last Edit: December 22, 2010, 11:48:49 am by daniloz »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Occurrences highlighting
« Reply #26 on: December 07, 2011, 01:49:27 am »
I'm sneaking what the "competition" does and I've found one feature which could be really useful.

See the video: http://www.youtube.com/watch?feature=player_embedded&v=fndDT2GK-KU

The feature they've added is keyboard shortcuts for going to the next/prev occurrence of the highlighted text.
How hard would it be for this to be implemented?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #27 on: November 13, 2012, 03:58:21 pm »
I'm afraid that finding references is a lot more complicated than finding syntax-agnostic substrings. Though it would be immensely cool (especially since non-patched occurrence highlighting doesn't do 1-character and 2-character selections, such as variable names like i, or pt, or it).

What would be even more helpful would be a feature to select all references, rather than highlighting them. Code::Blocks already supports non-standard selections and typing into all of them simultaneously. Now, for intuitive, quick-and-failsafe renaming, all one needs is "select all references".

"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 117
Re: Occurrences highlighting
« Reply #28 on: November 13, 2012, 04:12:32 pm »
Code::Blocks already supports non-standard selections and typing into all of them simultaneously.
I didn't know about this, where is this option? I have been looking around in menus and context menus, but I can't make multiple selections (let alone typing in multiple places).

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Occurrences highlighting
« Reply #29 on: November 13, 2012, 04:33:16 pm »
Code::Blocks already supports non-standard selections and typing into all of them simultaneously.
I didn't know about this, where is this option? I have been looking around in menus and context menus, but I can't make multiple selections (let alone typing in multiple places).
Look into "Settings -> Editor... -> Margins and caret -> Selections" .

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 117
Re: Occurrences highlighting
« Reply #30 on: November 13, 2012, 04:51:00 pm »
Interesting :)
However, I see that sometimes it can get very difficult to see what you have selected, precisely because of the highlight of occurrences.

See this as an example:

Code
int main()
{
    // try to select these Foos:
    if( SomeBool )  Foo( 1 );
    else            Foo( 2 );
   
    // but not this one:
    return Foo( 0 );
}

The selection color should get painted over the highlights, and not under it. As it is now, I can't see which ocurrences I have selected and which ones not. Another option could be to mix colors or use some transparency.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #31 on: November 13, 2012, 05:37:35 pm »


Don't undstand your problem. The first one is highlighted, the other two are highligted and selected. Typing will replace into the lower two.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Occurrences highlighting
« Reply #32 on: November 13, 2012, 05:42:33 pm »
(especially since non-patched occurrence highlighting doesn't do 1-character and 2-character selections, such as variable names like i, or pt, or it).
Thomas, this is possible if you use the "Incremental Search" plugin. Just enable the IS Toolbar from the menu, then enter even single character "words" into the search field and press "highlight". I find this really useful very often.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 117
Re: Occurrences highlighting
« Reply #33 on: November 13, 2012, 05:43:09 pm »
Ok, I'll try to post a screenshot when I get home so that you see what I mean.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #34 on: November 13, 2012, 05:49:34 pm »
I also think the highlighting and selection is confusing... see screenshot: I just double-clicked on the the first "cb_unused", but it's hard to tell which one is really selected...

[attachment deleted by admin]
« Last Edit: November 13, 2012, 05:51:32 pm by daniloz »

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 117
Re: Occurrences highlighting
« Reply #35 on: November 13, 2012, 05:53:08 pm »
Thanks daniloz, you saved me the work :) I think in that screenshot the first one is selected and the rest aren't, but one has to really focus to see it...

And by the way, the problem also happens for single selection. It is just less of a problem (it is easy to remember what you selected if it's only one thing ;) )
« Last Edit: November 13, 2012, 05:56:06 pm by carra »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #36 on: November 13, 2012, 05:57:53 pm »
(especially since non-patched occurrence highlighting doesn't do 1-character and 2-character selections, such as variable names like i, or pt, or it).
Thomas, this is possible if you use the "Incremental Search" plugin. Just enable the IS Toolbar from the menu, then enter even single character "words" into the search field and press "highlight". I find this really useful very often.
I've just patched the code to if(selection.Length() > 0) (therefore me referring to "unpatched"), which always works nicely, and doesn't ignore whitespace (used to trim whitespace, but it's even better without). Whitespace helps finding for example all occurrences of i without highlighting the one in while. Unluckily, it doesn't work nearly as well for for(Blah::iterator it = blah.begin; ...) f(*it); because it won't find the *it --- this is why finding (syntax aware) references would be so interesting.

Try and rename a single-letter variable (say, i) in a function that has more than 5 lines. It's a nightmare, and actually you should better stay away from it alltogether. When you are doing that kind of thing for a shadow warning, you spend 15-20 minutes on those 5 lines just to be sure you've not forgotten one, as that would modify the wrong variable in the wrong scope. And even then you feel bad about it afterwards. What's worst, the compiler won't even be able to warn you when it happens...

(Lesson to learn: don't use single-letter variables if you can help it. At least not in non-trivial code with several nested blocks.)
« Last Edit: November 13, 2012, 06:00:04 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Occurrences highlighting
« Reply #37 on: November 13, 2012, 08:30:04 pm »
Try and rename a single-letter variable (say, i) in a function that has more than 5 lines.
Technically its possible: Scintilla offers multiple selections (not necessarily bound together)  an also writing to multiple selections. CC could offer the interface to local variables, bringing both together allows what you want.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Occurrences highlighting
« Reply #38 on: November 13, 2012, 08:40:57 pm »
I find I get by pretty well with "match case + whole word" or regexp replaces. Something more interactive might be nice, but it might also be a lot of work for small result. Slightly offtopic, but, IMO, it would also be useful to be able to perform operations on the items in the find in files results list.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Occurrences highlighting
« Reply #39 on: November 14, 2012, 08:30:22 am »
I find I get by pretty well with "match case + whole word" or regexp replaces. Something more interactive might be nice, but it might also be a lot of work for small result.

I have to disagree with you here. I do agree that from a developer perspective "match case + whole word" or regexp replaces is just fine and the work for implementing something more interactive is not worth...

However, IMHO, from a typical user perspective, I think that would be a very nice feature because:

1- the user maybe is not acquainted with regexp
2- the user may feel more safe if there's something interactive to do the replaces, i.e. he may fell that he's not missing something

I'm fine with the actual "match case + whole word" or regexp replaces, but wanted to leave my 2 cents here....

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Occurrences highlighting
« Reply #40 on: November 14, 2012, 10:28:58 am »
Replace with "match regex" is not very usable. First, I've often seen it fail when it should work, especially when the regex contains properly escaped special characters such as ( or * or \ (incidentially this seems to work right now that I've mentioned it, but I've seen it fail with expressions that were 100% correct before), and second, merely having to bring up the dialog and writing the expression is a lot of work, which makes it less competitive.

Selecting a variable is a matter of holding down shift and pressing the arrow key (possibly 3-4 times), or doing a double-click with the mouse.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."