main: Make callback splits work with Python3

This commit is contained in:
Tomas Babej 2016-12-16 14:54:43 +01:00
parent df2b5f87e6
commit 183f40b99d

View file

@ -1,4 +1,5 @@
from __future__ import print_function from __future__ import print_function
import base64
import re import re
import os import os
import pickle import pickle
@ -387,14 +388,22 @@ class CallbackSplitMixin(object):
# We can't save the current instance in vim variable # We can't save the current instance in vim variable
# so save the pickled version # so save the pickled version
if six.PY2:
vim.current.buffer.vars['taskwiki_callback'] = pickle.dumps(self) vim.current.buffer.vars['taskwiki_callback'] = pickle.dumps(self)
else:
vim.current.buffer.vars['taskwiki_callback'] = base64.encodebytes(
bytes(pickle.dumps(self))
).decode()
# Remap <CR> to calling the callback and wiping the buffer # Remap <CR> to calling the callback and wiping the buffer
vim.command( vim.command(
"nnoremap <silent> <buffer> <enter> :" "nnoremap <silent> <buffer> <enter> :"
+ vim.vars['taskwiki_py'].decode() + + vim.vars['taskwiki_py'].decode() +
"callback = pickle.loads(" "callback = pickle.loads(" +
"vim.current.buffer.vars['taskwiki_callback']); " ( "base64.decodebytes("
"vim.current.buffer.vars['taskwiki_callback'])); "
if six.PY3 else
"vim.current.buffer.vars['taskwiki_callback']); " ) +
"callback.callback(); " "callback.callback(); "
"vim.command('bwipe') <CR>" "vim.command('bwipe') <CR>"
) )