Add documentation and improve misc.defined()
Move caret positioning into caret.js