Skip to content

Commit

Permalink
fixed deprecated vim APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
gennaro-tedesco committed May 31, 2024
1 parent 11b1d03 commit b6b74d2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Install it using your favourite plugin manager: for instance
```lua
{
"gennaro-tedesco/nvim-jqx",
event = {"BufReadPost"},
ft = { "json", "yaml" },
},
```
Expand Down
14 changes: 7 additions & 7 deletions lua/nvim-jqx/floating.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ local function centre_string(s)
end

local function floating_window(geometry)
local total_width = vim.api.nvim_get_option("columns")
local total_height = vim.api.nvim_get_option("lines")
local total_width = vim.api.nvim_get_option_value("columns", {})
local total_height = vim.api.nvim_get_option_value("lines", {})
local win_width = geometry.width <= 1 and math.ceil(total_width * geometry.width) or total_width
local win_height = geometry.height <= 1 and math.ceil(total_height * geometry.height) or total_height
local win_opts = {
Expand All @@ -23,15 +23,15 @@ local function floating_window(geometry)
local buf = vim.api.nvim_create_buf(false, true)

vim.api.nvim_open_win(buf, true, win_opts)
vim.api.nvim_win_set_option(0, "wrap", config.geometry.wrap)
vim.api.nvim_set_option_value("wrap", config.geometry.wrap, { win = 0 })
return buf
end

local function set_fw_opts(buf)
vim.api.nvim_buf_set_option(buf, "filetype", "jqx")
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
vim.api.nvim_buf_set_option(buf, "modifiable", false)
vim.api.nvim_buf_set_option(buf, "readonly", true)
vim.api.nvim_set_option_value("filetype", "jqx", { buf = buf })
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
vim.api.nvim_set_option_value("readonly", true, { buf = buf })
vim.api.nvim_buf_set_keymap(
buf,
"n",
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-jqx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ end

---set keymaps in the qf to query entry on keypress
local function set_qf_maps(ft)
vim.api.nvim_exec(
vim.api.nvim_exec2(
[[autocmd FileType qf nnoremap <buffer> ]]
.. config.query_key
.. [[ :lua require("nvim-jqx.jqx").on_keystroke("]]
.. ft
.. [[")<CR> ]],
false
{ output = false }
)
end

Expand Down
14 changes: 10 additions & 4 deletions lua/nvim-jqx/jqx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ end
local function get_key_location(key, ft)
if ft == "json" then
return {
row = vim.api.nvim_exec([[g/^\s*"]] .. parse_key(key) .. [["/echo line('.')]], true),
col = vim.api.nvim_exec([[g/^\s*"]] .. parse_key(key) .. [["/execute "normal! ^" | echo col('.')-1]], true),
row = vim.api.nvim_exec2([[g/^\s*"]] .. parse_key(key) .. [["/echo line('.')]], { output = true }).output,
col = vim.api.nvim_exec2(
[[g/^\s*"]] .. parse_key(key) .. [["/execute "normal! ^" | echo col('.')-1]],
{ output = true }
).output,
}
elseif ft == "yaml" then
return {
row = vim.api.nvim_exec([[g/^]] .. parse_key(key) .. [[/echo line('.')]], true),
col = vim.api.nvim_exec([[g/^]] .. parse_key(key) .. [[/execute "normal! ^" | echo col('.')]], true),
row = vim.api.nvim_exec2([[g/^]] .. parse_key(key) .. [[/echo line('.')]], { output = true }).output,
col = vim.api.nvim_exec2(
[[g/^]] .. parse_key(key) .. [[/execute "normal! ^" | echo col('.')]],
{ output = true }
).output,
}
else
return {}
Expand Down

0 comments on commit b6b74d2

Please sign in to comment.