diff options
| author | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
|---|---|---|
| committer | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
| commit | ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f (patch) | |
| tree | 92de2079e80f5f289dd87a54af123cb7d90c3058 /scripts/vimpatch.lua | |
| parent | 78bc52ea5397c092d01cd08296fe1dc85d998329 (diff) | |
| parent | ef4feab0e75be19c5f41d70a001db980b72090f5 (diff) | |
| download | rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.gz rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.bz2 rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.zip  | |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'scripts/vimpatch.lua')
| -rwxr-xr-x | scripts/vimpatch.lua | 67 | 
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/vimpatch.lua b/scripts/vimpatch.lua new file mode 100755 index 0000000000..0924f3d718 --- /dev/null +++ b/scripts/vimpatch.lua @@ -0,0 +1,67 @@ +--  Updates version.c list of applied Vim patches. +-- +--  Usage: +--    VIM_SOURCE_DIR=~/neovim/.vim-src/ nvim -i NONE -u NONE --headless +'luafile ./scripts/vimpatch.lua' +q + +local nvim = vim.api + +local function pprint(o) +  print(nvim.nvim_call_function('string', { o })) +end + +local function systemlist(...) +  local rv = nvim.nvim_call_function('systemlist', ...) +  local err = nvim.nvim_get_vvar('shell_error') +  local args_str = nvim.nvim_call_function('string', ...) +  if 0 ~= err then +    error('command failed: '..args_str) +  end +  return rv +end + +local function vimpatch_sh_list_numbers() +  return systemlist( { { 'bash', '-c', 'scripts/vim-patch.sh -M', } } ) +end + +-- Generates the lines to be inserted into the src/version.c +-- `included_patches[]` definition. +local function gen_version_c_lines() +  -- Set of merged Vim 8.0.zzzz patch numbers. +  local merged_patch_numbers = {} +  local highest = 0 +  for _, n in ipairs(vimpatch_sh_list_numbers()) do +    if n then +      merged_patch_numbers[tonumber(n)] = true +      highest = math.max(highest, n) +    end +  end + +  local lines = {} +  for i = highest, 0, -1 do +    local is_merged = (nil ~= merged_patch_numbers[i]) +    if is_merged then +      table.insert(lines, string.format('  %s,', i)) +    else +      table.insert(lines, string.format('  // %s,', i)) +    end +  end + +  return lines +end + +local function patch_version_c() +  local lines = gen_version_c_lines() + +  nvim.nvim_command('silent noswapfile noautocmd edit src/nvim/version.c') +  nvim.nvim_command('/static const int included_patches') +  -- Delete the existing lines. +  nvim.nvim_command('silent normal! j0d/};\rk') +  -- Insert the lines. +  nvim.nvim_call_function('append', { +      nvim.nvim_eval('line(".")'), +      lines, +    }) +  nvim.nvim_command('silent write') +end + +patch_version_c()  | 
