vimpatch.lua 1.8 KB

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