Home Download Buy Blog Forum Support

Mini Plugin: Rosetta Code Paster - Online snippet repository

Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby trishume on Thu Jan 26, 2012 4:09 pm

Simple sublime text plugin I made. It allows you to quickly insert snippets from rosetta code: http://rosettacode.org/

It is useful for saving time writing algorithms and common tasks. And because of the site's goal of having many languages, it has many snippets even for uncommon languages like Icon and J.

Example

Need to factor primes in scala?

  • Create a new file and set language to scala. Or open an existing file.
  • Select "Rosetta Code" in the "tools" menu. Or use the command pallet.
  • Search for "prime" in the menu, select "prime decomposition"
  • A 33 line scala prime factorizer appears in the file!


What it does

When invoked, it detects the current file language and pops up a search menu of all the Rosetta Code tasks implemented in that language. When a task is selected it is inserted into the current document.

Github Page
https://github.com/trishume/Sublime-Rosetta-Get
trishume
 
Posts: 6
Joined: Thu Jan 26, 2012 3:59 pm

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby barbuk on Thu Jan 26, 2012 4:13 pm

Very nice idea !

I'm testing it right now
barbuk
 
Posts: 9
Joined: Wed Oct 26, 2011 8:03 am

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby barbuk on Thu Jan 26, 2012 4:27 pm

You just got your first issue on this github repos :p
barbuk
 
Posts: 9
Joined: Wed Oct 26, 2011 8:03 am

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby trishume on Thu Jan 26, 2012 4:38 pm

Pushed a commit that hopefully fixes the bug.

I'm amazed at how versatile it is. The simple formula of capitalizing the scope name matches almost perfectly with rosetta code so it should work for almost all sublime text languages.

I only had to spend two hours writing it. Partly because I took the rosetta code wiki parser off rosetta code: http://rosettacode.org/wiki/Category:Rosetta_Code_related

:D
trishume
 
Posts: 6
Joined: Thu Jan 26, 2012 3:59 pm

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby barbuk on Fri Jan 27, 2012 8:48 am

It's really a good idea :)

I have two problems :

to make it work with a debian system, you have to add
Code: Select all
import sys
sys.path.append("/usr/lib/python2.6/lib-dynload/")

to be able to use pyexpat.

A more accurate way to determine the current language is to get the syntax file used for the file :
Code: Select all
def getLang(view):
        scopes = view.settings().get('syntax')
        lang = scopes.split("/")[1]
        return lang

wich return the correct capitalisation (Python, PHP, HTML...)

Anyway, thanks for the plugin
barbuk
 
Posts: 9
Joined: Wed Oct 26, 2011 8:03 am

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby trishume on Fri Jan 27, 2012 1:48 pm

Pushed a commit with those fixes. Thanks! This is my first plugin so I just looked at other plugins and saw them using the scope.

It's also my first time using python so I don't know about platform compatibility.

I also fixed a bug where C++ wouldn't work because of the site uses the short form "cpp"
trishume
 
Posts: 6
Joined: Thu Jan 26, 2012 3:59 pm

Re: Mini Plugin: Rosetta Code Paster - Online snippet repository

Postby pod on Thu Feb 02, 2012 11:33 pm

Love it, thank you!
pod
 
Posts: 37
Joined: Sun Nov 07, 2010 3:32 am


Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests