This is an idea for a Service (as in the Services menu) to help Objective-C programmers.
Often I'm looking at a method declaration or method invocation and I'd like to be able to copy and paste just the method name and not any of the arguments.
For example, say I'm looking at a method declaration like this:
- (void)putBook:(NSString *)theBookName
inSection:(NSString *)theSectionName
ofLibrary:(NSString *)theLibraryName
inCity:(NSString *)theCityName;
…or a method invocation like this:
[masterLibrarian putBook:@"The Dark Knight"
inSection:@"Graphic Novels"
ofLibrary:@"Mid-Manhattan Branch"
inCity:@"New York City"];
I'd like to be able to select either of these code snippets and invoke a Service that puts "putBook:inSection:ofLibrary:inCity:" into my pasteboard. Ideally, my selection could be sloppy at the beginning and end, so I could select:
ian putBook:@"The Dark Knight"
inSection:@"Graphic Novels"
ofLibrary:@"Mid-Manhattan Branch"
inCity:@"Ne
…and the Service would know what I mean.
Lately I've been running into situations like the above pretty frequently. One case is when I'm writing a method comment:
/*!
* @method putBook:inSection:ofLibrary:inCity:
* @discussion Blah blah blah...
*/
Another case is when I'm studying someone else's code and I'm taking notes about how a group of classes interact:
Upon receiving the XXBookDidGetClassified notification, we send a putBook:inSection:ofLibrary:inCity: message to the Librarian object and commit the change to the database.
I can imagine other uses as well — for example, selecting a fragment of code in a cocoa-dev email and pasting the method name into either Xcode's or AppKiDo's search field.
It would be nice if code completion could help here, but code completion in comments only completes the first word in a method name, without the colon — i.e., "putBook" in the example above. (I just filed rdar://7197881 about this.) Also, code completion only works in Xcode, and I use TextWrangler to edit notes that are not in the code.
Another way to do this would be to click anywhere in the method name and bring up the Refactoring window, which has the method name already selected and ready to copy to the pasteboard. But this adds two keystrokes — one to open the Refactoring window and one to close it — plus a moment's delay before the window appears. And this only works if I'm looking at the code in Xcode.
Come to think of it, if Xcode can populate that field in the Refactoring window, it can just as easily put the method name into my pasteboard. It could provide this functionality in a Service as well, so I'd be able to use it when I select code in a cocoa-dev message, for example, or on a web page. I just filed rdar://7198039 asking for this.