This forum has been archived. All content is frozen. Please use KDE Discuss instead.

auto brackets not so smart ?

Tags: None
(comma "," separated)
fluca1978
Registered Member
Posts
81
Karma
0
OS

auto brackets not so smart ?

Thu May 24, 2012 11:48 am
Hi all,
I'm really enjoying KDevelop, but coming from the Eclipse IDE I noted that auto-brackets function is not so smart: I mean each time I open a bracket the editor places a closing one, even if the closing one is already there. For instance:
Code: Select all
obj->method);

that is missing an opening bracket, so when I add a new one I end up with the following code:

Code: Select all
obj->method());


and a similar behavior is there for quoting, so that if you open a tick the closing one will be placed on the same line, so that I often end up with multiple ticks. Am I missing some trick in the configuration or this is the default KDevelop behavior?
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
I can confirm that I was annoyed by this a few times already, and that I effectively don't use auto brackets because of such issues (KDevelop itself does some auto-bracketing too, like for calling functions, the behaviour is more intelligent there).

To add an issue to the list: I think the correct behaviour to auto-add curly braces is this: if the user types "{", do nothing. As soon as "Enter" is pressed, switch to the next line, indent, and add a dedented "}" in the line below in case the document has mismatched "{"s overall.

This whole problem, however, is only related to kate (not in the scope of KDevelop). It must thus be improved there. I think it would definitely be worth it. :)

I think the relevant code is in kate/part/plugins/autobrace/autobrace.cpp.

Greetings


I'm working on the KDevelop IDE.
fluca1978
Registered Member
Posts
81
Karma
0
OS

Re: auto brackets not so smart ?

Thu May 24, 2012 3:44 pm
scummos wrote:To add an issue to the list: I think the correct behaviour to auto-add curly braces is this: if the user types "{", do nothing. As soon as "Enter" is pressed, switch to the next line, indent, and add a dedented "}" in the line below in case the document has mismatched "{"s overall.


This is exactly the behavior of Eclipse.

[quote="scummos"]
This whole problem, however, is only related to kate (not in the scope of KDevelop). It must thus be improved there. I think it would definitely be worth it. :)

I think the relevant code is in kate/part/plugins/autobrace/autobrace.cpp.

[quote]

Interesting, I'm going to have a look at the source code, I'm curious.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: auto brackets not so smart ?

Thu May 24, 2012 4:11 pm
This is exactly the behavior of Eclipse.

Yes, and the only sane one.

Interesting, I'm going to have a look at the source code, I'm curious.

Cool, good luck :)


I'm working on the KDevelop IDE.
fluca1978
Registered Member
Posts
81
Karma
0
OS

Re: auto brackets not so smart ?

Fri May 25, 2012 6:37 am
I took a look at the autobrackets.cpp source code, and it seems that it already implements the right behavior. I'm testing it right now.
User avatar
Milian Wolff
KDE Developer
Posts
61
Karma
1
OS

Re: auto brackets not so smart ?

Fri Jun 01, 2012 8:14 pm
Afaik the "autobrace" plugin (configure editor -> extensions) is also better in handling such cases, try it out.


current KDE projects: Quanta, KDevelop, Kate
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: auto brackets not so smart ?

Fri Jun 01, 2012 9:39 pm
Milian Wolff wrote:Afaik the "autobrace" plugin (configure editor -> extensions) is also better in handling such cases, try it out.

Judging from the name, that also seems to be the one related to the source code I found. Is there more than one engine doing this?


I'm working on the KDevelop IDE.
User avatar
Milian Wolff
KDE Developer
Posts
61
Karma
1
OS

Re: auto brackets not so smart ?

Sat Jun 02, 2012 5:30 pm
afaiks there is kate built-in stuff that handles this not-so-well and the plugin which is somewhat better - but not sure whether that has changed since I last hacked on the plugin ;-)


current KDE projects: Quanta, KDevelop, Kate
mpictor
Registered Member
Posts
7
Karma
0
OS

Re: auto brackets not so smart ?

Sun Jun 03, 2012 12:13 pm
scummos wrote:To add an issue to the list: I think the correct behaviour to auto-add curly braces is this: if the user types "{", do nothing. As soon as "Enter" is pressed, switch to the next line, indent, and add a dedented "}" in the line below in case the document has mismatched "{"s overall.


This is actually more work if you're modifying existing code, IMO.

Let's say that you have some existing code that you want to wrap with an if statement, because it's executing when it shouldn't. If you type the following and press enter, KDevelop is going to add two lines that you'll have to delete.
Code: Select all
if( condition ) {


What I do when adding new code is to type if( cond ) {} , left arrow, enter: I hold down shift while pressing the adjacent { and } keys, move the cursor inside them, and press enter. Kate and KDevelop both place the cursor on the next line, indented, with the curly brace unindented on the line after that.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: auto brackets not so smart ?

Sun Jun 03, 2012 11:59 pm
In my opinion the correct solution to solve this problem is to make the user edit and the IDE addition (auto bracket and newline) two seperate edits which can be seperately undone. The you can just do what you want and press Ctrl+Z in case you want to remove the auto-brackets. Do you think that would work okay?


I'm working on the KDevelop IDE.
mpictor
Registered Member
Posts
7
Karma
0
OS

Re: auto brackets not so smart ?

Tue Jun 05, 2012 12:51 am
scummos wrote:In my opinion the correct solution to solve this problem is to make the user edit and the IDE addition (auto bracket and newline) two seperate edits which can be seperately undone. The you can just do what you want and press Ctrl+Z in case you want to remove the auto-brackets. Do you think that would work okay?


Yes, that would work fine for me.

It wouldn't hurt to have an option somewhere to disable auto-bracket; I've heard rants from people who couldn't stand the fact that some software system insisted on doing something that (in their opinion) rarely or never helped them.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: auto brackets not so smart ?

Tue Jun 05, 2012 10:54 am
You can easily disable auto-brackets in the settings. I'm using this option...


I'm working on the KDevelop IDE.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell