@@ -187,30 +187,23 @@ M.buffers = function(opts)
187187 opts = config .normalize_opts (opts , " buffers" )
188188 if not opts then return end
189189
190- opts .__fn_reload = opts .__fn_reload or function (_ )
191- return function (cb )
192- local filtered , _ , max_bufnr = filter_buffers (opts , core .CTX ().buflist )
193-
194- if next (filtered ) then
195- local buffers = populate_buffer_entries (opts , filtered )
196- for _ , bufinfo in pairs (buffers ) do
197- local ok , entry = pcall (gen_buffer_entry , opts , bufinfo , max_bufnr )
198- assert (ok and entry )
199- cb (entry )
200- end
190+ local contents = function (cb )
191+ local filtered , _ , max_bufnr = filter_buffers (opts , core .CTX ().buflist )
192+
193+ if next (filtered ) then
194+ local buffers = populate_buffer_entries (opts , filtered )
195+ for _ , bufinfo in pairs (buffers ) do
196+ local ok , entry = pcall (gen_buffer_entry , opts , bufinfo , max_bufnr )
197+ assert (ok and entry )
198+ cb (entry )
201199 end
202- cb (nil )
203200 end
201+ cb (nil )
204202 end
205203
206- -- build the "reload" cmd and remove '-- {+}' from the initial cmd
207- local contents , id = shell .reload_action_cmd (opts , " " )
208- opts .__reload_cmd = contents
209-
210204 -- get current tab/buffer/previous buffer
211205 -- save as a func ref for resume to reuse
212206 opts ._fn_pre_fzf = function ()
213- shell .set_protected (id )
214207 core .CTX ({ includeBuflist = true }) -- include `nvim_list_bufs` in context
215208 end
216209
@@ -409,79 +402,65 @@ M.tabs = function(opts)
409402 end , " " , opts .debug ))
410403 end
411404
412- opts .__fn_reload = opts .__fn_reload or function (_ )
413- -- we do not return the populate function with cb directly to avoid
414- -- E5560: nvim_exec must not be called in a lua loop callback
415- local entries = {}
416- local populate = function (cb )
417- local max_bufnr = (function ()
418- local ret = 0
419- for _ , t in ipairs (vim .api .nvim_list_tabpages ()) do
420- for _ , w in ipairs (vim .api .nvim_tabpage_list_wins (t )) do
421- local b = vim .api .nvim_win_get_buf (w )
422- if b > ret then ret = b end
423- end
405+ local contents = function (cb )
406+ local max_bufnr = (function ()
407+ local ret = 0
408+ for _ , t in ipairs (vim .api .nvim_list_tabpages ()) do
409+ for _ , w in ipairs (vim .api .nvim_tabpage_list_wins (t )) do
410+ local b = vim .api .nvim_win_get_buf (w )
411+ if b > ret then ret = b end
424412 end
425- return ret
426- end )()
413+ end
414+ return ret
415+ end )()
427416
428- for tabnr , tabh in ipairs (vim .api .nvim_list_tabpages ()) do
429- (function ()
430- if opts .current_tab_only and tabh ~= core .CTX ().tabh then return end
431-
432- local tab_cwd = vim .fn .getcwd (- 1 , tabnr )
433- local tab_cwd_tilde = path .HOME_to_tilde (tab_cwd )
434- local title , fn_title_hl = opt_hl (tabnr , " tab_title" ,
435- function (s )
436- return string.format (" %s%s#%d%s" , s , utils .nbsp , tabnr ,
437- (uv .cwd () == tab_cwd and " " or string.format (" : %s" , tab_cwd_tilde )))
438- end ,
439- utils .ansi_codes [opts .hls .tab_title ])
440-
441- local marker , fn_marker_hl = opt_hl (tabnr , " tab_marker" ,
442- function (s ) return s end ,
443- utils .ansi_codes [opts .hls .tab_marker ])
444-
445- local tab_cwd_tilde_base64 = base64 .encode (tab_cwd_tilde )
446- if not opts .current_tab_only then
447- cb (string.format (" %s:%d:%d:0)%s%s %s" ,
448- tab_cwd_tilde_base64 ,
449- tabnr ,
450- tabh ,
451- utils .nbsp ,
452- fn_title_hl (title ),
453- (tabh == core .CTX ().tabh ) and fn_marker_hl (marker ) or " " ))
454- end
417+ for tabnr , tabh in ipairs (vim .api .nvim_list_tabpages ()) do
418+ (function ()
419+ if opts .current_tab_only and tabh ~= core .CTX ().tabh then return end
420+
421+ local tab_cwd = vim .fn .getcwd (- 1 , tabnr )
422+ local tab_cwd_tilde = path .HOME_to_tilde (tab_cwd )
423+ local title , fn_title_hl = opt_hl (tabnr , " tab_title" ,
424+ function (s )
425+ return string.format (" %s%s#%d%s" , s , utils .nbsp , tabnr ,
426+ (uv .cwd () == tab_cwd and " " or string.format (" : %s" , tab_cwd_tilde )))
427+ end ,
428+ utils .ansi_codes [opts .hls .tab_title ])
429+
430+ local marker , fn_marker_hl = opt_hl (tabnr , " tab_marker" ,
431+ function (s ) return s end ,
432+ utils .ansi_codes [opts .hls .tab_marker ])
433+
434+ local tab_cwd_tilde_base64 = base64 .encode (tab_cwd_tilde )
435+ if not opts .current_tab_only then
436+ cb (string.format (" %s:%d:%d:0)%s%s %s" ,
437+ tab_cwd_tilde_base64 ,
438+ tabnr ,
439+ tabh ,
440+ utils .nbsp ,
441+ fn_title_hl (title ),
442+ (tabh == core .CTX ().tabh ) and fn_marker_hl (marker ) or " " ))
443+ end
455444
456- for _ , w in ipairs (vim .api .nvim_tabpage_list_wins (tabh )) do
457- if tabh ~= core .CTX ().tabh or core .CTX ().curtab_wins [tostring (w )] then
458- local b = filter_buffers (opts , { vim .api .nvim_win_get_buf (w ) })[1 ]
459- if b then
460- local prefix = string.format (" %s:%d:%d:%d)%s%s%s" ,
461- tab_cwd_tilde_base64 , tabnr , tabh , w , utils .nbsp , utils .nbsp , utils .nbsp )
462- local bufinfo = populate_buffer_entries ({}, { b }, w )[1 ]
463- cb (gen_buffer_entry (opts , bufinfo , max_bufnr , tab_cwd , prefix ))
464- end
445+ for _ , w in ipairs (vim .api .nvim_tabpage_list_wins (tabh )) do
446+ if tabh ~= core .CTX ().tabh or core .CTX ().curtab_wins [tostring (w )] then
447+ local b = filter_buffers (opts , { vim .api .nvim_win_get_buf (w ) })[1 ]
448+ if b then
449+ local prefix = string.format (" %s:%d:%d:%d)%s%s%s" ,
450+ tab_cwd_tilde_base64 , tabnr , tabh , w , utils .nbsp , utils .nbsp , utils .nbsp )
451+ local bufinfo = populate_buffer_entries ({}, { b }, w )[1 ]
452+ cb (gen_buffer_entry (opts , bufinfo , max_bufnr , tab_cwd , prefix ))
465453 end
466454 end
467- end )()
468- end
469- cb (nil )
455+ end
456+ end )()
470457 end
471- populate (function (e )
472- if e then table.insert (entries , e ) end
473- end )
474- return entries
458+ cb (nil )
475459 end
476460
477- -- build the "reload" cmd and remove '-- {+}' from the initial cmd
478- local contents , id = shell .reload_action_cmd (opts , " " )
479- opts .__reload_cmd = contents
480-
481461 -- get current tab/buffer/previous buffer
482462 -- save as a func ref for resume to reuse
483463 opts ._fn_pre_fzf = function ()
484- shell .set_protected (id )
485464 core .CTX ({ includeBuflist = true }) -- include `nvim_list_bufs` in context
486465 end
487466
0 commit comments