vimpatch.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. -- Updates version.c list of applied Vim patches.
  2. --
  3. -- Usage:
  4. -- VIM_SOURCE_DIR=~/neovim/.vim-src/ nvim -V1 -es -i NONE +'luafile ./scripts/vimpatch.lua' +q
  5. local nvim = vim.api
  6. local function systemlist(...)
  7. local rv = nvim.nvim_call_function('systemlist', ...)
  8. local err = nvim.nvim_get_vvar('shell_error')
  9. local args_str = nvim.nvim_call_function('string', ...)
  10. if 0 ~= err then
  11. error('command failed: ' .. args_str)
  12. end
  13. return rv
  14. end
  15. local function vimpatch_sh_list_numbers()
  16. return systemlist({ { 'bash', '-c', 'scripts/vim-patch.sh -M' } })
  17. end
  18. -- Generates the lines to be inserted into the src/version.c
  19. -- `included_patches[]` definition.
  20. local function gen_version_c_lines()
  21. -- Set of merged Vim 8.1.zzzz patch numbers.
  22. local merged_patch_numbers = {}
  23. local highest = 0
  24. for _, n in ipairs(vimpatch_sh_list_numbers()) do
  25. n = tonumber(n)
  26. if n then
  27. merged_patch_numbers[n] = true
  28. highest = math.max(highest, n)
  29. end
  30. end
  31. local lines = {}
  32. for i = highest, 0, -1 do
  33. local is_merged = (nil ~= merged_patch_numbers[i])
  34. if is_merged then
  35. table.insert(lines, string.format(' %s,', i))
  36. else
  37. table.insert(lines, string.format(' // %s,', i))
  38. end
  39. end
  40. return lines
  41. end
  42. local function patch_version_c()
  43. local lines = gen_version_c_lines()
  44. nvim.nvim_command('silent noswapfile noautocmd edit src/nvim/version.c')
  45. nvim.nvim_command('/static const int included_patches')
  46. -- Delete the existing lines.
  47. nvim.nvim_command('silent normal! j0d/};\rk')
  48. -- Insert the lines.
  49. nvim.nvim_call_function('append', {
  50. nvim.nvim_eval('line(".")'),
  51. lines,
  52. })
  53. nvim.nvim_command('silent write')
  54. end
  55. patch_version_c()