Sublime Forum

Mini Plugin: Rosetta Code Paster - Online snippet repository

#1

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

0 Likes

#2

Very nice idea !

Iā€™m testing it right now

0 Likes

#3

You just got your first issue on this github repos :stuck_out_tongue:

0 Likes

#4

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

:smiley:

0 Likes

#5

Itā€™s really a good idea :smile:

I have two problems :

to make it work with a debian system, you have to add

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 :

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

0 Likes

#6

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ā€

0 Likes

#7

Love it, thank you!

0 Likes