how to make Xcode indentation from beginning of previous line? - xcode

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.

Related

Clarification of Xcode's Indentation Options?

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

How to automatically keep the smart indent in visual studio

I don't quite know how to phrase this question, but basically what happens is:
if i smart indent in visual studio, then click somewhere else on the page or even on the exact same line that has the smart indent, it then goes away, as if I'd had no indenting at all, not even block indenting.
It just puts the cursor/insertion point at the very beginning of the line.
EDIT: BTW I recently formatted my computer and I'm almost certain this wasn't the case before, I'm guessing it's a setting, but I've been fiddling around with all the settings trying to change this, but I can't.
Open Tools->Options. Navigate to Text Editor on the LHS. Select the source type (C++, VB, etc.). Open the tree view node and select Tabs. There, on the RHS you'll find your option

Reformatting code in text mate to established code conventions - Visual studio's ctrl K+D equivalent on Text Mate

Can anyone tell me if there's a quick way to format your code in Text Mate, similar to pressing ctrl K+D in Visual studio?
Thanks!
Edit by Damien_The_Unbeliever:
For those not familiar with Ctrl K+D, it doesn't just indent code - it reformats it using the generally established formatting conventions in the editor - it may replace spaces with tabs or vice-versa for the indentation, ensure code is consistently indented, move braces to separate lines, etc.
TextMate reindenting and reformatting varies a little depending on the language you're using.
You can generally use the Text menu, that depending wether you have an active selection or not it will show you different commands under it. For example, if you have selected a section of code, there will be a Indent Selection menu item. If you have no active selection, it will be Indent Line.
To have this working properly, be sure to select the current language, if it isn't assigned yet (like on unsaved documents). If you're working with HTML, it will simply indent the lines depending on what's above it. It will keep line breaks intact.
If you need something to break out tags on new lines and properly format the document, you should use the Tidy command that is found in the Bundles menu, under HTML (or simply by using the shortcut CTRL+SHIFT+H. If you have a selection active at the moment that you use it, it will simply reindent that section. If instead you have no selection, it will properly reformat the whole document, including checking for tag validity and other errors.
The Bundles for other language have similar commands, like XML (still Tidy) and Javascript (that has a Reformat Document command).
As an ending note, I simply suggest to look into the Bundles menu; there are many little gems in it. ;)
Did you look in the menu bar? Under Text you have a couple of Reformat… entries that may fit your needs.
Beside these native features, some bundles — like the JavaScript one — have custom Reformat… commands : click on the little cog button at the bottom and explore your current language's bundle's content.

Xcode 4 code editor questions

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.

Disable auto-indent certain items in Visual Studio 2005?

I don't mind most of the way that VS2005 auto-indents (or auto-formats) my C++ code, but certain items I don't want it to automatically indent. Like #define statements for example. It takes them and shoves them all the way to the left side of the screen, no matter how deep into my scope I type them. That's really really annoying.
Is there some way to alter this behaviour, besides completely disabling auto-indent/format?
If you have only a few examples you want to change (and don't mind re-correcting the indentation when there are whole section or file reformats), you can change the indentation to what you want, then move off the line.
The formatted indentation will return, but you can Undo (Ctrl+Z) and the indentation you want will return. (Note I haven't actually tested this in the C++ editor.)
As long as you don't mind "correcting" the indentation every time you edit the line (and the other times the whole section is reformatted), this allows you to have some lines alternately indented.
Try go to Options -> Text Editor -> C/C++ -> Tabs -> Indenting and change it to Block. When selected, new lines are automatically indented. The insertion point is placed at the same starting point as the preceding line.

Resources