Skip to content

Instantly share code, notes, and snippets.

@daveray
Created September 8, 2011 18:21
Show Gist options
  • Save daveray/1204183 to your computer and use it in GitHub Desktop.
Save daveray/1204183 to your computer and use it in GitHub Desktop.
Async vimclojure
(ns vim.core)
(defn async* [f]
(future
(let [result (with-out-str
(try
(println (f))
(catch Exception e
(.printStackTrace e
(java.io.PrintWriter. *out*))))) ]
(javax.swing.SwingUtilities/invokeLater
(fn []
(doto (javax.swing.JDialog.)
(.setTitle "Vim Async Result")
(.setContentPane
(javax.swing.JScrollPane.
(doto (javax.swing.JTextArea.)
(.setText result))))
(.setSize 640 480)
(.setModal true)
(.setVisible true)))))))
(defmacro async [& body]
`(async* (fn [] ~@body)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Usage: in a temp buffer ...
(use 'vim.core :reload)
(async
(doseq [t (range 0 100)]
(Thread/sleep 15)
(println t))
"DONE!")
; ... and then ,ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment