Skip to content

Commit 67d2e5b

Browse files
committed
Merge branch 'vim'
Conflicts: src/auto/configure src/if_python.c
2 parents 1d6e44c + a4341a3 commit 67d2e5b

File tree

27 files changed

+1133
-354
lines changed

27 files changed

+1133
-354
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ gvimext.lib
4444
*.mo
4545
*.swp
4646
*~
47+
*.pyc
4748
src/po/vim.pot
4849

4950
# Generated by "make test"

.hgtags

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,3 +2493,15 @@ bc3f4804cf470cec5773d8842743efb760f69102 v7-3-1153
24932493
6419ee8098c80f0418081c73b790b09c61f13c3a v7-3-1154
24942494
bf1e6326df1104cabc04b8490f9456dbda901fd2 v7-3-1155
24952495
8c4324e6f4779ee316361511ff783f6344750be9 v7-3-1156
2496+
2f1ee97f5f23a5f9e1c572ed4afb50fb79ce7a35 v7-3-1157
2497+
46077370bc605815f5e41cbfc925120a913acbaa v7-3-1158
2498+
208a6c04e6b8221c1f5187391d86c5b57e61445b v7-3-1159
2499+
60301d4d16827a961019d72a78e811f41326c680 v7-3-1160
2500+
ff393592644960783e9a1c7c7959a8cbb0954673 v7-3-1161
2501+
b8eabb6a96871321bec8526fa04ba1ff1a96780e v7-3-1162
2502+
70b1178dec7919120632cdeee6056e38108356a7 v7-3-1163
2503+
4db0bf9f1b44d1f0d42a1863732dfaef73c9971d v7-3-1164
2504+
05b8436873d48055cbd24f043548092755d77be7 v7-3-1165
2505+
d59ff2114733a526847ea38d093897f496f73ffc v7-3-1166
2506+
81dedcd648216d6b3fc6b967368fef23d8ee1154 v7-3-1167
2507+
ed47632fd1498d50e31ab5b30aac403de3db2496 v7-3-1168

Filelist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ SRC_ALL = \
8484
src/testdir/test49.vim \
8585
src/testdir/test60.vim \
8686
src/testdir/test83-tags? \
87+
src/testdir/python2/*.py \
88+
src/testdir/python3/*.py \
89+
src/testdir/pythonx/*.py \
8790
src/proto.h \
8891
src/proto/blowfish.pro \
8992
src/proto/buffer.pro \

runtime/doc/eval.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,8 @@ repeat( {expr}, {count}) String repeat {expr} {count} times
19061906
resolve( {filename}) String get filename a shortcut points to
19071907
reverse( {list}) List reverse {list} in-place
19081908
round( {expr}) Float round off {expr}
1909+
screenattr( {row}, {col}) Number attribute at screen position
1910+
screenchar( {row}, {col}) Number character at screen position
19091911
screencol() Number current cursor column
19101912
screenrow() Number current cursor row
19111913
search( {pattern} [, {flags} [, {stopline} [, {timeout}]]])
@@ -4890,6 +4892,21 @@ round({expr}) *round()*
48904892
< -5.0
48914893
{only available when compiled with the |+float| feature}
48924894

4895+
screenattr(row, col) *screenattr()*
4896+
Like screenchar(), but return the attribute. This is a rather
4897+
arbitrary number that can only be used to compare to the
4898+
attribute at other positions.
4899+
4900+
screenchar(row, col) *screenchar()*
4901+
The result is a Number, which is the character at position
4902+
[row, col] on the screen. This works for every possible
4903+
screen position, also status lines, window separators and the
4904+
command line. The top left position is row one, column one
4905+
The character excludes composing characters. For double-byte
4906+
encodings it may only be the first byte.
4907+
This is mainly to be used for testing.
4908+
Returns -1 when row or col is out of range.
4909+
48934910
screencol() *screencol()*
48944911
The result is a Number, which is the current screen column of
48954912
the cursor. The leftmost column has number 1.

runtime/doc/if_pyth.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ vim.strwidth(str) *python-strwidth*
180180
Like |strwidth()|: returns number of display cells str occupies, tab
181181
is counted as one cell.
182182

183+
vim.foreach_rtp(callable) *python-foreach_rtp*
184+
Call the given callable for each path in 'runtimepath' until either
185+
callable returns something but None, the exception is raised or there
186+
are no longer paths. If stopped in case callable returned non-None,
187+
vim.foreach_rtp function returns the value returned by callable.
188+
183189
vim.chdir(*args, **kwargs) *python-chdir*
184190
vim.fchdir(*args, **kwargs) *python-fchdir*
185191
Run os.chdir or os.fchdir, then all appropriate vim stuff.
@@ -300,6 +306,113 @@ Output from Python *python-output*
300306
supported, and may cause the program to crash. This should probably be
301307
fixed.
302308

309+
*python2-directory* *python3-directory* *pythonx-directory*
310+
Python 'runtimepath' handling *python-special-path*
311+
312+
In python vim.VIM_SPECIAL_PATH special directory is used as a replacement for
313+
the list of paths found in 'runtimepath': with this directory in sys.path and
314+
vim.path_hooks in sys.path_hooks python will try to load module from
315+
{rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for
316+
each {rtp} found in 'runtimepath'.
317+
318+
Implementation for python 2 is the following: usual importing code with empty
319+
lists in place of sys.path_hooks and sys.meta_path. Code is similar to the
320+
below, but written in C: >
321+
322+
# Assuming vim variable is already accessible and is set to the current
323+
# module
324+
import sys
325+
326+
def find_module(fullname):
327+
return vim
328+
329+
def load_module(fullname):
330+
# see vim._get_paths below
331+
new_path = _get_paths()
332+
333+
try: old_path = sys.path
334+
except: pass
335+
try: old_meta_path = sys.meta_path
336+
except: pass
337+
try: old_path_hooks = sys.path_hooks
338+
except: pass
339+
340+
sys.meta_path = []
341+
sys.path_hooks = sys.meta_path
342+
sys.path = new_path
343+
344+
try:
345+
exec ('import ' + fullname + ' as m') # No actual exec in C code
346+
return m
347+
finally:
348+
e = None
349+
try: sys.path = old_path
350+
except Exception as e: pass
351+
try: sys.meta_path = old_meta_path
352+
except Exception as e: pass
353+
try: sys.path_hooks = old_path_hooks
354+
except Exception as e: pass
355+
if e:
356+
raise e
357+
358+
def path_hook(d):
359+
if d == VIM_SPECIAL_PATH:
360+
return vim
361+
raise ImportError
362+
363+
sys.path_hooks.append(path_hook)
364+
365+
Implementation for python 3 is cleaner: code is similar to the following, but,
366+
again, written in C: >
367+
368+
from importlib.machinery import PathFinder
369+
import sys
370+
371+
class Finder(PathFinder):
372+
@classmethod
373+
def find_module(cls, fullname):
374+
# see vim._get_paths below
375+
new_path = _get_paths()
376+
377+
# super().find_module is also a class method
378+
# super() is not used because this variant is easier to implement
379+
# in C
380+
return PathFinder.find_module(fullname, new_path)
381+
382+
def path_hook(path):
383+
if path == VIM_SPECIAL_PATH:
384+
return Finder
385+
raise ImportError
386+
387+
sys.path_hooks.append(path_hook)
388+
389+
vim.VIM_SPECIAL_PATH *python-VIM_SPECIAL_PATH*
390+
String constant used in conjunction with vim path hook. If path hook
391+
installed by vim is requested to handle anything but path equal to
392+
vim.VIM_SPECIAL_PATH constant it raises ImportError. In the only other
393+
case it uses special loader.
394+
395+
Note: you must not use value of this constant directly, always use
396+
vim.VIM_SPECIAL_PATH object.
397+
398+
vim.load_module(name) *python-load_module*
399+
vim.find_module(...) *python-find_module*
400+
vim.path_hook(path) *python-path_hook*
401+
Methods or objects used to implement path loading as described above.
402+
You should not be using any of these directly except for vim.path_hook
403+
in case you need to do something with sys.meta_path. It is not
404+
guaranteed that any of the objects will exist in the future vim
405+
versions. In fact, load_module and find_module methods do not exists
406+
in python3.
407+
408+
vim._get_paths *python-_get_paths*
409+
Methods returning a list of paths which will be searched for by path
410+
hook. You should not rely on this method being present in future
411+
versions, but can use it for debugging.
412+
413+
It returns a list of {rtp}/python2 (or {rtp}/python3) and
414+
{rtp}/pythonx directories for each {rtp} in 'runtimepath'.
415+
303416
==============================================================================
304417
3. Buffer objects *python-buffer*
305418

0 commit comments

Comments
 (0)