0

I'm trying to figure out how to define a new text editing keystroke in Xcode 4.

To pick one example, Xcode does not appear to have the incredibly useful Emacs join-line function: delete the newline between the current line and the previous line AND ALSO delete any excess indentation whitespace at the beginning of the current line. ie, go in one keystroke from this:

    _measurement = 
        [DPLMeasurement newWithDate:measureDate inManagedObjectContext:[datastore managedObjectContext]];

to this:

    _measurement = [DPLMeasurement newWithDate:measureDate inManagedObjectContext:[datastore managedObjectContext]];

and NOT this:

    _measurement =         [DPLMeasurement newWithDate:measureDate inManagedObjectContext:[datastore managedObjectContext]];

I've seen instructions for user scripts that were apparently for Xcode 3. Does Xcode 4 no longer have anything like this?

c roald
  • 1,984
  • 1
  • 20
  • 30
  • are you talking about syntax aware indenting? – rishi May 11 '12 at 18:15
  • Well, sort of. Xcode does a lot of indenting for me, which is usually a good thing. But when I want to rejoin two lines I've just split, I have to manually delete all that whitespace also. Which is annoying. But I'm also interested in the general case -- there are other emacs-like text editing functions I'd like to define, and I do not know where to start in Xcode. – c roald May 11 '12 at 18:19
  • have you checked - Xcode - preferences - Text Editing - Identation, you can customise things here to behave as per your needs. – rishi May 11 '12 at 18:22
  • As far as I can tell, syntax-aware indenting inserts tabs for me when I type a newline, but it doesn't take the tabs out again when I type backspace. Unless I'm missing something? – c roald May 11 '12 at 18:24
  • No it works in both way, in prefer indent using option if you set tab. then i will work for newline as well as backspace. – rishi May 11 '12 at 18:25
  • I'm afraid it does not. Have you used the emacs join-line function? That's what I'm trying to replicate. – c roald May 11 '12 at 18:30
  • just give it a try first and see if it works for you as expected? – rishi May 11 '12 at 18:31
  • I went into Preferences>Text Editing>Indentation and set "Prefer Indent Using" to "Tabs". Then I went to a long line in my code and set my cursor in the middle, between two words. In sequence I typed return, cmd-left, backspace, and ended up with a rejoined line with a bunch of unwanted whitespace in the middle. If I skip the cmd-left, I instead have to type 9 backspaces before I get back to what I had before I typed return. (I do appreciate the help, but I don't think this is on the right track.) – c roald May 11 '12 at 18:35

1 Answers1

0

Halley's answer to this question does ALMOST what I want:

Xcode duplicate line

Add the following to the plist file, /Developer/Library/PrivateFrameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist:

Join Previous Line
String
moveToBeginningOfLine:, moveWordRight:, moveWordLeft:, deleteToBeginningOfLine:, deleteBackward:

I say "almost" because it joins the two lines, and deletes whitespace at the beginning of the second line, but if the first line doesn't end with a space it just rams them together and I have to type in the required space. It also deletes punctuation (like open brackets) if they happen to fall at the beginning of the line. So I'm not quite there.

Community
  • 1
  • 1
c roald
  • 1,984
  • 1
  • 20
  • 30