Sublime Forum

PasteBin

#1

Hi,

I’m hereby putting up my PasteBin addon for download. It supports right syntax highlighting for most comment languages and will add more later on. Maybe somebody has a better check for this than I am doing right now? My first time working with python. (:

To upload to PasteBin press alt+shift+P. Selected lines will be highlighted on PasteBin.com.

bitbucket.org/xikeon/pastebin/wiki/Home

If you have any issues, please add them to bitbucket so I get notified and able to track issues and updates.

0 Likes

#2

Does this work with Sublime 2?

0 Likes

#3

Xikeon, hope you don’t mind, but I updated your plugin to work with ST2. Just a couple of changes in the API was preventing it from working.

PasteBin.py

import sublime, sublime_plugin, httplib, urllib, re

class UploadViewCommand( sublime_plugin.TextCommand ):
  def run( self, view ):
    try:
      s = re.findall(r'\bphp|html|css|xml|haml|python|js|java|css|c\+\+|cs|c\b', self.view.scope_name(0))[0]
      if s == 'js':
        s = 'javascript'
      if s == 'cs':
        s = 'csharp'
      if s == 'c++':
        s = 'cpp'
    except:
      s = 'other'

    c, v, i = self.view.substr(sublime.Region(0, self.view.size())), self.view.sel()[0], 0
    if v.begin() != v.end():
      for x in self.view.lines(v):
        b = x.begin()+i
        c = c:b] + '@@' + c**
        i = i + 2
        
    r, p = httplib.HTTPConnection('www.pastebin.com'), urllib.urlencode({'paste_name': 'Sublime Text 2 Editor', 'paste_code': c, 'paste_format': s})
    h = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain"}
    r.request("POST", "/api_public.php", p, h)
    g = r.getresponse()
    if g.status == 200:
      l = g.read()
      if l[0:5] == 'ERROR':
        sublime.status_message('Something went wrong:\n' + l)
      else:
        sublime.set_clipboard(l)
        sublime.status_message('Link has been copied to your clipboard')
    else:
      sublime.status_message('Something went wrong: ' + g.status, g.reason)
    r.close()

User Key Binding

{ "keys": "alt+shift+p"], "command": "upload_view" } **

0 Likes

#4

Works great, thanks.

0 Likes

#5

Can this upload to your personal pastebin?

0 Likes

#6

I upgraded to 2101 today. This stopped working. I get “Something went wrong” ERROR: Invalid file format.

0 Likes

#7

Here’s a fix if anyone else uses this cool plugin:

[code]import sublime, sublime_plugin, httplib, urllib, re

class UploadViewCommand( sublime_plugin.TextCommand ):
def run( self, view ):
try:
s = re.findall(r’\bphp|html|css|xml|haml|python|js|java|css|c++|cs|c\b’, self.view.scope_name(0))-1]
if s == ‘js’:
s = ‘javascript’
if s == ‘cs’:
s = ‘csharp’
if s == ‘c++’:
s = ‘cpp’
if s == ‘php’:
s = ‘php’
except:
s = ‘other’

c, v, i = self.view.substr(sublime.Region(0, self.view.size())), self.view.sel()[0], 0
if v.begin() != v.end():
  for x in self.view.lines(v):
    b = x.begin()+i
    c = c:b] + '@@' + c**
    i = i + 2

r, p = httplib.HTTPConnection('www.pastebin.com'), urllib.urlencode({'paste_name': 'Sublime Text 2 Editor', 'paste_code': c, 'paste_format': s})
h = {"Content-type": "application/x-www-form-urlencoded",
           "Accept": "text/plain"}
r.request("POST", "/api_public.php", p, h)
g = r.getresponse()
if g.status == 200:
  l = g.read()
  if l[0:5] == 'ERROR':
    sublime.status_message('Something went wrong:\n' + l  + ' filetype: ' + s)
  else:
    sublime.set_clipboard(l)
    sublime.status_message('Link has been copied to your clipboard')
else:
  sublime.status_message('Something went wrong: ' + g.status, g.reason)
r.close()[/code]**
0 Likes