(buffer) remove unnecessary utilities
Some checks failed
NeoVim tests / plenary-tests (push) Failing after 40s

This commit is contained in:
Jonathan Apodaca 2025-04-14 16:10:19 -06:00
parent 3c7dd84ff2
commit ad1f3c26e2
2 changed files with 23 additions and 30 deletions

View File

@ -401,19 +401,19 @@ Access and manipulate buffers easily:
```lua
local Buffer = require 'u.buffer'
local buf = Buffer.current()
buf:line_count() -- the number of lines in the current buffer
buf:get_option '...'
buf:set_option('...', ...)
buf:get_var '...'
buf:set_var('...', ...)
buf:all() -- returns a Range representing the entire buffer
buf:is_empty() -- returns true if the buffer has no text
buf.b.<option> -- get buffer-local variables
buf.b.<option> = ... -- set buffer-local variables
buf.bo.<option> -- get buffer options
buf.bo.<option> = ... -- set buffer options
buf:line_count() -- the number of lines in the current buffer
buf:all() -- returns a Range representing the entire buffer
buf:is_empty() -- returns true if the buffer has no text
buf:append_line '...'
buf:line(1) -- returns a Range representing the first line in the buffer
buf:line(-1) -- returns a Range representing the last line in the buffer
buf:lines(1, 2) -- returns a Range representing the first two lines in the buffer
buf:lines(2, -2) -- returns a Range representing all but the first and last lines of a buffer
buf:txtobj('iw') -- returns a Range representing the text object 'iw' in the give buffer
buf:line(1) -- returns a Range representing the first line in the buffer
buf:line(-1) -- returns a Range representing the last line in the buffer
buf:lines(1, 2) -- returns a Range representing the first two lines in the buffer
buf:lines(2, -2) -- returns a Range representing all but the first and last lines of a buffer
buf:txtobj('iw') -- returns a Range representing the text object 'iw' in the give buffer
```
## License (MIT)

View File

@ -3,6 +3,8 @@ local Renderer = require('u.renderer').Renderer
--- @class u.Buffer
--- @field bufnr number
--- @field b vim.var_accessor
--- @field bo vim.bo
--- @field private renderer u.Renderer
local Buffer = {}
Buffer.__index = Buffer
@ -12,7 +14,12 @@ Buffer.__index = Buffer
function Buffer.from_nr(bufnr)
if bufnr == nil or bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() end
local renderer = Renderer.new(bufnr)
return setmetatable({ bufnr = bufnr, renderer = renderer }, Buffer)
return setmetatable({
bufnr = bufnr,
b = vim.b[bufnr],
bo = vim.bo[bufnr],
renderer = renderer,
}, Buffer)
end
--- @return u.Buffer
@ -26,25 +33,11 @@ function Buffer.create(listed, scratch)
end
function Buffer:set_tmp_options()
self:set_option('bufhidden', 'delete')
self:set_option('buflisted', false)
self:set_option('buftype', 'nowrite')
self.bo.bufhidden = 'delete'
self.bo.buflisted = false
self.bo.buftype = 'nowrite'
end
--- @param nm string
function Buffer:get_option(nm) return vim.api.nvim_get_option_value(nm, { buf = self.bufnr }) end
--- @param nm string
function Buffer:set_option(nm, val)
return vim.api.nvim_set_option_value(nm, val, { buf = self.bufnr })
end
--- @param nm string
function Buffer:get_var(nm) return vim.api.nvim_buf_get_var(self.bufnr, nm) end
--- @param nm string
function Buffer:set_var(nm, val) return vim.api.nvim_buf_set_var(self.bufnr, nm, val) end
function Buffer:line_count() return vim.api.nvim_buf_line_count(self.bufnr) end
function Buffer:all() return Range.from_buf_text(self.bufnr) end