diff --git a/README.md b/README.md
index 0483919..4fdda1b 100644
--- a/README.md
+++ b/README.md
@@ -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. -- get buffer-local variables
+buf.b. = ... -- set buffer-local variables
+buf.bo. -- get buffer options
+buf.bo. = ... -- 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)
diff --git a/lua/u/buffer.lua b/lua/u/buffer.lua
index 0b9d806..84a05cc 100644
--- a/lua/u/buffer.lua
+++ b/lua/u/buffer.lua
@@ -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