                          (throw (str "no matching open delimiter for " ch))))
     :else stack))
 
-(defmethod push-char* ";"
-  [stack [x-pos ch]]
-  (cond
-    (in-escape? stack) (pop stack)
+(defmethod push-char ";"
+  [stack [x-pos ch]]
+  (cond
+    (escaping? stack) (pop stack)
     (in-code? stack) (conj stack [x-pos ch])
     :else stack))
 
-(defmethod push-char* "\n"
-  [stack [x-pos ch]]
-  (let [s0 (cond-> stack (in-escape? stack) pop)
+(defmethod push-char "\n"
+  [stack [x-pos ch]]
+  (let [s0 (cond-> stack (escaping? stack) pop)
         s1 (cond-> s0 (in-comment? s0) pop)]
     s1))
 
-(defmethod push-char* "\\"
-  [stack [x-pos ch]]
-  (cond
-    (in-escape? stack) (pop stack)
+(defmethod push-char "\\"
+  [stack [x-pos ch]]
+  (cond
+    (escaping? stack) (pop stack)
     :else (conj stack [x-pos ch])))
 
-(defmethod push-char* "\""
-  [stack [x-pos ch]]
-  (cond
-    (in-escape? stack) (pop stack)
+(defmethod push-char "\""
+  [stack [x-pos ch]]
+  (cond
+    (escaping? stack) (pop stack)
     (in-str? stack) (pop stack)
     :else (conj stack [x-pos ch])))
 
-(defmethod push-char* :default
-  [stack [x-pos ch]]
-  (cond
-    (in-escape? stack) (pop stack)
-    :else stack))
+(defmethod push-char :default
+  [stack [x-pos ch]]
+  (cond
+    (escaping? stack) (pop stack)
+    :else stack))
+
+;;------------------------------------------------------------------------
+;; Closing Delimiter inferencing
+;;------------------------------------------------------------------------
+
+;; Utilities
 
 (defn whitespace? [ch]
   (re-find #"[\s,]" ch))

        result (cond-> result should-close? (close-delims x-pos))

        ;; Update the delimiter stack with this character.
        result (update-in result [:stack] push-char* [x-pos ch])
        stack (:stack result)

        ;; Add potential insert point for closing delimiters if required.

      (derive "]" :close)
      (derive ")" :close)))

;;; We track delimiters by using a stack of [x-pos char] tuples.

;; Simple state tracking by checking last character.

(defn prev-ch [stack]
  (second (peek stack)))

;;; A delimiter stack can be in any of the following states:

(defn escaping?
  "Next character will be escaped."
  [stack]
  (= \\ (prev-ch stack)))

(defn in-str?
  "Next character is inside a string."
  [stack]
  (= \" (prev-ch stack)))

(defn in-comment?
  "Next character is inside a comment."
  [stack]
  (= \; (prev-ch stack)))

(defn in-code?
  "Next character is inside actual code."
  [stack]
  (and (not (in-str? stack))
       (not (in-comment? stack))))

(defn valid-closer?
  "Determine if the given closing delimiter can be used next, assuming we are inside code."
  [stack ch]
  (= (prev-ch stack) (matching-delim ch)))

;; Push operations

(defmulti push-char
  "Update the delimiter stack with the given character."
  (fn [stack [x-pos ch]] ch)
  :hierarchy #'char-hierarchy)

(defmethod push-char "\t"
  [stack [x-pos ch]]
  (cond
    (not (in-str? stack)) (throw (str "no tabs allowed outside strings"))
    :else stack))

(defmethod push-char :open
  [stack [x-pos ch]]
  (cond
    (escaping? stack) (pop stack)
    (in-code? stack) (conj stack [x-pos ch])
    :else stack))

(defmethod push-char :close
  [stack [x-pos ch]]
  (cond
    (escaping? stack) (pop stack)
    (in-code? stack) (if (valid-closer? stack ch)
                       (pop stack)
                       (do
