Skip to content

Commit 22cc1a8

Browse files
committed
Isolate legacy vim.eval behavior on ScriptHost with a SessionHook
1 parent bc3332b commit 22cc1a8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

neovim/plugins/script_host.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import logging
33
import sys
44

5+
from ..api.common import SessionHook
6+
7+
58
logger = logging.getLogger(__name__)
69
debug, warn = (logger.debug, logger.warn,)
710

@@ -19,7 +22,7 @@ def __init__(self, nvim):
1922
nvim.script_context = self.module
2023
# it seems some plugins assume 'sys' is already imported, so do it now
2124
exec('import sys', self.module.__dict__)
22-
sys.modules['vim'] = nvim
25+
sys.modules['vim'] = nvim.with_hook(LegacyEvalHook())
2326

2427
def python_execute(self, script):
2528
exec(script, self.module.__dict__)
@@ -64,3 +67,16 @@ def python_do_range(self, start, stop, code):
6467

6568
def python_eval(self, expr):
6669
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

Comments
 (0)