> I'm guessing there's no easy way to replace the definition of the deleteToEndOfParagraph: action with something else...
with DYLD_INSERT_LIBRARIES and method_exchangeImplementations (and maybe launchd to apply that DYLD_INSERT_LIBRARIES to everything?).
What you have to do is:
Implement a category message that does what you want (my_deleteToEndOfParagraph:).
Write a function that uses method_exchangeImplementations to replace deleteToEndOfParagraph: with my_deleteToEndOfParagraph:. deleteToEndOfParagraph: probably depends on class (NSTextView, NSTextField, WebView, etc.)
Create a shared library that uses your function as an initialization routine.
Inject that shared library into every app on the system.
It's somewhat difficult to do DYLD_INSERT_LIBRARIES right on OSX; it tends to subtly break various system components even if your binary doesn't do anything. However, SIMBL (http://www.culater.net/software/SIMBL/SIMBL.php) usually works fine. (On the (jailbroken) iPhone, you'd want MobileSubstrate (http://iphonedevwiki.net/index.php/MobileSubstrate), which does use DLYD_INSERT_LIBRARIES, where it causes few to no issues.)
Also, when replacing methods, it's better to do it like this, by storing the actual function pointer to the implementation: http://pastie.org/private/nbaaog7hptyzsytahpc5a — it makes "stacked" overrides (imagine an app tried to hook the same thing as well, you don't want that to cause issues) safer than renaming.
I'm always agog when an organization changes something beloved like key bindings. Qui bono? Someone who uses them is in the same boat as everyone else, muscle memory-wise. And someone who doesn't shouldn't care. And in either case, there should be enough people with facial hair (or female equivalent) who will block it because toying with user expectations is bad.
This is a tangent, but you want 'cui bono'[1]. 'Qui' is the nominative; the phrase is a double dative. (Not trying to be a jerk, but I figured you might want to know.)
You can easily flip the question around, though. Who benefits if OS X keeps this key binding? A few people who still use some arcane, 30-year-old text editor. And the rest of us are stuck wondering what the heck just happened when we accidentally press one of these shortcuts.
I respectfully submit that those who expect their OS to act like emacs as a matter of design rather than historical happenstance have plenty of other options out there. But I also understand that it's not fun to have the rug pulled out from under you in this way.
Everyone benefits by the possibility of learning useful shortcuts that work in stuff like safari text fields -- no matter the bindings, and no matter how old -- as long as Apple isn't adding more modern ones.
I don't use emacs, but i did learn ctrl-k, ctrl-y and some others.
Not using emacs here but regular user of bash, zsh and various readline-based tools (python, irb, mysql...), ^A ^E ^K ^Y are extremely useful, everyday, so it's a boon to have them working in every text box in the system.
> And the rest of us are stuck wondering what the heck just happened when we accidentally press one of these shortcuts.
This seems to imply you shouldn't have keyboard shortcuts at all. After all, the principle of least astonishment says that if you hit a key combination you didn't intend, nothing you didn't intend to happen should happen.
OS X should be agnostic about the software running on it. If you fix it for Emacs, then it should also be fixed for vi users and nano users, etc. some of which are mutually exclusive.
A company can fix a problem without sponsoring a product associated with the problem, just like a company can release a product for a competing platform.
He doesn't want the key binding to be Emacs-like he wants to go back to being the way it was before this random change, the way he had already gotten used to. That is, he wants it to be Apple-like again. (It happens that the old Apple way and the Emacs way coincide, which is probably what confused you.)
To clarify this a bit for non-Emacs users (as I saw a comment), the tl;dr version is that jwz wants Mac to maintain the Emacs key bindings that essentially amount to a specialized set of copy, cut and paste functions in text editing.
This is not because Apple particularly sponsors Emacs, but because historically, Mac key bindings and Emacs key bindings were the same for those functions. So it's the same (roughly) as finding that Command-A, Command-C and Command-V no longer work the way they used to.
Clarification of this for those interested in history: The original Mac did not have control keys; I guess NextStep had some Emacs bindings. When Mac OS and NextStep gave birth to Mac OS X, it was possible to keep both sets, as there could not be clashes. I am not sure those Emacs bindings 'officially' exist, though (the human interface guidelines mention the use of the control key for accessibility, but not for text editing)
I've used your documentation before, and it's amazingly useful. It's let me solve keyboard mapping issues in the least hacky way possible, especially when combined with KeyRemap4MacBook.
Did you follow his little demo? Let me see if I can explain it. "Killing" in Emacs-jargon is similar to cutting (ctrl/cmd X). Holding control and pressing "k" (C-k) deletes the text starting at the cursor (point) up until the end of the line, and puts that text in a buffer. It can be pasted (yanked) with C-y. In Emacs, killing multiple times without any other movement between kills appends each bit of text to the buffer. If you move between kills the buffer is wiped out, and subsequent kills put the killed text into a clean buffer.
I think he basically wants the kill buffer to be wiped out when you move between kills. His demo shows that in OSX text fields this is no longer the case, and at least on my machine running 10.6.something this is true. Emacs of course still behaves the way he wants.
That was actually a great explanation - to clarify a bit, yes, jwz doesn't have any issue with Emacs. But Mac used to use the same key bindings typical of Emacs, so jwz is miffed because for people comfortable in that environment, it's a pain to not be able to use the same shortcut for what amounts to copy, paste and cut.
I use ^K all the time, but somehow I didn't remember ^Y from my dalliance with Emacs a decade ago. And now that I know I want it, I can't have it. Crap.
TextEdit uses the default cocoa text widget. Both TextMate and Safari have reimplemented it. TextMate’s text widget is substantially more sophisticated, and Safari’s is mostly compatible except for a few annoying edge cases (it’s been a few years since I investigated; maybe some have been fixed).
Amusingly enough, Mail’s compose window uses WebKit for the content area. According to http://webkit.org/b/73888 the issue is specific to the WebKit2 layer that is currently used only by Safari.
you can change the keybindings to do multiple things, not just pick a single preset command like deleteToEndOfParagraph. not sure how much help that is though, since what he wants is kind of adding "truncate buffer" (or at least "setLastCommandFlag") to ALL other commands, rather than actually changing ctrl-k itself. this is not a problem with the deleteToEndOfParagraph implementation though, and i don't see how hacking that could help, since he wants something to happen after hitting arrows keys, typing, etc...
I believe they are actually emacs bindings. These bindings originates in emacs and were then used by readline. Software that uses readline then acquires these bindings, including bash, etc. So I wouldn't say that these are standard shell bindings that happen to be used by emacs, since they originated in emacs and shells happen to use them.
While I can understand the issue the change creates for the author, a nexus between the emacs interface and Apple's overall user experience philosophy would appear to be somewhat hard to find.
I nearly got a guy on the MPW Shell team fired -- I was egging him on to add keyboard macros to MPW (the Macintosh Programmer's Workshop), and he eventually did. They were powerful enough to emulate at least a top-level mostly Emacs environment.
Oh, the fur flew. Post-facto, managers piled on and tried to make the feature more Mac-like. It was fine as it stood. It was amusing to watch.
Also, Apple is one strange company. A friend who worked there as a contractor told me that there were two Perl teams there, working in different buildings. He organized a lunch so that the two teams could meet each other. After someone higher up found out, that was the end of his contract. Apparently there is so much secrecy that even teams working on bullshit HR apps (or the equivalent) can't even have lunch together.
Apple is a cult. Follow the rules or you go to hell.
Once it was in there, they didn't roll it back for some reason -- probably because a lot of folks secretly liked the feature and killing it would have been politically difficult. So the User Interface people (why you have these on a command shell is beyond me) were given a chance to pee in the feature for a bit, until they liked the flavor, and it shipped. My cow-orker got into some hot water.