       (-> t (insert ins-str) (shift-offset offset-shift)))
     (-> t (insert (str o)))))
   
+(defn close-balanced
+  [[o c] {:keys [text offset length] :as t} 
+   chars-with-no-space-before chars-with-no-space-after]
+  #_(prn "t:" t)
+  (-> t (insert (str c)))
+  #_(if (in-code? text offset)
+    (let [add-pre-space? (not (contains? chars-with-no-space-before 
+                                         (previous-char t)))
+          add-post-space? (not (contains? chars-with-no-space-after 
+                                          (next-char t)))
+          ins-str (str (if add-pre-space? " " "")
+                       (str o c)
+                       (if add-post-space? " " ""))
+          offset-shift (if add-post-space? -2 -1)]
+      #_(prn "ins-str:" ins-str)
+      (-> t (insert ins-str) (shift-offset offset-shift)))
+    (-> t (insert (str o)))))
 
 (defmethod paredit 
   :paredit-open-round

    (conj (into *real-spaces* *open-brackets*) \#) ; add # for not inserting space before a set
    (into *extended-spaces* *close-brackets*)))
    
(defn test-command [title-prefix command]
  (testing (str title-prefix " " (second command) " (\"" (first command) "\")")
    (doseq [[input expected] (get command 2)]

                   "(a,|)" "(a, [|])"
                   "\\| " "\\[| "
                   "\\\\| " "\\\\ [|] "}]
      ["]"         :paredit-close-square
                  {#_"(define-key keymap [frob|  ] 'frobnicate)"
                   #_"(define-key keymap [frob]| 'frobnicate)"
                   "; [Bar.|" "; [Bar.]|"
                   "  \"Hello,| world!\" foo" "  \"Hello,]| world!\" foo"
                   "  \"Hello,| world!" "  \"Hello,]| world!"
                   "foo \\|" "foo \\]|"}]
      ["{"         :paredit-open-curly ; this command does not exist in paredit AFAIK
                 {"(a b |c d)"  "(a b {|} c d)"
                  "(foo \"bar |baz\" quux)" "(foo \"bar {|baz\" quux)"}
