XCode 3.2: Changing the default “Code Sense” indentation and whitespaces

柔情痞子 提交于 2019-12-03 02:52:01

问题


I'm working with XCode 3.2 (on "Snow Leopard") which (still) has this nice "Text Macro" auto-completion feature (eg. if you type if it will expand to if (<#condition#>) { <#statements#> }). These macros are also available via "Edit->Insert Text Macro".

Unfortunately, the default templates don't match my beloved indentation and whitespace style so I'd like to modify them.

According to this slightly outdated StackOverflow thread the corresponding definitions should be located at /Developer/Library/Xcode/Specifications/{C,HTML}.xctxtmacro but I can't find anything there using Snow Leopard and XCode 3.2 (not sure which one is responsible).

Has anyone noticed where the Apple defined Text Macros are located nowadays?


回答1:


The only **.xctxtmacro* files on my system were within the XCode.app bundle. After having a quick look a the definitions, I found a completely different way of adapting the formatting of all predefined macros:

You can simply set the XCCodeSenseFormattingOptions user defaults to modify the default newlines and other whitespaces within all macros!

For example the macro "if-else" looks like this by default:

if (<#condition#>) {
    <#statements#>
} else {
    <#statements#>
}

After executing the command

defaults write com.apple.Xcode XCCodeSenseFormattingOptions
-dict PreExpressionsSpacing "" BlockSeparator "\n" PostBlockSeparator "\n"

it looks like this (which I prefer):

if(<#condition#>)
{
    <#statements#>
}
else
{
    <#statements#>
}



回答2:


I believe that "defaults write com.apple.Xcode" doesn't work on the latest versions of Xcode.

The workaround is to edit the default Code Snippets.

However, Xcode doesn't allow to modify the default Code Snippets.

In order to modify them, you can download a "Snippet Edit" program from here



来源:https://stackoverflow.com/questions/1502710/xcode-3-2-changing-the-default-code-sense-indentation-and-whitespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!