Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " Version: 1.0
- " Last Change: Sat, 14 May 2011 14:38:50 +0200
- " Maintainer: Michon van Dooren <michon1992+vim+publish gmail com>
- " Description: Vim plugin that allows you to paste/publish pieces of code to various sites.
- " Requires: +python
- " Commands:
- " :Publish <site> <arguments>
- " Site can be any valid publisher.
- " Arguments are site-specific.
- if has('python')
- command! -nargs=* -range=% Publish execute ':<line1>,<line2>python publish(<f-args>)'
- else
- command! -nargs=* -range=% Publish echo 'Only avaliable with +python support.'
- endif
- if has('python')
- python << EOF
- def getvar(varname, default):
- if int(vim.eval('exists("' + varname + '")')):
- return vim.eval(varname)
- elif default:
- return default
- else:
- raise Exception('The setting ' + varname + ' is required')
- def getglobalsetting(settingname, default = None):
- return getvar('g:Publish_' + settingname, default)
- def getsetting(settingname, default = None):
- return getvar('g:Publish_' + getsetting.sitename + '_' + settingname, default)
- def publish(site=None, *args):
- import urllib, imp, vim
- if not site:
- site = getglobalsetting('default_site', 'pastebin')
- getsetting.sitename = site
- fn = vim.eval('findfile("publishers/' + site + '.py", &rtp)')
- if not fn:
- raise Exception('no publisher exists for ' + site)
- with open(fn, 'r') as f:
- mod = imp.load_module('vim_publisher_' + site, f, fn, ('.py', 'U', 1))
- mod.getglobalsetting = getglobalsetting
- mod.getsetting = getsetting
- data = {
- 'code': '\n'.join(vim.current.range),
- 'lang': vim.eval('&filetype'),
- }
- if hasattr(mod, 'publish'):
- response = mod.publish(data, *args)
- elif hasattr(mod, 'process'):
- data = mod.process(data, *args)
- response = urllib.urlopen(mod.url, urllib.urlencode(data))
- else:
- raise Exception('The publisher for ' + site + ' seems to be broken')
- print(dir(response))
- print('Published to ' + response.read())
- EOF
- endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement