vimpatch.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 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.0.zzzz patch numbers.
  22. local merged_patch_numbers = {}
  23. local highest = 0
  24. for _, n in ipairs(vimpatch_sh_list_numbers()) do
  25. if n then
  26. merged_patch_numbers[tonumber(n)] = true
  27. highest = math.max(highest, n)
  28. end
  29. end
  30. local lines = {}
  31. for i = highest, 0, -1 do
  32. local is_merged = (nil ~= merged_patch_numbers[i])
  33. if is_merged then
  34. table.insert(lines, string.format(' %s,', i))
  35. else
  36. table.insert(lines, string.format(' // %s,', i))
  37. end
  38. end
  39. return lines
  40. end
  41. local function patch_version_c()
  42. local lines = gen_version_c_lines()
  43. nvim.nvim_command('silent noswapfile noautocmd edit src/nvim/version.c')
  44. nvim.nvim_command('/static const int included_patches')
  45. -- Delete the existing lines.
  46. nvim.nvim_command('silent normal! j0d/};\rk')
  47. -- Insert the lines.
  48. nvim.nvim_call_function('append', {
  49. nvim.nvim_eval('line(".")'),
  50. lines,
  51. })
  52. nvim.nvim_command('silent write')
  53. end
  54. patch_version_c()