Author Topic: When include a file, auto add matching brackets  (Read 25010 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
When include a file, auto add matching brackets
« on: April 21, 2010, 06:11:09 pm »
In the #include statement:
When entering the #include <xxxx.h| , auto add the ending matching bracket.

As we know, if include a file, like this:
#include "someheader.h

Then, the CC tip's will show "someheader.h" in the Tip Window.
But when we selected it, it's only change to:

#include "someheader.h // HERE, lose a " or >

If we apply this patch, it's can auto completion the matching brackets.
Like this:
#include "someheader.h"
OR
#include <someheader.h>

EDIT: fix, when type some char, it will failed.

[attachment deleted by admin]
« Last Edit: April 22, 2010, 06:31:47 am by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #1 on: April 22, 2010, 06:15:55 am »
Fix a bug, now it will works well.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #2 on: May 02, 2010, 09:35:59 am »
Although I didn't try the patch out, this would indeed be nice. Question when the closing "> is added, I assume the cursor is behind it so I don't 'enter' the closing "> to the next line ?

I was wondering what you and others think of this (some of my personal irritations ;-) ).

I typically structure a project like this :

Project-Dir with the following subdirs :
* Project (contains the cbp file)
* src (contains *.cpp and .h[that don't need to be exported]
* inc (contains  *h[that are to be exported, typical use : when the project is a static lib or dll]

Use case 1 :
I am working on a file in the src dir, when I want to include a header file it gives them to me as "../src/header.h". This is correct but I like it to be normalized/reduced --> ../src is where I am at the moment, so I just want "header.h"

Use case 2 :
I added for example the inc directory of another component to the list of include/search directories.
I want to include in a source file in the src directory of my current project a header from that other component.
Not even 1 header file from the added include directory shows up. It would be nice those would pop up to.

Use case 3 :
In the ultimate case when I start an include with < , I would like to see the C/C++ headers too in the list.
I have type already so many times vector, string, iostream, .... ;-)

What do you guys think ?


Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #3 on: May 02, 2010, 09:51:34 am »
About Use case 1 ~ 3:
Hi, killerbot, I need check the code, but now, i can't be sure it.
I will trying.
« Last Edit: May 02, 2010, 09:56:31 am by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #4 on: May 02, 2010, 09:54:10 am »
Question when the closing "> is added, I assume the cursor is behind it so I don't 'enter' the closing "> to the next line ?
Yes, if completion the right brace, the caret is here:
#include <some.h>|

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: When include a file, auto add matching brackets
« Reply #5 on: May 02, 2010, 10:33:10 am »
Quote
Use case 3 :
In the ultimate case when I start an include with < , I would like to see the C/C++ headers too in the list.
I have type already so many times vector, string, iostream, .... Wink

I have a think for this for a long time , just not figure out a good way to implement it. :wink:
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: When include a file, auto add matching brackets
« Reply #6 on: May 02, 2010, 11:02:26 am »
For 3: Is there a way to get all automatic include paths?

If there is we can scan this paths and cache the result, after some time we can scan again.
Another way is to hook the folders and wait for changes.
(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 killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #7 on: May 02, 2010, 11:38:24 am »
For 3: Is there a way to get all automatic include paths?

If there is we can scan this paths and cache the result, after some time we can scan again.
Another way is to hook the folders and wait for changes.

For GCC we go hunt for them for the CC, otherwise even something like right clicking on include <string> to open the string header didn't work.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #8 on: August 02, 2010, 11:14:02 am »
Use case 1 :
I am working on a file in the src dir, when I want to include a header file it gives them to me as "../src/header.h". This is correct but I like it to be normalized/reduced --> ../src is where I am at the moment, so I just want "header.h"

Use case 2 :
I added for example the inc directory of another component to the list of include/search directories.
I want to include in a source file in the src directory of my current project a header from that other component.
Not even 1 header file from the added include directory shows up. It would be nice those would pop up to.
Hi, killerbot, I make a patch for do this.
Welcome for test.

The patch based cc branch.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #9 on: August 02, 2010, 12:21:19 pm »
this sounds great, could you think you can have a patch for trunk ?

by the way : any idea when another merge round from cc_branch to trunk might happen ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: When include a file, auto add matching brackets
« Reply #10 on: August 02, 2010, 01:04:47 pm »
The patch based cc branch.
...and applied there.

by the way : any idea when another merge round from cc_branch to trunk might happen ?
Depends on how well we do testing of this branch. Everybody can contribute by doing so and making tests. Basically the CC branch is very well lined-up with trunk so you are not going to miss any features if you simply switch to this branch.

What about a second nightly? - One for trunk and one for the branch... probably not always... but from time-to-time?!
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 Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #11 on: August 02, 2010, 07:01:49 pm »
Use case 3 :
In the ultimate case when I start an include with < , I would like to see the C/C++ headers too in the list.
I have type already so many times vector, string, iostream, .... ;-)
support system headers now. :lol:
Based CC Branch too.
Sorry, I am not using trunk, but only cc branch.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #12 on: August 02, 2010, 07:13:06 pm »
time to jump towards the cc branch for me then.

One question related to the branching. I would keep both branches on my laptop. And depending on what to use for the moment, I would issued the make install of the branch of interest.
Could there be any conflicts of each time make install on top of the previous one [by the way : what's the clean for make install ? is it make distclean ?]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #13 on: August 02, 2010, 07:14:00 pm »
Use case 3 :
In the ultimate case when I start an include with < , I would like to see the C/C++ headers too in the list.
I have type already so many times vector, string, iostream, .... ;-)
support system headers now. :lol:
Based CC Branch too.
Sorry, I am not using trunk, but only cc branch.
@Martin : could you apply this one too to the cc branch ?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: When include a file, auto add matching brackets
« Reply #14 on: August 02, 2010, 07:50:43 pm »
what's the clean for make install ? is it make distclean ?

Code
make uninstall

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: When include a file, auto add matching brackets
« Reply #15 on: August 02, 2010, 08:31:37 pm »
@Martin : could you apply this one too to the cc branch ?
Done. But it's untested (from my point of view).
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: When include a file, auto add matching brackets
« Reply #16 on: August 02, 2010, 08:35:39 pm »
Code
make uninstall
But this is not very robust way of uninstalling software (you should have the original sources/build system).

killerbot:
The best way is to learn how to make packages from source for your distro (gentoo and arch are pretty easy with svn software. I don't know how hard it is in deb and rpm based distros, but it shouldn't be too hard :) )
(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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: When include a file, auto add matching brackets
« Reply #17 on: August 02, 2010, 10:11:00 pm »
checkinstall is the package to look for (at least for test installs, normally not for real packages).
It monitors the installation and creates Slackware, rpm or debian packages.

And "make uninstall" should work, and yes it should be used from original sources of course.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #18 on: August 02, 2010, 10:38:45 pm »
well packages are a bit too much, when building from source : make && make install, then make uninstall should do the trick, I guess as suggested by Jens.

By the way, currently I checked out the cc branch with just read permissions, anyone have it open with write permissions --> merge from trunk please because cc branch does not build (wxMedia issue ...).

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #19 on: August 03, 2010, 08:00:25 am »
I tested it using ArchLinux,  it still works well, but prompt header slower rate of more than XP. :(

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #20 on: August 03, 2010, 08:03:10 am »
Here is another patch, for support preprocessor completion.
And improve system headers completion.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #21 on: August 03, 2010, 08:19:57 am »
wauw, this is really looking very great  :P

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #22 on: August 09, 2010, 04:01:20 pm »
it however doesn't work for some preprocessor stuff for me.
I want to type : #include ......

when I type the '#' I already get code completion suggestions, but include is not one of them.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #23 on: August 10, 2010, 04:20:51 am »
it however doesn't work for some preprocessor stuff for me.
I want to type : #include ......

when I type the '#' I already get code completion suggestions, but include is not one of them.
Fixed!
« Last Edit: August 10, 2010, 04:44:39 am by Loaden »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #24 on: August 10, 2010, 08:13:07 am »
I can confirm this is fixed, but now I don't get any include files anymore.

1) I type #in  --> complete to include
2) then I type either < or "  --> once again I get the list of preprocessor completions (define, elif, include , ....)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: When include a file, auto add matching brackets
« Reply #25 on: August 10, 2010, 08:41:54 am »
1) I type #in  --> complete to include
2) then I type either < or "  --> once again I get the list of preprocessor completions (define, elif, include , ....)
Harhar... same here. :-)
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 Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: When include a file, auto add matching brackets
« Reply #26 on: August 10, 2010, 02:39:53 pm »
1) I type #in  --> complete to include
2) then I type either < or "  --> once again I get the list of preprocessor completions (define, elif, include , ....)
Harhar... same here. :-)
Sorry, I was careless.
Fixed again.
« Last Edit: August 10, 2010, 02:46:19 pm by Loaden »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: When include a file, auto add matching brackets
« Reply #27 on: August 10, 2010, 03:55:57 pm »
I can confirm it now works, and also right click on an include to open it, now works again (just before most of them were 'not found').