Xcode offers the following options under
Preferences > Text Editing > Indentation > Tab key:
In leading white space: Pressing Tab inserts an indentation only at the beginning of a line or following a space.
Never: Pressing Tab never causes an indentation.
Always: Pressing Tab always causes an indentation.
I checked the documentation for these options (that's what is to the right of the colons) but I still don't understand. What is "an indentation"? What I'd really like is if Xcode wouldn't act like it knows better than me and try reindenting lines of code that were already perfectly indented (I find it often does this inside of blocks - I'll have my code nested one level more than the line before it, and for whatever reason it tries aligning with the colon that starts the block argument, leading to unwieldy long lines, as if Obj-C doesn't have enough of those.)
Can anyone give me examples of how Xcode's behavior will change if I choose each of those options? Will one of those options make Xcode behave/autoindent the way I want it to?
If what you want is:
if Xcode wouldn't act like it knows better than me and try reindenting lines of code that were already perfectly indented
then the "Tab key" indentation setting has nothing to do with what you want.
Instead, try unchecking "Automatically indent based on syntax" and Xcode will stop changing your indentation level.
Alternatively, uncheck { and } under "Automatic indent for:".
See also: Xcode Text Editing Preferences Help: Setting Source Editing and Indenting Preferences
Related
I have to submit an assignment and they want all the indents to be 3 spaces. I don't know how to change the settings of Astyle.dll so that it will change them 3 spaces instead of the default 4. Any ideas?
Also, Astyle seems to like having no indent between switch() and its cases, and I need there to be an indent there. Any ideas?
All of Astyle's settings are exposed in the Code::Blocks editor settings dialog. To access them, open the Settings menu, click Editor, and scroll through the sidebar to find the Default code entry.
I have to submit an assignment and they want all the indents to be 3 spaces.
Switch to the Indentation tab, found under Source Formatter in the sidebar, and change Indentation size (in spaces): to 3.
Also, Astyle seems to like to have no indent between switch() and its cases, and i need there to be an indent there.
If I understand what you need correctly, check the box that says Indent switches (keyword case:) and check the box that says Indent case: statement in switches (commands under case:).
You can change any other settings you want as well. When you're done, hit OK, then reformat your code and make sure the settings are set the way you want them.
In Eclipse, there are two distinct features: one to format a selection, one to just indent the lines, see e.g. Difference between Ctrl+Shift+F and Ctrl+I in Eclipse. I found the format feature in Visual Studio but how can I actually just indent the lines? Is there some built-in command for that or possibly a 3rd party add-on?
Note: I have asked a couple of friend that use VS daily and they all tried to persuade me that I am looking for the format feature. No I'm not. I tried to live with it for a while and it is just a different feature. I am after the indent/reindent only.
EDIT: I am looking for a clever indent, sometimes called reindent, which is different to just pressing Tab or Shift+Tab (increase/decrease indent level). The indent feature in Eclipse behaves like this:
It places a beginning of current line at the right position, no matter where that line was starting before. So instead of thinking whether you need to increase or descrease the indent level (Tab or Shift+Tab), you just invoke the indent command and it will do the right thing.
Invoking the indent command on an empty line places the caret at the right position for the user to start typing.
It never influences any character beyond the first non-whitespace character.
If you just want to indent some lines, you can
Select them.
Press Tab.
To un-indent them, replace the second step to: Shift+Tab.
You can find more VS shortcuts here.
There are toolbar buttons for this, with wonderfully inconsistent labels (at least in the Visual Studio 2013 I'm using)...
In the "Text Editor" toolbar (in my default setup), I have to buttons whose tooltips are:
"Decrease Line Indent"
"Increase Line Indent"
In the "Customize" dialog, on the "Commands" tab (with "Toolbar" set to "Text Editor") they appear in the list as:
"Line Unindent"
"Line Indent"
And finally, if you press the "Add Command..." button (on the "Customize" dialog) to produce the "Add Command" dialog and select the "Edit" category, you'll see these two entries:
"Outdent"
"Indent"
As far as I can tell, these are all the same two commands, which should do what you want.
They also appear in the Edit -> Advanced menu, at the very bottom.
----- Edit -----
I believe you might be able to turn off all of the "formatting" actions except for indentation, so that when you use the "auto-format" command, only the indentation is "formatted" for you. (Of course this prevents you from ever using the rest of the formatting features without turning them on again, but if you don't use them, this might work!)
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.
ok, possibly insanely n00b question or something i have overlooked in Xcode prefs: On pressing return, in stead of Xcode's syntax-aware indentation doing smart indent from whatever brackets i've used on the previous line, how can I make it so Xcode indents just from the beginning of the previous line?
From the picture below, first block of code is what i got, second block of code is what I want.
Visual representation:
visual representation http://img704.imageshack.us/img704/289/screenshot20100504at122.png
As an alternative to xcodes formatting, you can use Uncrustify. It can understand Objective as well as a variety of other languages. I set mine up as a script in xcode and assigned it a hot key so that it reformats the whole file or just the selected code.
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