From 259a672d0036b6d23199e7e36956448ab6c8da5f Mon Sep 17 00:00:00 2001 From: gnattishness Date: Fri, 31 Oct 2014 02:59:29 +1100 Subject: [PATCH 1/2] Enabled HPaste with vim featuring python3 --- autoload/vim2hs/hpaste.py3 | 31 +++++++++++++++++++++++++++++++ autoload/vim2hs/hpaste.vim | 11 +++++++++-- plugin/hpaste.vim | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 autoload/vim2hs/hpaste.py3 diff --git a/autoload/vim2hs/hpaste.py3 b/autoload/vim2hs/hpaste.py3 new file mode 100644 index 0000000..0f824e0 --- /dev/null +++ b/autoload/vim2hs/hpaste.py3 @@ -0,0 +1,31 @@ +def hpaste(): + import vim, sys, urllib.request, urllib.parse, urllib.error + + code = vim.eval('l:code') + + title = vim.eval('input("Title: ")') + if not title: + print('aborted') + return + + author = vim.eval('s:GetHPasteAuthor()') + language = vim.eval('&filetype') + channel = vim.eval('input("Channel: ")') + + data = urllib.parse.urlencode({ + 'title' : title, + 'author' : author, + 'language' : language, + 'channel' : channel, + 'paste' : code, + 'email' : '' + }) + + try: + res = urllib.request.urlopen('http://lpaste.net/new', data.encode()) + paste = res.geturl() + print(res.info()) + print('Created new paste {!s}'.format(paste)) + vim.command('call setreg("+", {!r})'.format(paste)) + finally: + res.close() diff --git a/autoload/vim2hs/hpaste.vim b/autoload/vim2hs/hpaste.vim index 30207df..faca7d6 100644 --- a/autoload/vim2hs/hpaste.vim +++ b/autoload/vim2hs/hpaste.vim @@ -1,5 +1,7 @@ -if has('python') +if has('python') pyfile :p:h/hpaste.py +elseif has('python3') + py3file :p:h/hpaste3.py endif function! s:GetHPasteAuthor() " {{{ @@ -13,6 +15,11 @@ endfunction " }}} function! vim2hs#hpaste#hpaste(line1, line2) " {{{ let l:code = join(getline(a:line1, a:line2), "\n") - python hpaste() + if has('python') + python hpaste() + elseif has('python3') + python3 hpaste() + endif + endfunction " }}} diff --git a/plugin/hpaste.vim b/plugin/hpaste.vim index bda98eb..694d290 100644 --- a/plugin/hpaste.vim +++ b/plugin/hpaste.vim @@ -1,4 +1,4 @@ -if has('python') +if has('python') || has('python3') command! -range=% LPaste call vim2hs#hpaste#hpaste(, ) command! -range=% HPaste call vim2hs#hpaste#hpaste(, ) endif From 6875abbfa3afa2891cdde7be043d6ebe23d35282 Mon Sep 17 00:00:00 2001 From: gnattishness Date: Fri, 31 Oct 2014 03:03:07 +1100 Subject: [PATCH 2/2] Typo --- autoload/vim2hs/hpaste.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vim2hs/hpaste.vim b/autoload/vim2hs/hpaste.vim index faca7d6..c480af2 100644 --- a/autoload/vim2hs/hpaste.vim +++ b/autoload/vim2hs/hpaste.vim @@ -1,7 +1,7 @@ if has('python') pyfile :p:h/hpaste.py elseif has('python3') - py3file :p:h/hpaste3.py + py3file :p:h/hpaste.py3 endif function! s:GetHPasteAuthor() " {{{