Skip to content

Commit 07393e8

Browse files
Merge pull request #30 from gennaro-tedesco/fix-deprecations
fixed deprecated vim APIs
2 parents 11b1d03 + 8129fa0 commit 07393e8

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Install it using your favourite plugin manager: for instance
3535
```lua
3636
{
3737
"gennaro-tedesco/nvim-jqx",
38+
event = {"BufReadPost"},
3839
ft = { "json", "yaml" },
3940
},
4041
```

doc/jqx.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*jqx.txt* For Neovim >= 0.8.0 Last change: 2023 February 28
1+
*jqx.txt* For Neovim >= 0.8.0 Last change: 2024 May 31
22

33
==============================================================================
44
Table of Contents *jqx-table-of-contents*
@@ -7,6 +7,7 @@ Table of Contents *jqx-table-of-contents*
77
- Usage |jqx-usage|
88
- Customisation |jqx-customisation|
99
- Feedback |jqx-feedback|
10+
1. Links |jqx-links|
1011

1112

1213

@@ -27,12 +28,12 @@ INSTALLATION *jqx-installation*
2728

2829
Install it using your favourite plugin manager: for instance
2930

30-
3131
- with lazy.nvim <https://github.com/folke/lazy.nvim>
3232

3333
>lua
3434
{
3535
"gennaro-tedesco/nvim-jqx",
36+
event = {"BufReadPost"},
3637
ft = { "json", "yaml" },
3738
},
3839
<
@@ -63,11 +64,11 @@ file `test.json` and issue `JqxQuery <my-query>`this translates into `jq
6364
".<my-query>" test.json` as shown below
6465

6566
>
66-
JqxQuery grammar
67+
# JqxQuery grammar
6768
JqxQuery friends[2].name
6869
"Michael Marquez"
6970
70-
jq equivalent
71+
# jq equivalent
7172
jq '.friends[2].name' test.json
7273
"Michael Marquez"
7374
<
@@ -84,8 +85,8 @@ Default commands
8485
<Esc> close floating window
8586
Try it out directly with `nvim examples/test.json -c JqxList`.
8687

87-
For more in-depth description and explanations check the documentation `:h
88-
nvim-jqx` and links therein.
88+
For more in-depth description and explanations check the documentation
89+
|nvim-jqx| and links therein.
8990

9091

9192
YAML FILES ~
@@ -137,7 +138,7 @@ autogroup
137138
local jqx = vim.api.nvim_create_augroup("Jqx", {})
138139
vim.api.nvim_clear_autocmds({ group = jqx })
139140
vim.api.nvim_create_autocmd("BufWinEnter", {
140-
pattern = { ".json", ".yaml" },
141+
pattern = { "*.json", "*.yaml" },
141142
desc = "preview json and yaml files on open",
142143
group = jqx,
143144
callback = function()

lua/nvim-jqx/floating.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ local function centre_string(s)
66
end
77

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

2525
vim.api.nvim_open_win(buf, true, win_opts)
26-
vim.api.nvim_win_set_option(0, "wrap", config.geometry.wrap)
26+
vim.api.nvim_set_option_value("wrap", config.geometry.wrap, { win = 0 })
2727
return buf
2828
end
2929

3030
local function set_fw_opts(buf)
31-
vim.api.nvim_buf_set_option(buf, "filetype", "jqx")
32-
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
33-
vim.api.nvim_buf_set_option(buf, "modifiable", false)
34-
vim.api.nvim_buf_set_option(buf, "readonly", true)
31+
vim.api.nvim_set_option_value("filetype", "jqx", { buf = buf })
32+
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
33+
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
34+
vim.api.nvim_set_option_value("readonly", true, { buf = buf })
3535
vim.api.nvim_buf_set_keymap(
3636
buf,
3737
"n",

lua/nvim-jqx/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ end
3131

3232
---set keymaps in the qf to query entry on keypress
3333
local function set_qf_maps(ft)
34-
vim.api.nvim_exec(
34+
vim.api.nvim_exec2(
3535
[[autocmd FileType qf nnoremap <buffer> ]]
3636
.. config.query_key
3737
.. [[ :lua require("nvim-jqx.jqx").on_keystroke("]]
3838
.. ft
3939
.. [[")<CR> ]],
40-
false
40+
{ output = false }
4141
)
4242
end
4343

lua/nvim-jqx/jqx.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ end
2424
local function get_key_location(key, ft)
2525
if ft == "json" then
2626
return {
27-
row = vim.api.nvim_exec([[g/^\s*"]] .. parse_key(key) .. [["/echo line('.')]], true),
28-
col = vim.api.nvim_exec([[g/^\s*"]] .. parse_key(key) .. [["/execute "normal! ^" | echo col('.')-1]], true),
27+
row = vim.api.nvim_exec2([[g/^\s*"]] .. parse_key(key) .. [["/echo line('.')]], { output = true }).output,
28+
col = vim.api.nvim_exec2(
29+
[[g/^\s*"]] .. parse_key(key) .. [["/execute "normal! ^" | echo col('.')-1]],
30+
{ output = true }
31+
).output,
2932
}
3033
elseif ft == "yaml" then
3134
return {
32-
row = vim.api.nvim_exec([[g/^]] .. parse_key(key) .. [[/echo line('.')]], true),
33-
col = vim.api.nvim_exec([[g/^]] .. parse_key(key) .. [[/execute "normal! ^" | echo col('.')]], true),
35+
row = vim.api.nvim_exec2([[g/^]] .. parse_key(key) .. [[/echo line('.')]], { output = true }).output,
36+
col = vim.api.nvim_exec2(
37+
[[g/^]] .. parse_key(key) .. [[/execute "normal! ^" | echo col('.')]],
38+
{ output = true }
39+
).output,
3440
}
3541
else
3642
return {}

0 commit comments

Comments
 (0)