2
2
import logging
3
3
import sys
4
4
5
+ from ..api .common import SessionHook
6
+
7
+
5
8
logger = logging .getLogger (__name__ )
6
9
debug , warn = (logger .debug , logger .warn ,)
7
10
@@ -19,7 +22,7 @@ def __init__(self, nvim):
19
22
nvim .script_context = self .module
20
23
# it seems some plugins assume 'sys' is already imported, so do it now
21
24
exec ('import sys' , self .module .__dict__ )
22
- sys .modules ['vim' ] = nvim
25
+ sys .modules ['vim' ] = nvim . with_hook ( LegacyEvalHook ())
23
26
24
27
def python_execute (self , script ):
25
28
exec (script , self .module .__dict__ )
@@ -64,3 +67,16 @@ def python_do_range(self, start, stop, code):
64
67
65
68
def python_eval (self , expr ):
66
69
return eval (expr , self .module .__dict__ )
70
+
71
+
72
+ class LegacyEvalHook (SessionHook ):
73
+
74
+ """Injects legacy `vim.eval` behavior to a Nvim instance."""
75
+
76
+ def __init__ (self ):
77
+ super (LegacyEvalHook , self ).__init__ (from_nvim = self ._string_eval )
78
+
79
+ def _string_eval (self , obj , session , method , kind ):
80
+ if method == 'vim_eval' and isinstance (obj , (int , long , float )):
81
+ return str (obj )
82
+ return obj
0 commit comments