@@ -245,35 +245,33 @@ function Help.prepare_content(opts)
245
245
return content
246
246
end
247
247
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 )
250
255
251
- local opts = {
256
+ local window_opts = {
252
257
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 ) ,
255
260
anchor = ' NW' ,
256
261
style = ' minimal' ,
257
262
border = ' single' ,
258
263
row = 5 ,
259
264
col = vim .o .columns / 4 ,
260
265
}
261
266
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
271
269
272
270
Help .buf = vim .api .nvim_create_buf (false , true )
273
271
vim .api .nvim_buf_set_name (Help .buf , ' orghelp' )
274
272
vim .api .nvim_buf_set_option (Help .buf , ' filetype' , ' orghelp' )
275
273
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 )
277
275
278
276
vim .api .nvim_buf_set_lines (Help .buf , 0 , - 1 , true , content )
279
277
0 commit comments