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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
commit c2b7a104b826b7ff9283d32cb95a039ddccde79b
Author: Shunsuke Shimizu <grafi@grafi.jp>
Date: Sun Jan 10 00:12:10 2016 -0800
Make the plugin to be compatible with Python 3.
Squashed commit of the following:
commit 0973c5179e504ffbd74a38d6557bb49fe3bf8b5d
Author: Hong Xu <hong@topbug.net>
Date: Sun Jan 10 00:11:11 2016 -0800
Some minor corrections
commit ca17e97e86bd6379bcf3782adfa200c1589cab69
Author: Shunsuke Shimizu <grafi@grafi.jp>
Date: Sun Jan 10 15:24:13 2016 +0900
vim 7.3 support by using `py[3]` command instead of `py[3]eval()` function
commit c51ae80ce0ca8fe24c014a7c2d54a85d604d3c88
Author: grafi <grafi@grafi.jp>
Date: Sun Jan 10 14:42:38 2016 +0900
use print_function on python2
commit 401a9486bba7528aa4d54b06b8ef3ace582829c9
Author: grafi <grafi@grafi.jp>
Date: Sun Jan 10 14:33:25 2016 +0900
assure that sys.path is cleaned
commit f3bf442429d9579a336a1bb8f98fee82710fbd1e
Author: grafi <grafi@grafi.jp>
Date: Sun Jan 10 14:22:45 2016 +0900
python3 style print
commit 8e059379328b23e4253f76cbd72d3ef484501d42
Author: Shunsuke Shimizu <grafi@grafi.jp>
Date: Sat Dec 26 07:54:49 2015 +0900
Support python3
diff --git a/plugin/editorconfig.py b/plugin/editorconfig.py
new file mode 100644
index 0000000..21ea9c7
--- /dev/null
+++ b/plugin/editorconfig.py
@@ -0,0 +1,42 @@
+from __future__ import print_function
+
+try:
+ try:
+ import vim
+ import sys
+ except:
+ vim.command('let l:ret = 2')
+ raise
+
+ try:
+ sys.path.insert(0, vim.eval('a:editorconfig_core_py_dir'))
+
+ import editorconfig
+ import editorconfig.exceptions as editorconfig_except
+ except:
+ vim.command('let l:ret = 3')
+ raise
+ finally:
+ del sys.path[0]
+
+ # `ec_` prefix is used in order to keep clean Python namespace
+ ec_data = {}
+
+ def ec_UseConfigFiles():
+ ec_data['filename'] = vim.eval("expand('%:p')")
+ ec_data['conf_file'] = ".editorconfig"
+
+ try:
+ ec_data['options'] = editorconfig.get_properties(ec_data['filename'])
+ except editorconfig_except.EditorConfigError as e:
+ if int(vim.eval('g:EditorConfig_verbose')) != 0:
+ print(str(e), file=sys.stderr)
+ vim.command('let l:ret = 1')
+ return
+
+ for key, value in ec_data['options'].items():
+ vim.command("let l:config['" + key.replace("'", "''") + "'] = " +
+ "'" + value.replace("'", "''") + "'")
+
+except:
+ pass
diff --git a/plugin/editorconfig.vim b/plugin/editorconfig.vim
index a21b103..af4f630 100644
--- a/plugin/editorconfig.vim
+++ b/plugin/editorconfig.vim
@@ -36,6 +36,8 @@ let g:loaded_EditorConfig = 1
let s:saved_cpo = &cpo
set cpo&vim
+let s:pyscript_path = expand('<sfile>:p:r') . '.py'
+
" variables {{{1
if !exists('g:EditorConfig_exec_path')
let g:EditorConfig_exec_path = ''
@@ -231,48 +233,23 @@ function! s:InitializePythonBuiltin(editorconfig_core_py_dir) " {{{2
let s:builtin_python_initialized = 1
- let l:ret = 0
-
- if !has('python')
+ if has('python')
+ let s:pyfile_cmd = 'pyfile'
+ let s:py_cmd = 'py'
+ elseif has('python3')
+ let s:pyfile_cmd = 'py3file'
+ let s:py_cmd = 'py3'
+ else
return 1
endif
- python << EEOOFF
-
-try:
- import vim
- import sys
-except:
- vim.command('let l:ret = 2')
-
-EEOOFF
-
- if l:ret != 0
- return l:ret
- endif
-
- python << EEOOFF
-
-try:
- sys.path.insert(0, vim.eval('a:editorconfig_core_py_dir'))
-
- import editorconfig
- import editorconfig.exceptions as editorconfig_except
-
-except:
- vim.command('let l:ret = 3')
-
-del sys.path[0]
-
-ec_data = {} # used in order to keep clean Python namespace
-
-EEOOFF
-
- if l:ret != 0
- return l:ret
- endif
+ let l:ret = 0
+ " The following line modifies l:ret. This is a bit confusing but
+ " unfortunately to be compatible with Vim 7.3, we cannot use pyeval. This
+ " should be changed in the future.
+ execute s:pyfile_cmd s:pyscript_path
- return 0
+ return l:ret
endfunction
" Do some initalization for the case that the user has specified core mode {{{1
@@ -388,41 +365,22 @@ augroup END
function! s:UseConfigFiles_Python_Builtin() " {{{2
" Use built-in python to run the python EditorConfig core
- let l:config = {}
- let l:ret = 0
-
" ignore buffers that do not have a file path associated
if empty(expand('%:p'))
return 0
endif
- python << EEOOFF
-
-ec_data['filename'] = vim.eval("expand('%:p')")
-ec_data['conf_file'] = ".editorconfig"
-
-try:
- ec_data['options'] = editorconfig.get_properties(ec_data['filename'])
-except editorconfig_except.EditorConfigError as e:
- if int(vim.eval('g:EditorConfig_verbose')) != 0:
- print >> sys.stderr, str(e)
- vim.command('let l:ret = 1')
+ let l:config = {}
-EEOOFF
+ let l:ret = 0
+ execute s:py_cmd 'ec_UseConfigFiles()'
if l:ret != 0
return l:ret
endif
- python << EEOOFF
-for key, value in ec_data['options'].items():
- vim.command("let l:config['" + key.replace("'", "''") + "'] = " +
- "'" + value.replace("'", "''") + "'")
-
-EEOOFF
-
call s:ApplyConfig(l:config)
- return 0
+ return l:ret
endfunction
function! s:UseConfigFiles_Python_External() " {{{2
|