I think over the last year and a half, while experimenting with Cocoa and Cocoa Touch development, I've been struggling with getting Xcode to support a kind of key macro to handle this specific coding scenario...
I frequently find myself not knowing ahead of time how many message dispatches to chain together while typing a new line of code. For example, I might type this... (Pipe character represents cursor location)
someVariable = [someObject someMessage]|
...I then realize that I need to chain a message from the returned object (since messaging nil is safe in ObjC, this is a common idiom.) So I would need to change the line of code to look like this...
someVariable = [[someObject someMessage] |
The big problem is having to prepend a left bracket before the bracket pair I'm at the end of, which would entail using the mouse or lots of repeated key tapping each time I needed to do this. After wasting about 40 or so hours off and on trying to find any kind of pre-existing keyboard shortcut or script (I investigated Perl, shell scripting, and even a bit of emacs Lisp scripting in my Googling.), I hacked together this monstrosity in AppleScript, of all things...
tell application "System Events"
delay 0.2
set editMenu to menu "Edit" of menu bar item "Edit" in menu bar 1 of
process "Xcode"
set kLeftArrowKey to 123
key code kLeftArrowKey
set theMenu to menu item "Balance" in menu "Format" of menu item
"Format" in editMenu
click theMenu
set theMenu to menu item "Bracket Expression" in menu "Objective C"
of menu item "Objective C" in menu "Insert Text Macro" of menu
item "Insert Text Macro" in editMenu
click theMenu
key code kLeftArrowKey
end tell
There has got to be a better way.
I count at least five problems with the above... (which I'll comment on if asked.) I see frequent online complaints from new ObjC developers all the time about this syntax, and I suspect this one typing issue is the major sore point. While I like how the syntax reads (so much so that I avoid the dot notation for properties out of coding consistency), how it's first written kind of sucks. (Just like AppleScript, ironically enough, given my current hacked implementation.)
Help me end my suffering, and you'll probably end the suffering of a lot of other ObjC developers as well...