Yank to gist (and insert the url instead) in Emacs

On our distributed team, we use IRC constantly to stay in touch, and we often share gists of code/log file chunks/whatever. I use ERC as my IRC client, and use gist.el constantly to turn content in to gists. It works really well when the content you are trying to gistify is already in an emacs buffer. You can gist an entire buffer (or a region of the buffer), and have the url to the gist on your kill-ring (clipboard) ready to yank (paste). But I often have the need to create a gist of content I’ve copied from somewhere outside of emacs – from a terminal, a browser window, wherever.

Until tonight, my workflow was to paste into a temp buffer in emacs, call gist-buffer to create the gist, then yank the gist url into ERC. This evening, I wrote yank-to-gist to streamline that process a bit. It takes the top of the kill-ring, inserts it into a temp buffer, creates a gist from the buffer, then inserts the url for the new gist at the point.

It relies on gist.el being loaded. I Currently only have it bound in erc-mode to C-c y.