News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

A feature I want to implement

Started by oBFusCATed, May 11, 2009, 02:53:36 PM

Previous topic - Next topic

oBFusCATed

Hello,

I have an idea for a new feature, but I don't know where to start/what to modify, can you help me?

Here is the idea:
When I type a very long function definition/declaration/call, I hit enter to make the line shorter an more readable.
The current behavior on this action is to send the cursor at the beginning of the next line + 1 tab (I think).
I want to make it to go to the first opening bracket '(', so I can type:


void mylongfunc(int param1, 'hit enter here and directly go to the bracket and type the second param'
                int param2, ' ... and so on so forth'


The MS VC has that feature for function definitions, I want to expand it to definitions and callings.

Where do I need to hack  :lol:  :P?

Best regards,
Teodor
(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!]

dmoore

open codeblocks.cbp
ctrl-shift-f, search the project for SMART INDENTING

I would think that you won't need to hand parse the text. You should be able to use the lexing info in scintilla to find the position of the opening brace.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

ollydbg

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

oBFusCATed

Thank you,
I'll take a look at it, tonight.

Yesterday, I've done some experimenting and I have the basic feature working.
I need to polish it and add some improvements.
Then I'll show it, so more testing can be done.
(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!]

oBFusCATed

Here is the patch,
It only one major problem:


a = 5 + my_func(long_arg1, long_arg2, --> hit enter it works
                       long_arg3, long_arg4); --> hit enter and the cursor goes to
                       | --> here :(

a = 5 + my_func(long_arg1, long_arg2); --> here it works
| --> cursor is here after enter is hit


Is there a way to get the indent level of the previous statement or something similar.
It can stay that way, it is not mega annoying, but I prefer to make it better?

Feedback is welcome :)

p.p. Patch is attached to the post



[attachment deleted by admin]
(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!]

ollydbg


a = 5 + my_func(long_arg1, long_arg2, --> hit First enter it works
                       long_arg3, long_arg4); --> hit Second enter and the cursor goes to
                       | --> here :(



Great!
I'm not quite understand your idea.
Where should the cursor be after the second enter? :D

It should be like this below?:


a = 5 + my_func(long_arg1, long_arg2, --> hit First enter it works
                       long_arg3, long_arg4); --> hit Second enter and the cursor goes to
| --> here :(


Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

oBFusCATed

#6
Yes, it should go to the position of "a".
(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!]

dmoore

but won't your patch do this?


cout<<"(";<-- press enter
        |<-- cursor position


also, why not indent for other types of braces

slightly off-topic, but one reason I despise this feature is that it encourages coders to do this:


void my_func(
                  int arg1, // random gibberish comment
                  char *arg2,
                  myclass arg3, // random gibberish comment
                  )


instead of


// comment
void my_func(int arg1, char *arg2, myclass arg3);


even worse when they then do similar crap with the call, reducing the number of effective loc that I can fit on screen without really enhancing readability of the code.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

oBFusCATed

Quote from: dmoore on May 13, 2009, 05:42:15 PM
but won't your patch do this?


cout<<"(";<-- press enter
        |<-- cursor position


no, but


cout << "(" <<

will break it  :(
Any ideas what I can do to fix it?

Quote

also, why not indent for other types of braces
The '{' are handled by the indenter, '[' are not used on multiple lines (if there are no strange overloads :) ),
< require some more parsing (to distinguish if it is used in template or as operation).

Quote
slightly off-topic, but one reason I despise this feature is that it encourages coders to do this:


void my_func(
                  int arg1, // random gibberish comment
                  char *arg2,
                  myclass arg3, // random gibberish comment
                  )


instead of


// comment
void my_func(int arg1, char *arg2, myclass arg3);

Isn't that a problem of the coding standard/programmer? C::B is just a tool.
And if it is such a problem a config option could be added that is off by default.

Quote

even worse when they then do similar crap with the call, reducing the number of effective loc that I can fit on screen without really enhancing readability of the code.

Do you talk about this:

api_with_many_params(param1, // here we set something
                           param2, // here we set something else
                           param3, // here we set something else
                           param4, // here we set something else
                           );


(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!]

oBFusCATed

Hello again,

Here is the latest version of the patch.
I've fixed lots of problems, while using it (the patch wasn't working in lots of cases)
I've fixed the cout/quotes problem (the braces inside strings are ignored).
I've also made the patch to work when "Use Tab character" option is used (I think, I do the best I can in this mode).

I hope that someone from the devs team will find some time to review it,
so I can further polish it (fix bugs, some commenting, configuration option ...).
After that I hope it will be applied to trunk.

Best regards,
Teodor Petrov

[attachment deleted by admin]
(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!]

MortenMacFly

Quote from: oBFusCATed on May 21, 2009, 10:13:54 PM
I hope that someone from the devs team will find some time to review it,
I reviewed the past versions, too but in fact (sorry to say this) it was more annoying than helpful. Will try this one for sure. Looking forward to it! :-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

oBFusCATed

Don't be sorry, the patch version1 was totally broken.

Please report any problems you find.
(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!]