Home Download Buy Blog Forum Support

PasteBin

PasteBin

Postby Xikeon on Tue Mar 02, 2010 10:06 am

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.

http://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.
Xikeon
 
Posts: 18
Joined: Fri Feb 26, 2010 5:30 pm

Re: PasteBin

Postby ViViDboarder on Wed Mar 23, 2011 3:20 pm

Does this work with Sublime 2?
ViViDboarder
 
Posts: 4
Joined: Wed Mar 23, 2011 2:55 pm

Re: PasteBin

Postby ehamiter on Fri Jun 10, 2011 8:06 pm

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
Code: Select all
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[b:]
        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
Code: Select all
{ "keys": ["alt+shift+p"], "command": "upload_view" }
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: PasteBin

Postby iamntz on Sat Jun 11, 2011 9:27 am

Works great, thanks.
iamntz
 
Posts: 896
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: PasteBin

Postby aashish108 on Sat Jul 16, 2011 3:38 pm

Can this upload to your personal pastebin?
aashish108
 
Posts: 1
Joined: Sat Jul 16, 2011 3:26 pm

Re: PasteBin

Postby nobleach on Wed Aug 17, 2011 5:46 pm

I upgraded to 2101 today. This stopped working. I get "Something went wrong" ERROR: Invalid file format.
nobleach
 
Posts: 48
Joined: Thu Jun 23, 2011 4:14 pm

Re: PasteBin

Postby nobleach on Wed Aug 17, 2011 6:26 pm

nobleach wrote:I upgraded to 2101 today. This stopped working. I get "Something went wrong" ERROR: Invalid file format.


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

Code: Select all
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[b:]
        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()
nobleach
 
Posts: 48
Joined: Thu Jun 23, 2011 4:14 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 6 guests