Any Xcode shortcut for wrapping a text selection in opening & closing brackets - { }, ( ) or [ ]?
Growing tired of removing the "}" that Xcode automatically enters after I type "{" in cases where I've already got code in the editor that wants to be inside the new brackets.
Here's an Xcode user script which should not wipe out new lines in the text.
#!/usr/bin/python
#
# Wraps selection in braces.
# Set Input to "Selection".
# Set Output to "Replace Selection".
tabChar = '\t' # Replace with spaces if desired
input = '''%%%{PBXSelectedText}%%%'''
print "{"
for line in input.splitlines():
print tabChar + line
print "}"
See the Script Input Variables section of the Xcode Workspace Guide for more information on %%%{PBXSelectedText}%%%
and the other available input variables.
EDIT: added support for indenting the code to be surrounded by a given amount. Right now the indent must be hard coded. It may be possible to get this value from, e.g., the Xcode preferences file, but I didn't go that far.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With