Author Topic: A feature I want to implement  (Read 8530 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
A feature I want to implement
« on: May 11, 2009, 02:53:36 pm »
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:

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

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: A feature I want to implement
« Reply #1 on: May 11, 2009, 04:03:23 pm »
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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: A feature I want to implement
« Reply #2 on: May 12, 2009, 02:40:17 am »
You can look into this thread for a reference:

http://forums.codeblocks.org/index.php/topic,10361.0.html
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: A feature I want to implement
« Reply #3 on: May 12, 2009, 11:04:18 am »
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!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: A feature I want to implement
« Reply #4 on: May 13, 2009, 03:25:43 pm »
Here is the patch,
It only one major problem:

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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: A feature I want to implement
« Reply #5 on: May 13, 2009, 04:16:21 pm »
Code
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?:

Code
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: A feature I want to implement
« Reply #6 on: May 13, 2009, 04:51:29 pm »
Yes, it should go to the position of "a".
« Last Edit: May 13, 2009, 04:59:38 pm by oBFusCATed »
(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 dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: A feature I want to implement
« Reply #7 on: May 13, 2009, 05:42:15 pm »
but won't your patch do this?

Code
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:

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

instead of

Code
// 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: A feature I want to implement
« Reply #8 on: May 13, 2009, 08:05:24 pm »
but won't your patch do this?

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

no, but

Code
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:

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

instead of

Code
// 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:
Code
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!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: A feature I want to implement
« Reply #9 on: May 21, 2009, 10:13:54 pm »
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!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: A feature I want to implement
« Reply #10 on: May 22, 2009, 06:50:16 am »
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: 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: A feature I want to implement
« Reply #11 on: May 22, 2009, 03:43:06 pm »
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!]