Created
September 8, 2011 18:21
-
-
Save daveray/1204183 to your computer and use it in GitHub Desktop.
Async vimclojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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