hadronized / hop.nvim

Neovim motions on speed!
Other
2.47k stars 137 forks source link

Replace charcol that is only supported in neovim 0.7 #336

Open firstmover opened 1 year ago

firstmover commented 1 year ago

This commit replaces Neovim's built-in function charcol with functions that is available >= 0.5. charcoal Neovim built-in function is introduced in Neovim 0.7 (see https://github.com/neovim/neovim/commit/6ab71683d14a408e79f7cbda3a07ab65f76c6b35). The get_window_context function in hop.nvim will raise function not found error when the Neovim version is below 0.7. This commit partially reverts the 6ed29f1 commit without breaking it.

aznhe21 commented 1 year ago

No, this will not pass the test cases in https://github.com/phaazon/hop.nvim/pull/315.

I'v tried charidx and others, but it seems impossible to simulate charcol before neovim 0.7. So I think it's better to use charcol in neovim 0.7+, and allow bugs and use the original code in older neovim.

local cur_col
if vim.fn.exists('*charcol') == 1 then
  cur_col = vim.fn.charcol('.')
else
  cur_col = vim.fn.strwidth(vim.api.nvim_get_current_line():sub(1, vim.fn.col('.')))
end