 
   key_emitter = new KeyEmitter
   do key_emitter.listen
-  keyhandler = new KeyHandler view, keyBindings
-  key_emitter.on 'keydown', keyhandler.handleKey.bind(keyhandler)
+  key_handler = new KeyHandler view, key_bindings
+  key_emitter.on 'keydown', key_handler.handleKey.bind(key_handler)
+
+  # expose globals, for debugging
+  window.view = view
+  window.key_handler = key_handler
+  window.key_emitter = key_emitter
+  window.key_bindings = key_bindings
 
   $(document).ready ->
     do view.hideSettings

  settings = new Settings data.store, {mainDiv: $('#settings'), keybindingsDiv: $('#keybindings')}
  do settings.loadRenderSettings

  keyBindings = new KeyBindings settings, {modebindingsDiv: $('#keybindings')}

  view = new View data, {
    bindings: keyBindings
    settings: settings
    mainDiv: $('#view'),
    settingsDiv: $('#settings')

                hotkey_settings = JSON.parse content
            catch e
                return view.showMessage "Failed to parse JSON: #{e}", {text_class: 'error'}
            err = key_bindings.apply_hotkey_settings hotkey_settings
            if err then return view.showMessage err, {text_class: 'error'}
            key_bindings.save_settings hotkey_settings
            key_bindings.renderModeTable view.mode # TODO: do this elsewhere?
            view.showMessage 'Loaded new hotkey settings!', {text_class: 'success'}

    $("#hotkeys_export").click () =>
        filename = 'vimflowy_hotkeys.json'
        content = JSON.stringify(key_bindings.hotkeys, null, 2)
        download_file filename, 'application/json', content
        view.showMessage "Downloaded hotkeys to #{filename}!", {text_class: 'success'}

    $("#hotkeys_default").click () =>
        do key_bindings.apply_default_hotkey_settings
        key_bindings.renderModeTable view.mode # TODO: do this elsewhere?
        view.showMessage "Loaded defaults!", {text_class: 'success'}

    $("#data_import").click () =>
