Skip to content

Commit 6878b99

Browse files
Merge pull request #321 from jgollenz/refactor/show-help
Make Help:show() more explicit
2 parents 667ffd7 + 3070446 commit 6878b99

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lua/orgmode/objects/help.lua

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,35 +245,33 @@ function Help.prepare_content(opts)
245245
return content
246246
end
247247

248-
function Help.show(o)
249-
o = o or {}
248+
function Help.show(opts)
249+
opts = opts or {}
250+
251+
local content = Help.prepare_content(opts)
252+
local longest = utils.reduce(content, function(acc, item)
253+
return math.max(acc, item:len())
254+
end, 0)
250255

251-
local opts = {
256+
local window_opts = {
252257
relative = 'editor',
253-
width = vim.o.columns / 2,
254-
height = vim.o.lines - 10,
258+
width = math.min(longest + 2, vim.o.columns - 2),
259+
height = math.min(#content + 1, vim.o.lines - 2),
255260
anchor = 'NW',
256261
style = 'minimal',
257262
border = 'single',
258263
row = 5,
259264
col = vim.o.columns / 4,
260265
}
261266

262-
local content = Help.prepare_content(o)
263-
local longest = utils.reduce(content, function(acc, item)
264-
return math.max(acc, item:len())
265-
end, 0)
266-
267-
opts.width = math.min(longest + 2, vim.o.columns - 2)
268-
opts.height = math.min(#content + 1, vim.o.lines - 2)
269-
opts.row = (vim.o.lines - opts.height) / 2
270-
opts.col = (vim.o.columns - opts.width) / 2
267+
window_opts.row = (vim.o.lines - window_opts.height) / 2
268+
window_opts.col = (vim.o.columns - window_opts.width) / 2
271269

272270
Help.buf = vim.api.nvim_create_buf(false, true)
273271
vim.api.nvim_buf_set_name(Help.buf, 'orghelp')
274272
vim.api.nvim_buf_set_option(Help.buf, 'filetype', 'orghelp')
275273
vim.api.nvim_buf_set_option(Help.buf, 'bufhidden', 'wipe')
276-
Help.win = vim.api.nvim_open_win(Help.buf, true, opts)
274+
Help.win = vim.api.nvim_open_win(Help.buf, true, window_opts)
277275

278276
vim.api.nvim_buf_set_lines(Help.buf, 0, -1, true, content)
279277

0 commit comments

Comments
 (0)