marijnh/CodeMirror — pull request #1261 by dandavison (2013-02-18 05:40:13+00:00)
Title: Emacs kill word/line handlers

### What

With the emacs keymap active, Ctrl-K (`killLine`) should kill to the end of the line (it does), and the killed text should be added to the kill ring so that a subsequent Ctrl-Y replaces the killed text (this was not happening prior to this commit.) Similarly, Alt-D (`delWordAfter`) and Alt-Backspace (`delWordBefore`) should add the killed text to the kill ring.

In order to make this happen, these commits do the following:

1. Modify the `killLine`, `delWordBefore`, and `delWordAfter` commands so that the killed text is returned. Previously these functions had no return value (side-effect only).
2. Add handlers to the emacs keymap. These behave like the handlers in the `emacsy` keymap, but in addition to killing the text, they add it to the kill ring.

### Testing

The Travis CI build passes. However, only `delWordAfter` is covered by the test suite currently. I tested the new functionality in an [ipython](https://github.com/ipython/ipython) notebook, which uses codemirror.

### Caveats

- In a real emacs, consecutive kill commands would append the killed text to the most recent kill ring entry. This would add considerable code complexity and no attempt is made to model that behavior here.

- I've added calls to `getRange` to determine the text that will be killed. `getRange` performs some of the same logic as the actual killing operation, so more efficient implementations exist in principle. I suspect that the user experience would be the same.