From 3a342f9cc9f0ca67620fe0886cdc7a5e03e6fece Mon Sep 17 00:00:00 2001 From: Corey Williamson Date: Tue, 9 Mar 2021 21:21:45 -0600 Subject: api: add vim.api.nvim_win_hide --- src/nvim/api/window.c | 24 ++++++++++++++++++++++ test/functional/api/window_spec.lua | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f4af1632ec..f10b4b900b 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -492,6 +492,30 @@ Dictionary nvim_win_get_config(Window window, Error *err) return rv; } +/// Hides the window (like |:hide| with a |window-ID|). +/// +/// @param window Window handle, or 0 for current window +/// @param[out] err Error details, if any +void nvim_win_hide(Window window, Error *err) + FUNC_API_SINCE(7) + FUNC_API_CHECK_TEXTLOCK +{ + win_T *win = find_window_by_handle(window, err); + if (!win) { + return; + } + + tabpage_T *tabpage = win_find_tabpage(win); + TryState tstate; + try_enter(&tstate); + if (tabpage == curtab) { + win_close(win, false); + } else { + win_close_othertab(win, false, tabpage); + } + vim_ignored = try_leave(&tstate, err); +} + /// Closes the window (like |:close| with a |window-ID|). /// /// @param window Window handle, or 0 for current window diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 7471f50dbd..ceeb84cec9 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -347,4 +347,44 @@ describe('API/win', function() eq('', funcs.getcmdwintype()) end) end) + + describe('hide', function() + it('can hide current window', function() + local oldwin = meths.get_current_win() + command('split') + local newwin = meths.get_current_win() + meths.win_hide(newwin) + eq({oldwin}, meths.list_wins()) + end) + it('can hide noncurrent window', function() + local oldwin = meths.get_current_win() + command('split') + local newwin = meths.get_current_win() + meths.win_hide(oldwin) + eq({newwin}, meths.list_wins()) + end) + it('does not close the buffer', function() + local oldwin = meths.get_current_win() + local oldbuf = meths.get_current_buf() + local buf = meths.create_buf(true, false) + local newwin = meths.open_win(buf, true, { + relative='win', row=3, col=3, width=12, height=3 + }) + meths.win_hide(newwin) + eq({oldwin}, meths.list_wins()) + eq({oldbuf, buf}, meths.list_bufs()) + end) + it('deletes the buffer when bufhidden=wipe', function() + local oldwin = meths.get_current_win() + local oldbuf = meths.get_current_buf() + local buf = meths.create_buf(true, false) + local newwin = meths.open_win(buf, true, { + relative='win', row=3, col=3, width=12, height=3 + }) + meths.buf_set_option(buf, 'bufhidden', 'wipe') + meths.win_hide(newwin) + eq({oldwin}, meths.list_wins()) + eq({oldbuf}, meths.list_bufs()) + end) + end) end) -- cgit From 3fbd9ed4ab1d7a90297488d778205e8dc270cbf4 Mon Sep 17 00:00:00 2001 From: Corey Williamson Date: Wed, 10 Mar 2021 13:29:01 -0600 Subject: api: clarify difference between win_hide and win_close --- src/nvim/api/window.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f10b4b900b..89fa2f86fb 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -492,7 +492,12 @@ Dictionary nvim_win_get_config(Window window, Error *err) return rv; } -/// Hides the window (like |:hide| with a |window-ID|). +/// Closes the window and hide the buffer it contains (like |:hide| with a +/// |window-ID|). +/// +/// Like |:hide| the buffer becomes hidden unless another window is editing it, +/// or 'bufhidden' is `unload`, `delete` or `wipe` as opposed to |:close| or +/// |nvim_win_close|, which will close the buffer. /// /// @param window Window handle, or 0 for current window /// @param[out] err Error details, if any -- cgit From 45236981d887e3a535adc0fc1e91cadce54c9463 Mon Sep 17 00:00:00 2001 From: Corey Williamson Date: Tue, 16 Mar 2021 01:02:20 -0500 Subject: run docgen --- runtime/doc/api.txt | 21 ++++++++++++++++++--- runtime/doc/lsp.txt | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index bd34411065..5d7f559c0d 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1415,8 +1415,8 @@ nvim_put({lines}, {type}, {after}, {follow}) *nvim_put()* • "c" |charwise| mode • "l" |linewise| mode • "" guess by contents, see |setreg()| - {after} If true insert after cursor (like |p|), or before (like - |P|). + {after} If true insert after cursor (like |p|), or + before (like |P|). {follow} If true place cursor at end of inserted text. *nvim_replace_termcodes()* @@ -1737,7 +1737,7 @@ nvim__buf_stats({buffer}) *nvim__buf_stats()* TODO: Documentation *nvim_buf_add_highlight()* -nvim_buf_add_highlight({buffer}, {src_id}, {hl_group}, {line}, {col_start}, +nvim_buf_add_highlight({buffer}, {ns_id}, {hl_group}, {line}, {col_start}, {col_end}) Adds a highlight to buffer. @@ -2468,6 +2468,21 @@ nvim_win_get_width({window}) *nvim_win_get_width()* Return: ~ Width as a count of columns +nvim_win_hide({window}) *nvim_win_hide()* + Closes the window and hide the buffer it contains (like + |:hide| with a |window-ID|). + + Like |:hide| the buffer becomes hidden unless another window + is editing it, or 'bufhidden' is `unload` , `delete` or `wipe` + as opposed to |:close| or |nvim_win_close|, which will close + the buffer. + + Attributes: ~ + not allowed when |textlock| is active + + Parameters: ~ + {window} Window handle, or 0 for current window + nvim_win_is_valid({window}) *nvim_win_is_valid()* Checks if a window is valid diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index d2d88fb9ba..1f6ecc911d 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -1469,8 +1469,8 @@ show_line_diagnostics({opts}, {bufnr}, {line_nr}, {client_id}) ============================================================================== Lua module: vim.lsp.handlers *lsp-handlers* - *vim.lsp.handlers.progress_callback()* -progress_callback({_}, {_}, {params}, {client_id}) + *vim.lsp.handlers.progress_handler()* +progress_handler({_}, {_}, {params}, {client_id}) See also: ~ https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand -- cgit