Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: C++ editor behavior


This question is answered.


Permlink Replies: 4 - Last Post: Sep 2, 2016 4:37 AM Last Post By: Guest
James McKenna

Posts: 8
Registered: 5/20/16
C++ editor behavior  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2016 12:01 PM
Hi

I'm new to Embarcadero and this forum. I'm finding some frustration with the C++ editor auto formatting, and I can't find the options to change the behavior. I am using C++ in Berlin 10.1 with default editor options.

Specifically:

- When I type "if" followed by a space, the line autocompletes to "if (true) {" but with the cursor between the U and E of "true", and the four characters "e ){" selected (highlighted). Then of course the next character I type deletes those four characters, making a total mess out of the line. I've searched for options to fix this behavior but haven't found it. I've also tried to search the forum and web... but just try to describe that with keywords to a search engine and you'll come back with nothing related or useful... ;-)

- I'd prefer the closing brace on a separate line. I've found an option under "Formatter -> C++ -> Line Breaks -> Line Break Before Open Brace", but it does not seem to have an effect on auto completion.

- Strangely, every single mouse-click, search, etc seems to be considered a "change" when using undo (ctrl-z) - whether or not any actual change has occurred. Is there a way to change this behavior so that only real changes are considered by ctrl-z?

Any ideas? TIA.
Mike Versteeg

Posts: 118
Registered: 9/16/07
Re: C++ editor behavior  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2016 11:45 PM   in response to: James McKenna in response to: James McKenna
Do yourself a favour and disable autocomplete (and every other option on that page).
James McKenna wrote:
Hi

I'm new to Embarcadero and this forum. I'm finding some frustration with the C++ editor auto formatting, and I can't find the options to change the behavior. I am using C++ in Berlin 10.1 with default editor options.

Specifically:

- When I type "if" followed by a space, the line autocompletes to "if (true) {" but with the cursor between the U and E of "true", and the four characters "e ){" selected (highlighted). Then of course the next character I type deletes those four characters, making a total mess out of the line. I've searched for options to fix this behavior but haven't found it. I've also tried to search the forum and web... but just try to describe that with keywords to a search engine and you'll come back with nothing related or useful... ;-)

- I'd prefer the closing brace on a separate line. I've found an option under "Formatter -> C++ -> Line Breaks -> Line Break Before Open Brace", but it does not seem to have an effect on auto completion.

- Strangely, every single mouse-click, search, etc seems to be considered a "change" when using undo (ctrl-z) - whether or not any actual change has occurred. Is there a way to change this behavior so that only real changes are considered by ctrl-z?

Any ideas? TIA.
Andrew Law

Posts: 74
Registered: 11/6/02
Re: C++ editor behavior
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2016 8:30 AM   in response to: James McKenna in response to: James McKenna
James McKenna wrote:
- When I type "if" followed by a space, the line autocompletes to "if (true) {" but with the cursor between the U and E of "true", and the four characters "e ){" selected (highlighted). Then of course the next character I type deletes those four characters, making a total mess out of the line. I've searched for options to fix this behavior but haven't found it. I've also tried to search the forum and web... but just try to describe that with keywords to a search engine and you'll come back with nothing related or useful... ;-)

This automatic code behaviour is called Live Templates (more on this in a moment).

- I'd prefer the closing brace on a separate line. I've found an option under "Formatter -> C++ -> Line Breaks -> Line Break Before Open Brace", but it does not seem to have an effect on auto completion.

Formatter is for reformatting the layout of existing code, so this is not the area that you want to be editing, to solve your question.

It's not that difficult to edit the live templates, once you know where they "live" in the options.

My personal editing preferences for live templates, when completing a fresh install of C++Builder, is to do the following:

Go to View -> Templates. You should get a new popup window with a tree view. The tree nodes consist of various C++ keywords and shortcuts for longer code templates.
For each of the following tree nodes, you want to select the node, right-click on it, and select "Edit". The corresponding template will open up in the editor as an XML file. Scroll towards the bottom of the XML file, and look for the CDATA section. Move any opening curly brace from the end of one line to the beginning of the next line, save and close the XML file. That's it.

* for
* if
* ifeb
* struct
* switch
* try
* whileb (which is stored in while.xml, and not while, which is stored in whiles.xml)

If you really want to turn these features off entirely, then I think it is Tools -> Options -> Editor Options -> Code Insight -> Code template completion: un-tick.
James McKenna

Posts: 8
Registered: 5/20/16
Re: C++ editor behavior  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2016 11:39 AM   in response to: Andrew Law in response to: Andrew Law
Perfect - moving the brace to the next line not only updated the format the way I like it, but it also somehow fixed the problem with the wrong text being highlighted. Now "true" is selected as it should be.

Thanks Andrew!
Guest
Re: C++ editor behavior
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 2, 2016 4:37 AM   in response to: James McKenna in response to: James McKenna
Hello,

I have the same behavior with the little difference, that sometimes it is as James describes ( "e ){" selected ) and sometimes "true" is selected.
It makes no difference turning on or off the auto complete. It is the same.
Is there anything I can check/do, that "true" will be always selected?

Thanks,
Florian
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02