Skip to content

Commit

Permalink
Check Vim version through call to Vim's has() function (#1516)
Browse files Browse the repository at this point in the history
* Do not parse output of the `--version` option. The format is not documented.
  • Loading branch information
mymedia2 authored Feb 1, 2023
1 parent e99fdf1 commit 0ad238b
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions test/vim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,18 @@ class VimInterface(TempFileManager):
def __init__(self, vim_executable, name):
TempFileManager.__init__(self, name)
self._vim_executable = vim_executable
self._version = None

@property
def vim_executable(self):
return self._vim_executable

def has_version(self, major, minor, patchlevel):
if self._version is None:
output = subprocess.check_output([self._vim_executable, "--version"])

_major = 0
_minor = 0
_patch = 0
for line in output.decode("utf-8").split("\n"):
if line.startswith("VIM - Vi IMproved"):
_major, _minor = map(int, line.split()[4].split("."))
if line.startswith("Included patches:"):
_patch = int(line.split(":")[-1].strip().split("-")[-1])
self._version = (_major, _minor, _patch)

return self._version >= (major, minor, patchlevel)
cmd = [
self._vim_executable, "-e", "-c",
"if has('patch-%d.%d.%d') | quit | else | cquit | endif"
% (major, minor, patchlevel),
]
return not subprocess.call(cmd, stdout=subprocess.DEVNULL)

def get_buffer_data(self):
buffer_path = self.unique_name_temp(prefix="buffer_")
Expand Down

0 comments on commit 0ad238b

Please sign in to comment.