M-x all-things-emacs

Fixing Pastie for Emacs

January 7th, 2008 by Rob Christie · 92 Comments

Pastie Icon Recently, I have been doing more remote pair programming at my day job, and I was copying some code snippets into pastie. Pastie is a site that allows you to share code snippets with nice syntax highlighting. One thing led to another, and next I was searching for emacs integration with pastie. I found it here, but unfortunately the lisp package no longer seemed to work. It turned out that the package just needed to support a minor change to the pastie API. I have fixed it, and added support for sniffing more of the emacs modes associated with Ruby on Rails and java. Here is the updated version of pastie.el. (Note: After publishing I added it to the emacs wiki based on a user’s suggestion: pastie.el). The package has the following functions:

pastie-buffer – Posts the current buffer as a new paste at pastie.caboo.se.
pastie-region – Posts the selected region as a new paste at pastie.caboo.se.
pastie-get – Fetches the contents of a paste from pastie.caboo.se into a new buffer.

Tags: misc · rails · ruby

92 responses so far ↓

  • 1 Suno // Jan 7, 2008 at 9:01 am

    Great Job! Very useful! Pyhton mode is still missing though :-]

  • 2 Suno // Jan 7, 2008 at 9:06 am

    me again … I thought it might be a great idea if you create a “pastie” page at emacswiki.org so pastie might thrive since others might add code etc.

    Tia, Suno :-)

  • 3 Tiago // Jan 7, 2008 at 2:39 pm

    Here it is with python mode enabled: http://pastie.caboo.se/paste/136134

  • 4 Rob Christie // Jan 7, 2008 at 4:40 pm


    Good idea. It is now on the wiki at pastie.el.

  • 5 Dan McKinley // Jan 7, 2008 at 5:15 pm

    Here’s a version with python mode and a function that lets you browse to the last paste.


  • 6 Ryan McGeary // Jan 7, 2008 at 6:01 pm

    Dan, Good call. I wonder if it makes sense to pastie-browse automatically at the end of pastie-region?

  • 7 Johan Andersson // Jan 11, 2008 at 8:00 am

    Hi and great work! Nice to see you post again!

  • 8 Jacob Tjoernholm // Feb 7, 2008 at 2:43 pm

    Great, thanks!

    I wonder how many copies of pastie.el is now on pastie – it’s a pretty obvious choice for trying itself out 😉

  • 9 Phil // Apr 5, 2008 at 11:46 pm

    I’ve just coded up a similar package (though much, much less code) called SCPaste that leverages Emacs’ font-lock so it knows how to syntax highlight everything that Emacs supports.


  • 10 Ryan McGeary // Apr 6, 2008 at 3:53 am

    Phil, Clever and simple.

  • 11 Joonhwan // Jul 14, 2008 at 6:07 am

    I’m not that good at html/css-thing, but when I tried to upload my c++ region using pastie.*region function, error occured, and figured out that pastie.el seemed to convert ‘>’, ‘<’, or ‘&’ sign incorrectly.
    Does it have to convert them into “>”, “<”, or “amp;” respectively?.

    I did..

    • /tmp/ediff25948Iqi Mon Jul 14 15:07:08 2008

    —- /myhome/jwlee/.emacs.d/lisp/web/pastie.el Fri Jul 11 15:31:16 2008

    • 51,59 ****

    (lambda (match)
    (case (string-to-char match)
    ! (?< “ “>”)
    ! (?& “&”)))
    (mode (pastie-language))
    (url-request-method “POST”)
    —- 51,59 ——
    (lambda (match)
    (case (string-to-char match)
    ! (? “>”)
    ! (?& “&”)))
    (mode (pastie-language))
    (url-request-method “POST”)

  • 12 Joonhwan // Jul 14, 2008 at 6:12 am

    Wired. I donwloaded pastie.el from http://www.emacswiki.org/cgi-bin/wiki/pastie.el. After leaving a comment on this site(see above comment), I also found that special characters notations (greater than, less than, and ampersand..) are automatically turned back their corresponding signs.

    Emacswiki might have a bug in elisp code uploading feature.

    If you download a pastie.el from above link, please check around Line54~57 and correct code so that it can convert specical characters into proper xml/html notation.

  • 13 Ben Atkin // Aug 4, 2008 at 9:37 am

    This is good stuff. It is one of two libraries I’ve added to my emacs setup today. The other one was twit.el, a twitter interface for emacs.

    It’s really nice to be able to quickly put code up on pastie, start composing a twitter update, and yank the pastie URL from the kill ring to put a link to the code in the twitter update.

    I think the library would lose a lot of its charm if by default it browsed automatically after pastie-region. It’s just not necessary most of the time. If you get a URL with a number, chances are it posted properly. The only thing that might have been screwed up is the syntax highlighting type. Please keep this part of the utility the way it is.

    Thanks for updating this so it works!

  • 14 Chao // Dec 1, 2010 at 3:14 am

    Upon submission I get…

    Search failed: “^Status: \\([0-S9]+.*\\)”

    Seems to be happening in pastie-retrieve on line 127

  • 15 Josiah // Feb 12, 2011 at 3:04 pm

    I am getting the same error Chao is. Hopefully a fix is forthcoming. :)

  • 16 Rob Christie // Feb 12, 2011 at 5:17 pm


    Sorry about the error. I have actually switched over to gist.el,https://github.com/defunkt/gist.el, for handling code snippets. I would recommend using it.