    "Ô" "J" ;;join
    })
 
-(def keymap
+(def ^:const default-keymap
+  {[nil "\t"] :paredit-indent-line
+   [nil "\n"] :paredit-newline})
+
+(def ^:const advanced-keymap
   {[nil "("] :paredit-open-round
    [nil ")"] :paredit-close-round
    [nil "["] :paredit-open-square

         key-text
         (str key-char)))]))

(defn key-event-handler [w buffer]
  (reify java.awt.event.KeyListener
    (keyReleased [this e] nil)
    (keyTyped [this e]
      (when (get #{"(" ")" "[" "]" "{" "}" "\""}
                 (str (.getKeyChar e)))
        (.consume e)))
    (keyPressed [this e]
      (when-not (.isConsumed e)
        (let [k (convert-key-event e)
              p (exec-paredit k w buffer)]
          (if p (.consume e) (format/exec-format k w)))))))

(defn input-method-event-handler [w buffer]
  (reify java.awt.event.InputMethodListener
    (inputMethodTextChanged [this e]
      (let [k (convert-input-method-event e)
            p (exec-paredit k w buffer)]
        (when p (.consume e))))))

(defn get-toggle-fn [w]
  (let [buffer (atom (paredit.parser/edit-buffer nil 0 -1 (s/value w)))
        key-listener (key-event-handler w buffer)
        input-listener (input-method-event-handler w buffer)]
    (fn [enable?]
      (if enable?
        (doto w
          (.addKeyListener key-listener)
          (.addInputMethodListener input-listener))
        (doto w
          (.removeKeyListener key-listener)
          (.removeInputMethodListener input-listener))))))

(defn paredit-widget [x]
  (let [w (if (string? x)
            (javax.swing.JTextArea. x)
            x)
        toggle-fn (get-toggle-fn w)]
    (toggle-fn true)
    w))

(defn test-paredit-widget []
  (s/native!)

   ["C" "9"] :paredit-backward-slurp-sexp
   ["C" "Close Bracket"] :paredit-forward-barf-sexp
   ["C" "Open Bracket"] :paredit-backward-barf-sexp
   ["M" "S"] :paredit-split-sexp
   ["M" "J"] :paredit-join-sexps
   ["M" "Right"] :paredit-expand-right
   ["M" "Left"] :paredit-expand-left})

(defn exec-paredit [k w buffer enable?]
  (when-let [cmd (or (default-keymap k)
                     (and @enable? (advanced-keymap k)))]
    (when *debug* (println [cmd k]))
    (let [result (exec-command cmd w buffer)]
      (when *debug* (println [cmd result]))
