More user-friendly LualineBuffersJump (#780)
* buffers: user friendly LualineBuffersJump version LualineBuffersJump throws an error when an attempt to jump to a non-existent buffer index is made. It's expected from users to trigger this error by accident while attempting to switch buffers. To deal with this add <bang> support to LualineBuffersJump. Signed-off-by: Plato Kiorpelidis <kioplato@gmail.com> * chore: autogen (vimdocs+formating) Co-authored-by: kioplato <kioplato@users.noreply.github.com>
This commit is contained in:
parent
4b5048aee1
commit
03bcf015d1
|
@ -759,10 +759,14 @@ Shows currently open buffers. Like bufferline . See
|
|||
for all builtin behaviors of buffers component.
|
||||
You can use `:LualineBuffersJump` to jump to buffer based on index
|
||||
of buffer in buffers component.
|
||||
Jumping to non-existent buffer indices generates an error. To avoid these errors
|
||||
`LualineBuffersJump` provides `<bang>` support, meaning that you can call
|
||||
`:LualineBufferJump!` to ignore these errors.
|
||||
|
||||
```vim
|
||||
:LualineBuffersJump 2 " Jumps to 2nd buffer in buffers component.
|
||||
:LualineBuffersJump $ " Jumps to last buffer in buffers component.
|
||||
:LualineBuffersJump! 3 " Attempts to jump to 3rd buffer, if it exists.
|
||||
```
|
||||
|
||||
#### Tabs
|
||||
|
|
|
@ -793,12 +793,19 @@ Buffers Shows currently open buffers. Like
|
|||
builtin behaviors of buffers component.
|
||||
You can use `:LualineBuffersJump` to
|
||||
jump to buffer based on index of buffer
|
||||
in buffers component.
|
||||
in buffers component. Jumping to
|
||||
non-existent buffer indices generates an
|
||||
error. To avoid these errors
|
||||
`LualineBuffersJump` provides `<bang>`
|
||||
support, meaning that you can call
|
||||
`:LualineBufferJump!` to ignore these
|
||||
errors.
|
||||
|
||||
|
||||
>
|
||||
:LualineBuffersJump 2 " Jumps to 2nd buffer in buffers component.
|
||||
:LualineBuffersJump $ " Jumps to last buffer in buffers component.
|
||||
:LualineBuffersJump! 3 " Attempts to jump to 3rd buffer, if it exists.
|
||||
<
|
||||
|
||||
|
||||
|
|
|
@ -211,14 +211,18 @@ function M:draw()
|
|||
return self.status
|
||||
end
|
||||
|
||||
function M.buffer_jump(buf_pos)
|
||||
function M.buffer_jump(buf_pos, bang)
|
||||
if buf_pos == '$' then
|
||||
buf_pos = #M.bufpos2nr
|
||||
else
|
||||
buf_pos = tonumber(buf_pos)
|
||||
end
|
||||
if buf_pos < 1 or buf_pos > #M.bufpos2nr then
|
||||
error('Error: Unable to jump buffer position out of range')
|
||||
if bang ~= '!' then
|
||||
error('Error: Unable to jump buffer position out of range')
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
vim.api.nvim_set_current_buf(M.bufpos2nr[buf_pos])
|
||||
end
|
||||
|
@ -228,7 +232,7 @@ vim.cmd([[
|
|||
execute ":buffer " . a:bufnr
|
||||
endfunction
|
||||
|
||||
command! -nargs=1 LualineBuffersJump call v:lua.require'lualine.components.buffers'.buffer_jump(<f-args>)
|
||||
command! -nargs=1 -bang LualineBuffersJump call v:lua.require'lualine.components.buffers'.buffer_jump(<f-args>, "<bang>")
|
||||
]])
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in New Issue