From 8af81c820e9487aa5c9d4cf43504764855979ef1 Mon Sep 17 00:00:00 2001 From: Uldis Sturms Date: Mon, 24 Feb 2020 11:27:08 +0000 Subject: [PATCH] feat: support both Python2 and Python3 --- plugin/image.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/image.vim b/plugin/image.vim index 16fb80d..e488d47 100644 --- a/plugin/image.vim +++ b/plugin/image.vim @@ -1,6 +1,6 @@ command! -nargs=0 Image call DisplayImage() -if !has("python") +if !has("pythonx") echo "image.vim requires python support" finish endif @@ -9,11 +9,19 @@ au BufRead *.png,*.jpg,*.jpeg :call DisplayImage() function! DisplayImage() set nowrap -python << EOF + +pyx << EOF from __future__ import division import vim from PIL import Image +try: + # Python 2 + xrange +except NameError: + # Python 3, xrange is now named range + xrange = range + def getAsciiImage(imageFile, maxWidth, maxHeight): try: img = Image.open(imageFile) @@ -63,7 +71,7 @@ def getAsciiImage(imageFile, maxWidth, maxHeight): vim.current.buffer.append(asciiImage) return asciiImage - + vim.command("let imagefile = expand('%:p')") imagefile = vim.eval("imagefile")