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.
13 responses so far ↓
Great Job! Very useful! Pyhton mode is still missing though :-]
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
Here it is with python mode enabled: http://pastie.caboo.se/paste/136134
@Sunu,
Good idea. It is now on the wiki at pastie.el.
Here’s a version with python mode and a function that lets you browse to the last paste.
http://pastie.caboo.se/paste/136194
Dan, Good call. I wonder if it makes sense to
pastie-browseautomatically at the end ofpastie-region?Hi and great work! Nice to see you post again!
Great, thanks!
I wonder how many copies of pastie.el is now on pastie – it’s a pretty obvious choice for trying itself out
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.
http://p.hagelb.org
Phil, Clever and simple.
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..
—- /myhome/jwlee/.emacs.d/lisp/web/pastie.el Fri Jul 11 15:31:16 2008
***************
“[&]”
(lambda (match)
(case (string-to-char match)
! (?< “ “>”)
! (?& “&”)))
body-raw))
(mode (pastie-language))
(url-request-method “POST”)
—- 51,59 ——
“[&]”
(lambda (match)
(case (string-to-char match)
! (? “>”)
! (?& “&”)))
body-raw))
(mode (pastie-language))
(url-request-method “POST”)
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.
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!
Leave a Comment