@@ -163,13 +163,9 @@ M.fzf_exec = function(contents, opts)
163163 end
164164 -- Contents sent to fzf can only be nil or a shell command (string)
165165 -- the API accepts both tables and functions which we "stringify"
166- if contents ~= nil and type ( contents ) ~= " string " and not opts .__stringified then
166+ if not opts .fn_reload then
167167 opts .__contents = contents
168- local cmd , id = shell .stringify (opts )
169- -- Protect function ptr from being overwritten in the circular buffer
170- -- NOTE: will be cleared when a new picker is opened (not a resume)
171- shell .set_protected (id )
172- contents = cmd
168+ contents = shell .stringify (opts )
173169 end
174170 assert (contents == nil or type (contents ) == " string" , " contents must be of type string" )
175171 -- setup as "live": disables fuzzy matching and reload the content
@@ -180,6 +176,7 @@ M.fzf_exec = function(contents, opts)
180176 -- TODO: add support for 'fn_transform' using 'mt_cmd_wrapper'
181177 -- functions can be stored using 'config.bytecode' which uses
182178 -- 'string.dump' to convert from function code to bytes
179+ opts .fn_reload = M .mt_cmd_wrapper (opts ) or opts .fn_reload
183180 opts = M .setup_fzf_interactive_native (opts .fn_reload , opts )
184181 contents = opts .__fzf_init_cmd
185182 else
@@ -233,7 +230,7 @@ M.fzf_resume = function(opts)
233230end
234231
235232--- @param opts table
236- --- @param contents content
233+ --- @param contents string ?
237234--- @param fn_selected function ?
238235--- @return thread
239236M .fzf_wrap = function (opts , contents , fn_selected )
@@ -320,7 +317,7 @@ M.CTX = function(opts)
320317 return M .__CTX
321318end
322319
323- --- @param contents content
320+ --- @param contents string ?
324321--- @param opts {}?
325322--- @return string[] ?
326323M .fzf = function (contents , opts )
@@ -789,7 +786,7 @@ M.build_fzf_cli = function(opts, fzf_win)
789786end
790787
791788--- @param opts table
792- --- @return string | function
789+ --- @return string ?
793790M .mt_cmd_wrapper = function (opts )
794791 assert (opts and opts .cmd )
795792 --- @param o table<string , unknown>
@@ -910,10 +907,7 @@ M.mt_cmd_wrapper = function(opts)
910907 opts .__fn_preprocess = opts .__fn_preprocess == nil
911908 and function (o ) return make_entry .preprocess (o ) end
912909 or opts .__fn_preprocess
913- opts .__contents = opts .cmd
914- local cmd , id = shell .stringify (opts )
915- shell .set_protected (id )
916- return cmd
910+ return nil
917911 end
918912end
919913
@@ -1169,18 +1163,17 @@ end
11691163
11701164-- converts actions defined with "reload=true" to use fzf's `reload` bind
11711165-- provides a better UI experience without a visible interface refresh
1172- --- @param reload_cmd content
1166+ --- @param reload_cmd string ?
11731167--- @param opts table
11741168--- @return table
11751169M .convert_reload_actions = function (reload_cmd , opts )
11761170 local fallback --- @type boolean ?
1177- local has_reload --- @type boolean ?
11781171 -- Does not work with fzf version < 0.36, fzf fails with
11791172 -- "error 2: bind action not specified:" (#735)
11801173 -- Not yet supported with skim
11811174 if not utils .has (opts , " fzf" , { 0 , 36 })
11821175 or utils .has (opts , " sk" )
1183- or type ( reload_cmd ) ~= " string " then
1176+ or not reload_cmd then
11841177 fallback = true
11851178 end
11861179 -- Two types of action as table:
@@ -1191,7 +1184,6 @@ M.convert_reload_actions = function(reload_cmd, opts)
11911184 if type (v ) == " function" or type (v ) == " table" then
11921185 assert (type (v ) == " function" or (v .fn and v [1 ] == nil ) or (v [1 ] and v .fn == nil ))
11931186 if type (v ) == " table" and v .reload then
1194- has_reload = true
11951187 assert (type (v .fn ) == " function" )
11961188 -- fallback: we cannot use the `reload` event (old fzf or skim)
11971189 -- convert to "old-style" interface reload using `resume`
@@ -1207,10 +1199,6 @@ M.convert_reload_actions = function(reload_cmd, opts)
12071199 end
12081200 end
12091201 end
1210- if opts .silent ~= true and has_reload and reload_cmd and type (reload_cmd ) ~= " string" then
1211- utils .warn (
1212- " actions with `reload` are only supported with string commands, using resume fallback" )
1213- end
12141202 if fallback then
12151203 -- for fallback, conversion to "old-style" actions is sufficient
12161204 return opts
0 commit comments