Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 640f06c

Browse files
authored
Merge pull request #77 from matthew-brett/allow-py23-choice
MRG: allow choice of Python version in vimrc
2 parents 4301e58 + 17b50f3 commit 640f06c

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

README.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,24 @@ Options
8989
-------
9090

9191
Set this option in your vimrc file to disable quickfix support::
92-
92+
9393
let g:pyflakes_use_quickfix = 0
9494

9595
The value is set to 1 by default.
9696

97+
Pyflakes can use Python 2 or Python 3 compiled into Vim. If you have both,
98+
you can ask Pyflakes to prefer one or the other, with this in your vimrc::
99+
100+
let g:pyflakes_prefer_python_version = 3
101+
102+
or::
103+
104+
let g:pyflakes_prefer_python_version = 2
105+
106+
Pyflakes will chose Python 2 by default, if you have both. If you prefer a
107+
version that you don't have, Pyflakes will quietly fall back to the version
108+
that you do have.
109+
97110
TODO
98111
----
99112
* signs_ support (show warning and error icons to left of the buffer area)

ftplugin/python/pyflakes.vim

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,32 @@ endif
2424
if !exists("b:did_python_init")
2525
let b:did_python_init = 0
2626

27+
if !has('python') && !has('python3')
28+
echoerr "Error: Requires Vim compiled with +python or +python3"
29+
finish
30+
endif
31+
" Default to Python 2
2732
if has('python')
33+
let py_cmd_ver = 'python'
34+
else
35+
let py_cmd_ver = 'python3'
36+
endif
37+
if exists('g:pyflakes_prefer_python_version')
38+
if g:pyflakes_prefer_python_version == 3 && has('python3')
39+
let py_cmd_ver = 'python3'
40+
elseif g:pyflakes_prefer_python_version == 2 && has('python')
41+
let py_cmd_ver = 'python'
42+
endif
43+
endif
44+
if py_cmd_ver == 'python'
2845
command! -nargs=1 Python python <args>
29-
elseif has('python3')
30-
command! -nargs=1 Python python3 <args>
3146
else
32-
echo "Error: Requires Vim compiled with +python or +python3"
33-
finish
47+
command! -nargs=1 Python python3 <args>
3448
endif
3549

36-
if !exists('g:pyflakes_use_quickfix')
37-
let g:pyflakes_use_quickfix = 1
38-
endif
39-
50+
if !exists('g:pyflakes_use_quickfix')
51+
let g:pyflakes_use_quickfix = 1
52+
endif
4053

4154
Python << EOF
4255
import vim

0 commit comments

Comments
 (0)