Where to put event handler?

I’m a less experienced JS programmer, and I’m having a hard time filling in the blanks in the manual. I need to add an event handler:
cm.on(“cursorActivity”, onCursorActivity);

This works fine when I add it into any context which contains a copy of cm, such as CodeMirror.defineOption(). But I don’t need to define an option. I’m using it for linting, so I want to put it in javascript-lint.js. CodeMirror.defineInitHook() looked good, but it doesn’t supply cm. It works when I add to lint.js, but I don’t think I’m supposed to mess with that one.

I’m sure I’m missing something obvious! Thanks for your help, and for a truly wonderful product!

At some point, you are creating an editor instance by calling CodeMirror or CodeMirror.fromTextArea. You can call on on the return value from that call. Or in an init hook, which most certainly are passed an editor instance as well.

Oh, that’s what the editor instance is for :slight_smile: I think I get it. Thank you! That is working now.

And I’ve got

CodeMirror.defineInitHook(function(cm) {
cm.on(“cursorActivity”, onCursorActivity);

…Which also works when placed above my main CM setup call. So I’m on my way! Thanks again for answering my newbie questions :slight_smile: