Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created December 11, 2008 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chouser/34602 to your computer and use it in GitHub Desktop.
Save Chouser/34602 to your computer and use it in GitHub Desktop.
(defn bind-vec [state-map start-state [stroke & strokes] func force?]
(when-not force?
(let [old-val (get-in start-state [start-state stroke])]
(cond
(and (symbol? old-val) (not strokes))
(throw (Exception. "New binding would be eclipsed by existing binding"))
(and (not (symbol? old-var)) strokes)
(throw (Exception. "Existing binding would eclipse new binding"))
(and (not (symbol? old-var)) (not strokes))
(throw (Exception. "New binding would replace existing binding")))))
(if strokes
(let [new-state (gensym 'state)]
(recur (assoc-in state-map [start-state stroke] new-state)
new-state strokes func force?))
(assoc-in state-map [start-state stroke] func)))
; ...and then something like:
(defn register [] (alt nil [\" (append :register (alpha))]))
(defn num-arg [arg-name] (alt nil [(append arg-name (digit)) (num-arg arg-name)]))
(bind-keys :cmd [(num-arg :early-num) (register) \y
(alt (append :double \y) (movement) (visual-block))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment