From f449121764c19cebda7b8b2c970b76bc8121bae7 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 2 Mar 2023 18:03:11 +0100 Subject: feat(treesitter): add :InspectTree command (#22477) --- runtime/plugin/nvim.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 815886f896..762e9519db 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -5,3 +5,7 @@ vim.api.nvim_create_user_command('Inspect', function(cmd) vim.show_pos() end end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true }) + +vim.api.nvim_create_user_command('InspectTree', function() + vim.treesitter.inspect_tree() +end, { desc = 'Inspect treesitter language tree for buffer' }) -- cgit From 673d2b52fa4335aa083c52e6686f0728e25b8ebd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Mar 2023 16:04:57 +0100 Subject: refactor!: rename vim.pretty_print => vim.print Problem: The function name `vim.pretty_print`: 1. is verbose, which partially defeats its purpose as sugar 2. does not draw from existing precedent or any sort of convention (except external projects like penlight or python?), which reduces discoverability, and degrades signaling about best practices. Solution: - Rename to `vim.print`. - Change the behavior so that 1. strings are printed without quotes 2. each arg is printed on its own line 3. tables are indented with 2 instead of 4 spaces - Example: :lua ='a', 'b', 42, {a=3} a b 42 { a = 3 } Comparison of alternatives: - `vim.print`: - pro: consistent with Lua's `print()` - pro: aligns with potential `nvim_print` API function which will replace nvim_echo, nvim_notify, etc. - con: behaves differently than Lua's `print()`, slightly misleading? - `vim.echo`: - pro: `:echo` has similar "pretty print" behavior. - con: inconsistent with Lua idioms. - `vim.p`: - pro: very short, fits with `vim.o`, etc. - con: not as discoverable as "echo" - con: less opportunity for `local p = vim.p` because of potential shadowing. --- runtime/plugin/nvim.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 762e9519db..e4b099f7ad 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -1,6 +1,6 @@ vim.api.nvim_create_user_command('Inspect', function(cmd) if cmd.bang then - vim.pretty_print(vim.inspect_pos()) + vim.print(vim.inspect_pos()) else vim.show_pos() end -- cgit From 2720d2c793b22e6c0c8719e5592922619fffdf7a Mon Sep 17 00:00:00 2001 From: Yochem van Rosmalen Date: Fri, 17 Mar 2023 12:41:57 +0100 Subject: fix(treesitter): InspectTree does not respect 'splitright' #22692 Problem: vim.treesitter.inspect_tree() and :InspectTree does not respect 'splitright'. Solution: - Change the default `command` from `topleft 60vnew` to `60vnew`. - Change :InspectTree to respect command mods (`:vertical`, count, etc.). Closes #22656 --- runtime/plugin/nvim.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index e4b099f7ad..0a33826b82 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -6,6 +6,15 @@ vim.api.nvim_create_user_command('Inspect', function(cmd) end end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true }) -vim.api.nvim_create_user_command('InspectTree', function() - vim.treesitter.inspect_tree() -end, { desc = 'Inspect treesitter language tree for buffer' }) +vim.api.nvim_create_user_command('InspectTree', function(cmd) + if cmd.mods ~= '' or cmd.count ~= 0 then + local count = cmd.count ~= 0 and cmd.count or '' + local new = cmd.mods ~= '' and 'new' or 'vnew' + + vim.treesitter.inspect_tree({ + command = ('%s %s%s'):format(cmd.mods, count, new), + }) + else + vim.treesitter.inspect_tree() + end +end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -- cgit From af6e6ccf3dee815850639ec5613dda3442caa7d6 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Sun, 30 Apr 2023 15:53:02 +1000 Subject: feat(vim.ui): vim.ui.open, "gx" without netrw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mathias Fußenegger Co-authored-by: Justin M. Keyes Co-authored-by: ii14 <59243201+ii14@users.noreply.github.com> --- runtime/plugin/nvim.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 0a33826b82..fcc1b016aa 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -18,3 +18,11 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) vim.treesitter.inspect_tree() end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) + +if vim.g.use_lua_gx == nil or vim.g.use_lua_gx == true then + vim.keymap.set({ 'n', 'x' }, 'gx', function() + local uri = vim.fn.expand('') + + vim.ui.open(uri) + end, { desc = 'Open URI under cursor with system app' }) +end -- cgit From 67b2ed1004ae551c9fe1bbd29a86b5a301570800 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 2 Jul 2023 16:51:30 +0200 Subject: fix(gx): visual selection, expand env vars --- Rejected experiment: move vim.ui.open() to vim.env.open() Problem: `vim.ui` is where user-interface "providers" live, which can be overridden. It would also be useful to have a "providers" namespace for platform-specific features such as "open", clipboard, python, and the other providers listed in `:help providers`. We could overload `vim.ui` to serve that purpose as the single "providers" namespace, but `vim.ui.nodejs()` for example seems awkward. Solution: `vim.env` currently has too narrow of a purpose. Overload it to also be a namespace for `vim.env.open`. diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 913f1fe20348..17d05ff37595 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -37,8 +37,28 @@ local options_info = setmetatable({}, { end, }) -vim.env = setmetatable({}, { - __index = function(_, k) +vim.env = setmetatable({ + open = setmetatable({}, { + __call = function(_, uri) + print('xxxxx'..uri) + return true + end, + __tostring = function() + local v = vim.fn.getenv('open') + if v == vim.NIL then + return nil + end + return v + end, + }) + }, + { + __index = function(t, k, ...) + if k == 'open' then + error() + -- vim.print({...}) + -- return rawget(t, k) + end local v = vim.fn.getenv(k) if v == vim.NIL then return nil --- runtime/plugin/nvim.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index fcc1b016aa..9fff6246e3 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -19,10 +19,15 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -if vim.g.use_lua_gx == nil or vim.g.use_lua_gx == true then - vim.keymap.set({ 'n', 'x' }, 'gx', function() - local uri = vim.fn.expand('') - - vim.ui.open(uri) - end, { desc = 'Open URI under cursor with system app' }) +-- TODO: use vim.region() when it lands... #13896 #16843 +local function get_visual_selection() + local save_a = vim.fn.getreginfo('a') + vim.cmd[[norm! "ay]] + local selection = vim.fn.getreg('a', 1) + vim.fn.setreg('a', save_a) + return selection end + +local gx_desc = 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' +vim.keymap.set({ 'n' }, 'gx', function() vim.ui.open(vim.fn.expand('')) end, { desc = gx_desc }) +vim.keymap.set({ 'x' }, 'gx', function() vim.ui.open(get_visual_selection()) end, { desc = gx_desc }) -- cgit From e644e7ce0b36dd5e75770f3faa0a84f15e2561e8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 4 Jul 2023 23:33:23 +0200 Subject: fix(vim.ui.open): return (don't show) error message Problem: Showing an error via vim.notify() makes it awkward for callers such as lsp/handlers.lua to avoid showing redundant errors. Solution: Return the message instead of showing it. Let the caller decide whether and when to show the message. --- runtime/plugin/nvim.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 9fff6246e3..33d399e577 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -22,12 +22,23 @@ end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -- TODO: use vim.region() when it lands... #13896 #16843 local function get_visual_selection() local save_a = vim.fn.getreginfo('a') - vim.cmd[[norm! "ay]] + vim.cmd([[norm! "ay]]) local selection = vim.fn.getreg('a', 1) vim.fn.setreg('a', save_a) return selection end -local gx_desc = 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' -vim.keymap.set({ 'n' }, 'gx', function() vim.ui.open(vim.fn.expand('')) end, { desc = gx_desc }) -vim.keymap.set({ 'x' }, 'gx', function() vim.ui.open(get_visual_selection()) end, { desc = gx_desc }) +local gx_desc = + 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' +local function do_open(uri) + local _, err = vim.ui.open(uri) + if err then + vim.notify(err, vim.log.levels.ERROR) + end +end +vim.keymap.set({ 'n' }, 'gx', function() + do_open(vim.fn.expand('')) +end, { desc = gx_desc }) +vim.keymap.set({ 'x' }, 'gx', function() + do_open(get_visual_selection()) +end, { desc = gx_desc }) -- cgit From df297e3c2bd743616371db73467a3f08d2b96d9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Jul 2023 16:31:45 +0800 Subject: fix(runtime): don't set gx mapping if already mapped (#24262) This matches netrw's use of maparg(). --- runtime/plugin/nvim.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 33d399e577..e3d4625c3b 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -36,9 +36,13 @@ local function do_open(uri) vim.notify(err, vim.log.levels.ERROR) end end -vim.keymap.set({ 'n' }, 'gx', function() - do_open(vim.fn.expand('')) -end, { desc = gx_desc }) -vim.keymap.set({ 'x' }, 'gx', function() - do_open(get_visual_selection()) -end, { desc = gx_desc }) +if vim.fn.maparg('gx', 'n') == '' then + vim.keymap.set({ 'n' }, 'gx', function() + do_open(vim.fn.expand('')) + end, { desc = gx_desc }) +end +if vim.fn.maparg('gx', 'x') == '' then + vim.keymap.set({ 'x' }, 'gx', function() + do_open(get_visual_selection()) + end, { desc = gx_desc }) +end -- cgit From 6a486c44e66f05ae11137ad7a192b89989192566 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Tue, 25 Jul 2023 01:35:19 +1000 Subject: fix(gx): move to to _init_default_mappings #24420 Problem: netrw may conflict with the Nvim default "gx" mapping. Solution: Initialize keymapping earlier by moving it to vim._init_default_mappings(). That also avoids needing to check maparg(). --- runtime/plugin/nvim.lua | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index e3d4625c3b..0a33826b82 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -18,31 +18,3 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) vim.treesitter.inspect_tree() end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) - --- TODO: use vim.region() when it lands... #13896 #16843 -local function get_visual_selection() - local save_a = vim.fn.getreginfo('a') - vim.cmd([[norm! "ay]]) - local selection = vim.fn.getreg('a', 1) - vim.fn.setreg('a', save_a) - return selection -end - -local gx_desc = - 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' -local function do_open(uri) - local _, err = vim.ui.open(uri) - if err then - vim.notify(err, vim.log.levels.ERROR) - end -end -if vim.fn.maparg('gx', 'n') == '' then - vim.keymap.set({ 'n' }, 'gx', function() - do_open(vim.fn.expand('')) - end, { desc = gx_desc }) -end -if vim.fn.maparg('gx', 'x') == '' then - vim.keymap.set({ 'x' }, 'gx', function() - do_open(get_visual_selection()) - end, { desc = gx_desc }) -end -- cgit From 5d8ab32f3871b0232972cac1116ac7cba98389e5 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Fri, 25 Aug 2023 11:17:36 -0700 Subject: feat(treesitter): add a query editor (#24703) --- runtime/plugin/nvim.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 0a33826b82..2ddccfcff6 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -18,3 +18,7 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) vim.treesitter.inspect_tree() end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) + +vim.api.nvim_create_user_command('PreviewQuery', function() + vim.treesitter.preview_query() +end, { desc = 'Preview treesitter query' }) -- cgit From 28233bcb49067aaa70fa6e5fec14e2cc4bcaa315 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Fri, 15 Sep 2023 03:10:55 -0700 Subject: refactor(treesitter): rename "preview" => "edit" #25161 "Edit" more closely describes the generic application than "Preview", though the buffer contents don't (yet) map to an actual file on disk. https://github.com/neovim/neovim/pull/24703#discussion_r1321719133 --- runtime/plugin/nvim.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 2ddccfcff6..13a54a5e20 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -19,6 +19,6 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -vim.api.nvim_create_user_command('PreviewQuery', function() - vim.treesitter.preview_query() -end, { desc = 'Preview treesitter query' }) +vim.api.nvim_create_user_command('EditQuery', function() + vim.treesitter.query.edit() +end, { desc = 'Edit treesitter query' }) -- cgit From 28f54a78782318cb9c356a372b9e52a3a6b1f8dd Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sat, 16 Sep 2023 10:05:59 -0700 Subject: feat(treesitter): add lang parameter to the query editor (#25181) --- runtime/plugin/nvim.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/plugin/nvim.lua') diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 13a54a5e20..743d3044b6 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -19,6 +19,6 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd) end end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -vim.api.nvim_create_user_command('EditQuery', function() - vim.treesitter.query.edit() -end, { desc = 'Edit treesitter query' }) +vim.api.nvim_create_user_command('EditQuery', function(cmd) + vim.treesitter.query.edit(cmd.fargs[1]) +end, { desc = 'Edit treesitter query', nargs = '?' }) -- cgit