Skip to content

Commit

Permalink
Adding python3 support
Browse files Browse the repository at this point in the history
Fix #12
Fix #40

Auto-dispatch python interpreter according to which one (python2 or
python3) vim has been compiled with
  • Loading branch information
badouralix committed Sep 22, 2017
1 parent 6aee95e commit 63abf0f
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions plugin/latexlivepreview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@ if exists("g:loaded_vim_live_preview")
endif
let g:loaded_vim_live_preview = 1

" This plugin requires +python and mkdir features
" TODO: print an error message
if (!has('python') || !exists("*mkdir"))
" Check mkdir feature
if (!exists("*mkdir"))
echohl ErrorMsg
echo 'vim-llp: mkdir required'
echohl None
finish
endif

" Setup python
if (has('python3'))
let s:py_exe = 'python3'
elseif (has('python'))
let s:py_exe = 'python'
else
echohl ErrorMsg
echo 'vim-llp: python required'
echohl None
finish
endif

Expand All @@ -40,7 +54,7 @@ let s:previewer = ''
" Run a shell command in background
function! s:RunInBackground(cmd)

python << EEOOFF
execute s:py_exe "<< EEOOFF"

try:
subprocess.Popen(
Expand Down Expand Up @@ -77,8 +91,10 @@ endfunction
function! s:StartPreview(...)
let b:livepreview_buf_data = {}

let b:livepreview_buf_data['py_exe'] = s:py_exe

" Create a temp directory for current buffer
python << EEOOFF
execute s:py_exe "<< EEOOFF"
vim.command("let b:livepreview_buf_data['tmp_dir'] = '" +
tempfile.mkdtemp(prefix="vim-latex-live-preview-") + "'")
EEOOFF
Expand Down Expand Up @@ -198,7 +214,7 @@ endfunction
" Initialization code
function! s:Initialize()
let l:ret = 0
python << EEOOFF
execute s:py_exe "<< EEOOFF"
try:
import vim
import tempfile
Expand Down

0 comments on commit 63abf0f

Please sign in to comment.