-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathPython.txt
132 lines (100 loc) · 4.53 KB
/
Python.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
*vital/Vim/Python.txt* Vim python/python3 compatible function
Maintainer: lambdalisue <[email protected]>
==============================================================================
CONTENTS *Vital.Vim.Python-contents*
INTRODUCTION |Vital.Vim.Python-introduction|
INTERFACE |Vital.Vim.Python-interface|
FUNCTIONS |Vital.Vim.Python-functions|
==============================================================================
INTRODUCTION *Vital.Vim.Python-introduction*
*Vital.Vim.Python* provides compatible functions of |python|, |pyfile|, and |pyeval|.
It automatically uses a correct function/command to execute a Python code/file.
>
let s:V = vital#{plugin-name}#new()
let s:P = s:V.import('Vim.Python')
" Check if Python is enabled
echo s:P.is_enabled()
" => 0 or 1, depends on +python/+python3
" Execute a Python file
execute s:P.exec_file('your/python/file.py')
" Execute a Python code
execute s:P.exec_code('print("Hello Python")')
" Evaluate a Python expression and return
echo s:P.eval_expr('1 + 1')
" => 2
" Get a current major version
echo s:P.get_major_version()
" => 0, 2, or 3, depends on +python/+python3
" Set a current major versioin
" NOTE: It only affects when a Vim was compiled with +python/+python3
call s:P.set_major_version(2)
echo s:P.eval_expr('print(sys.version_info.major)')
" => 2
call s:P.set_major_version(3)
echo s:P.eval_expr('print(sys.version_info.major)')
" => 3
<
==============================================================================
INTERFACE *Vital.Vim.Python-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Vim.Python-functions*
is_enabled() *Vital.Vim.Python.is_enabled()*
Return 1 if |Vital.Vim.Python.is_python2_enabled()| or
|Vital.Vim.Python.is_python3_enabled()| return 1.
is_python2_enabled() *Vital.Vim.Python.is_python2_enabled()*
Return 1 if |+python| and the following code exit without exceptions.
>
python 0
<
is_python3_enabled() *Vital.Vim.Python.is_python3_enabled()*
Return 1 if |+python3| and the following code exit without exceptions.
>
python3 0
<
get_major_version() *Vital.Vim.Python.get_major_version()*
Return 0, 2, or 3. Depends on |+python| and/or |+python3| features.
In case of |+python|/|+python3|, it returns a current major version.
In case of |+python|/-python3, it always returns 2.
In case of -python/|+python3|, it always returns 3.
In case of -python/-python3, it always returns 0.
set_major_version({version}) *Vital.Vim.Python.set_major_version()*
Set a current major version to {version}. It throws an exception if
the specified {version} is not available or an invalid {version} is
specified.
Calling this function does not make any sense in a Vim not compiled
with |+python|/|+python3|.
exec_file({path}[, {version}]) *Vital.Vim.Python.exec_file()*
Return an executable |String| to execute a Python file {path} (|String|)
with a specified {version} of Python.
It is required to be called with |execute| to enable script local or
function local variables in the Python (|python-eval|).
If {version} is 0 or omitted, it uses a version value returned from
|Vital.Vim.Python.get_major_version()|.
It throws an exception if the specified {version} is not available or
an invalid {version} is specified.
>
" Note: use 'execute' instead of 'call'
execute Python.exec_file('your/python/file.py')
<
exec_code({code}[, {version}]) *Vital.Vim.Python.exec_code()*
Return an executable |String| to execute a Python {code} (|String| or |List|)
with a specified {version} of Python.
It is required to be called with |execute| to enable script local or
function local variables in the Python (|python-eval|).
If {version} is 0 or omitted, it uses a version value returned
from |Vital.Vim.Python.get_major_version()|.
It throws an exception if the specified {version} is not available or
an invalid {version} is specified.
>
" Note: use 'execute' instead of 'call'
execute Python.exec_code('print("hello")')
<
eval_expr({expr}[, {version}]) *Vital.Vim.Python.eval_expr()*
Evaluate a Python {expr} (|String| or |List|) with a specified {version} of
Python and return the result. If {version} is 0 or omitted, it uses a
version value returned from |Vital.Vim.Python.get_major_version()|.
It throws an exception if the specified {version} is not available or
an invalid {version} is specified.
This function requires a Vim 7.3.601 or later.
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl