Skip to content

Instantly share code, notes, and snippets.

@Folcon
Created August 24, 2011 11:50
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Folcon/1167903 to your computer and use it in GitHub Desktop.
Save Folcon/1167903 to your computer and use it in GitHub Desktop.
Just a quick clipboard slip/slurp I put together because I didn't find anything similar, don't know if it's useful for anyone but found it invaluable when getting large strings being returned from the repl and sticking the result in an editor for more car
(defn get-clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp-clipboard []
(try
(.getTransferData (.getContents (get-clipboard) nil) (java.awt.datatransfer.DataFlavor/stringFlavor))
(catch java.lang.NullPointerException e nil)))
(defn spit-clipboard [text]
(.setContents (get-clipboard) (java.awt.datatransfer.StringSelection. text) nil))
@ordnungswidrig
Copy link

I'd rather do

(if-let [contents (.getContents (get-clipboard) nil)](.getTransferData contents %28java.awt.datatransfer.DataFlavor/stringFlavor%29)

@Folcon
Copy link
Author

Folcon commented Aug 26, 2011

good point, I suppose that is more idiomatic :). Hmm github seems to truncate descriptions after a while...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment