Xcode 4 code editor questions - xcode

How can I turn on curly brace matching?
This worked fine in Xcode 3.x. In Xcode 4 is doesn't work. I've already checked the box for "Automatically insert closing '}'" in the Preferences->Text Editing->Editing panel.
How can I turn on parenthesis matching?
How can I turn on code compeletion for "if/else-if", "for" etc?
In Xcode 3.x I would start to type "for" and autocomplete would provide the parenthesis, curly braces, semi-colons etc. I could then press escape for a menu containing (amongst other things) the option to do a "for i" loop (in which case Xcode would fill in "int i; i < n; i++" with n selected so I could just type a value).
In Xcode 3.x I could do something similar for if/else-if blocks. I could just start to type "if" and autocomplete would provide parenthesis, curly braces etc.
Edit: after looking for the "get info" option for a source code file (was simply right click the file name in Xcode 3) for five minutes I decided to downgrade to version 3.2.x. Which means hours of downloading. This really stinks :-(

Auto-} works a little differently in Xcode4. It doesn't appear as soon as you type the {. You have to hit return after to get the closing brace. So typing { gives the autocomplete. It feels a little odd at first, it took me awhile to adjust, but I think it makes sense. Most coding styles dictate a return after the opening brace, so it pretty much will always auto-close when you want it to. It doesn't give the } though in a case like making a single line if into a multi-line one. You can now add in the opening brace, move the curser to after the line, and enter the closing brace. Before when I did something like that I'd have to spend time deleting the auto-}.
For code completion, it sounds like you're having an indexing issue. Code completion still works as you want (it's actually a lot smarter now) in Xcode4. Your syntax coloring is also usually off when this happens. I ran into it with one of my projects and fixed it by editing my build settings, I had a bad one in it. You might also try deleting the project's derived data in the organizer. That'll force a rebuild of the index.
The "get info" items have moved. It's one of the land mines of the IDE rewrite. They're not in the file inspector. Show the utilities pane and then select the file inspector (the first icon in the tab bar).
Xcode 4 is a bit alien when coming from Xcode 3. They changed a lot of stuff. I'd recommend getting a feel for it. At some time in the near future Xcode 3 will be deprecated and you won't get the new SDks for it. You can have Xcode 3 and 4 both installed at once which is helpful for making the switch. That way you can fall back to Xcode 3 when you get stuck on something and will allow you to gradually make the change.

Related

xCode indenting driving be batty

I use xCode as my C editor for a small makefile project I'm working on. I keep noticing during Git commits that the whitespace is being changed on me. Here's an example:
void parse_key_values(Card *card, Errors *errors)
{
char str[MAX_LINE_LEN];
char key[MAX_LINE_LEN], value[MAX_LINE_LEN];
Although difficult to see, if you cursor through this you will notice there is a single 2-space-wide tab and a space at the front of the lines. The tab is correct and what I would expect to see. I have no idea where the space is coming from. When I remove it manually and re-indent, it re-inserts it.
Here is my setup:
I have tried changing "prefer tabs" to "prefer spaces", and then goes ahead and inserts three spaces.
I suspected that it was counting the opening brace and indenting from there, but then noticed the same problem on code like this:
if(split != NULL) {
if (split[0] == '=') split++;
if (split[0] == ':') split++;
This is driving me crazy, and causing all sorts of annoyance during commits. Anyone know what's going on here?
sigh
So right over on the right side of the screen is this little bit of UI:
Somehow, and it absolutely was not deliberate, the second of those two settings was changed to "3", so xcode was doing precisely what it was told to do.
Having never used that field, ever, I have never even looked at it. I'm still lost as to how I managed to change it.

DataGrip current statement highlighting

I installed DataGrip and spent a couple hours getting rid of bells and whistles that distract me from editing sql, like the lightbulb. I'm down to this one that for my life I can't figure, so when I move around with the caret, the editor comes up with what it thinks is the current statement and draws a thin border around it, say if it's a line ending in a semicolon, it will border just that line, but if I have several statements each not ending in semicolon, it will think they all make up a single one and draw the rectangle around the whole thing. This in itself is distracting, plus if I hit Enter within the border, it will indent differently according to what it thinks the whole thing is. I just want Enter to go to a new line at the 0, leftmost position.
Is there any way to turn the whole feature off completely?
Apart from that, does anyone know if it's possible to get DataGrip to display the number of rows affected after an INSERT or UPDATE, like most other tools do?
I'm using it with Postgresql. Thank you in advance!
cpp_developer! (By the way, what do you think about CLion? :)
There are several questions in one, let's get answers one by one.
Lightbulb: there is no UI for getting rid of it, but there is the way. It is described in this ticket: https://youtrack.jetbrains.com/issue/IDEA-94381
TLDR:
Following line should be added to the
$IDE_CONFIG_HOME/options/editor.xml then:
<option name="SHOW_INTENTION_BULB" value="false" />
Line showing the current statement.
It can be removed, like any other color/font thing: A small helpful action. For now it is only present in the Find Action menu (Ctrl/Cmd+Shift+A), but as usual, you can assign any shortcut to it.
This action will navigate you to the settings which are relevant to the context under the caret. If there are several of them, just choose one. In your case "Statement to execute". Then remove it or make white.
Smart indenting. Just turn this off:
Number of INSERTed and UPDATEd rows can be found in Output tab. But please, run them in batch mode -> context menu "Run %your_console%.sql"

Alt + Enter doesn't use appropriate quick fix in Resharper

I worked with Resharper 5 before and when I have a problem in code (for example unsuitable space around a parentheses), I used Alt+Enter and Resharper fixed the problem. But in V6, this doesn't fix the problem, it generate a supress statement! What should I do?
Here is more detail:
1- I have this line in my code:
if (this.RequestClose!= null)
Resharper draw a blue line under it and warn that the space around != is not correct.
In Resharper 5, I could press Alt+Entyer two times to fix the spacing problem. In Resharper 6, if I press Alt + Enter two times on this line, nothing happens.
2- I have this line in my code:
var view = new AddressDetailView();
view.DataContext = viewModel;
Resharper suggests using object initializer, but pressing Alt+Enter twice doesn't fix it.
Resharper 6.1 solved this problem!
Did you actually look at the menu item you're selecting? (I'm guessing not, since your question includes no mention of what's in the menu.) Alt+Enter brings up a pop-up menu, you know. By pressing Alt+Enter twice, you're just selecting the first item in that menu.
ReSharper 6 has new features, therefore it has more options in the list, therefore the order is sometimes different. The quick fixes are almost certainly still working; it's just that the first quick-fix in the list isn't always the same one as in R#5.
The solution is simple: read what's on the screen before you select it. If the quick-fix you want isn't the first in the list, then cursor to the one you want before you hit Enter.
(There's never been a ReSharper version where it's safe to always accept the first item in the menu -- the options change depending on whether R#'s background scanning has completed yet or not. If you've been blindly accepting the first item every time, I'm surprised you haven't gotten bitten before now.)
I could not find any way to fix this problem and decided to use R# 5.1 with Style cope instead.

Automatically insert closing bracket in Xcode

is there a way to have Xcode append a closing bracket ")" when I type the opening one "("? I know that it does this for those {}. I really miss Textmate :( A generic way to define which chars should be automatically inserted when the opening ones are entered would be kickass.
In Xcode 3.1 go to Preferences->Indentation
Check Syntax-ware indenting to on
and check Automatically insert closing "}"
and choose the characters you want to be inserted when the opening one is.
Also why not use Textmate nothing stops you and Xcode will notice if a file is edited externally
Have a look under Edit->Insert Text Macro->Objective C->Bracket Expression. This will insert a matched pair of brackets (or if you have something highlighted, put brackets around it). You could bind this to [ as a keyboard shortcut.
You can follow the instructions here to create one for parentheses. I tried but couldn't make it work.
http://cocoawithlove.com/2008/06/hidden-xcode-build-debug-and-template.html#textmacros
Personally, I drag the classes folder over to Textmate and edit there. I switch back to Xcode when I need to type in some long method name, or to build. I've been building a library of snippets for some of the common things I do in Textmate to make life easier there.

How can I turn on parenthesis matching in Xcode?

Curly brace matching was pretty easy to turn on. How can I turn on parenthesis matching in Xcode?
on Xcode Version 6.1 (6A1052d), you just need to double click on one of the parenthesis and the entire code that the parenthesis is scoping out is highlighted.
for example, if you have a code like the one below and you double click '{' or '}' bracket the entire code in their scope is highlighted :
if(condition == true)
{
//do something
}
Choose editor -> code folding -> focus
Edit
In XCode 9 the only solution is to put mouse over parentheses while pressing command button. Only this works.
Previous
To extend the other answers
it is possible to roll in/out code inside brackets.
Choose Editor > Structure > Balance Delimiter
url
Nevertheless, as already written earlier, the major feature is
Editor > Code Folding > Focus Follows Selection
press command key and its hover the brace and parenthesis ...
You must be running Xcode in Snow Leopard and install Xcode from the Snow Leopard disc that you got at WWDC. If you did not get a Snow Leopard disk, then you are out of luck unless you find one elsewhere.
The version of Xcode needed is 3.2 and the other components in the about page are:
Component versions
Xcode IDE: 1600.0
Xcode Core: 1599.0
ToolSupport: 1591.0
Please have a look at below answer for Xcode 9.0 and above:
Xcode highlights an opening delimiter (brace, bracket, parenthesis) when you move the cursor left-to-right over the matching closing delimiter. The highlight animation lasts about 1 second total, which is plenty in the case where you need a hint (and as you say the other delimiter is nearby).
If you need a more persistent indication, you can double-click either the opening or the closing delimiter, and Xcode will select both delimiters and their contents. (You can also use this, for example, to get quickly to one delimiter from another, even if they're far apart — double-click the delimiter you can see, use the left or right arrow to get the other end of the selection.)
With latest xcode13 we can permanent active this option with
"Xcode" --> "Preference" ---> "Text Editing" and by enabling "Code folding ribbon"
Thanks

Resources