    [nil "{"] :paredit-open-curly
    [nil "}"] :paredit-close-curly
    [nil "\b"] :paredit-backward-delete
-   [nil "\t"] :paredit-indent-line
    ["M" ")"] :paredit-close-round-and-newline
    [nil "\""] :paredit-doublequote
    [nil "DEL"] :paredit-forward-delete

   "Ô" "J" ;;join
   })

(def keymap
  {[nil "("] :paredit-open-round
   [nil ")"] :paredit-close-round
   [nil "["] :paredit-open-square

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

(defn key-event-handler [w buffer enable?]
  (reify java.awt.event.KeyListener
    (keyReleased [this e] nil)
    (keyTyped [this e]
      (when (and @enable?
                 (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 enable?)]
          (if p (.consume e) (format/exec-format k w)))))))

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

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

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

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