Skip to content

Commit

Permalink
Use vim.iter():map()
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed Apr 23, 2024
1 parent 17512dd commit 817aa16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions lua/cmdbuf/handler/lua/variable/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ function M.histories(self)
local keys = vim.api.nvim_buf_call(self._bufnr, function()
return vim.fn.getcompletion("b:*", "var")
end)
local vars = vim.tbl_map(function(key)
local name = key:sub(prefix_length)
local value = vim.api.nvim_buf_get_var(self._bufnr, name)
return ("%s = %s"):format(name, vim.inspect(value, { newline = " ", indent = " " }))
end, keys)
local vars = vim
.iter(keys)
:map(function(key)
local name = key:sub(prefix_length)
local value = vim.api.nvim_buf_get_var(self._bufnr, name)
return ("%s = %s"):format(name, vim.inspect(value, { newline = " ", indent = " " }))
end)
:totable()

local histories = {}
table.insert(histories, "-- Buffer variables")
Expand Down
13 changes: 8 additions & 5 deletions lua/cmdbuf/handler/lua/variable/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ function M.histories(_)

local prefix_length = #"g:" + 1
local keys = vim.fn.getcompletion("g:*", "var")
local vars = vim.tbl_map(function(key)
local name = key:sub(prefix_length)
local value = vim.api.nvim_get_var(name)
return ("%s = %s"):format(name, vim.inspect(value, { newline = " ", indent = " " }))
end, keys)
local vars = vim
.iter(keys)
:map(function(key)
local name = key:sub(prefix_length)
local value = vim.api.nvim_get_var(name)
return ("%s = %s"):format(name, vim.inspect(value, { newline = " ", indent = " " }))
end)
:totable()

local histories = {}
table.insert(histories, "-- Global variables")
Expand Down

0 comments on commit 817aa16

Please sign in to comment.