Inserting space before parens in Xcode

Hey everybody! I've got a Juce-related code-formatting issue (stop groaning, it's not that bad). 

I like the Juce convention of inserting a space before opening parentheses. Unfortunately this is a bit at odds with the way Xcode likes to format things when it tries to help you complete function calls. 

Is there any way to get Xcode to insert a space before parens automatically? It would save me a lot of reaching for the mouse, but can't seem to find an option for this anywhere. 

nick

 

Perhaps this

Can be modified to do that.

Rail

interesting, i may check that out. thanks! wish there was some native way to do this but so far I'm coming up short.

Is there any way to get Xcode to insert a space before parens automatically?

This also bothers me quite a lot. I neither found a solution yet.

My workaround - no evangelism intended:
I have added the key binding 'Alt-Command-E' for 'Open in external editor' to XCode. My weapon of choice is MacVim + YouCompleteMe. With this you can add a space before an opening parentheses and still get code completion. You also can split horizontal and vertical and edit multiple files with ease, and you get a ton of other powerful vim features.
http://www.juce.com/comment/308777#comment-308777

 

@Jules:
May you share your workflow about how you deal with adding spaces in front of parentheses in XCode? Has Juce mainly been written in XCode or do you use a dedicated text editor?

@Jules:
May you share your workflow about how you deal with adding spaces in front of parentheses in XCode? Has Juce mainly been written in XCode or do you use a dedicated text editor?

I mainly use Xcode these days, but never attempted to make it automatically do the spacing - I just spend a lot of time nudging things around manually!

I'm also a VIM user these days, feel handicapped coding without it! 

MacVim, YouCompleteMe + Syntastic, plus Command-T are the main plugins that help my coding flow.

Recommended if you have the time to learn the basics of VIM:

  • type 'vimtutor' and complete the exercises a few times. 
  • use Vundle or similar plugin manager
  • once you've got the basics read http://www.slideshare.net/andreizm/vim-for-php-programmers-pdf

I know this is an old thread, but as a developer just learning JUCE and c++, I wanted to find a solution to easily check that I’m using the correct conventions. I was able to find an Xcode plugin on Github that worked perfectly. You can find it here: https://github.com/mapbox/XcodeClangFormat. It takes in a custom .clang-format file to format your code to your needs. You can find the documentation for writing your own file on the clang llvm website. Amazingly, I was able to find someone on Github that had already written a .clang-format file for JUCE! You can find that here: https://github.com/MartyLake/CrdtExamples/blob/master/.clang-format.

3 Likes

Hey @GrantEmerson, thanks for quoting my clang-format file :smiley: .

I created a bash alias that does more or less the same: it formats all modified files and opens the git-gui to commit. I know it can be done with git hooks but did not have the patience to set it up for every projects. :slight_smile:
https://gist.github.com/MartyLake/b76796d70bd65f4e601093477571a566

3 Likes