@@ -218,6 +218,36 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
218
218
print (" [Fzf-lua]: fzf cmd:" , table.concat (cmd , " " ))
219
219
end
220
220
221
+ local pid , chan_id , ns_id , fh_trace
222
+ if opts .debug_tracelog then
223
+ fh_trace = io.open (vim .fn .expand (opts .debug_tracelog ), " wb" )
224
+ if fh_trace then
225
+ debug.sethook (function (_ , _ )
226
+ local s = string.format (" %s %s:%s %s\n " ,
227
+ os.date (" %Y-%m-%dT%H:%M:%S" ),
228
+ debug.getinfo (2 , " S" ).source ,
229
+ debug.getinfo (2 , " l" ).currentline ,
230
+ debug.getinfo (2 , " n" ).name )
231
+ fh_trace :write (s )
232
+ fh_trace :flush ()
233
+ end , " l" )
234
+ end
235
+ end
236
+
237
+ local function unset_debughook ()
238
+ if fh_trace then
239
+ debug.sethook (nil , " " , 0 )
240
+ fh_trace :close ()
241
+ end
242
+ end
243
+
244
+ local function unhook_onkey ()
245
+ if tonumber (ns_id ) and vim .on_key then
246
+ --- @diagnostic disable-next-line : param-type-mismatch
247
+ vim .on_key (nil , ns_id )
248
+ end
249
+ end
250
+
221
251
local co = coroutine.running ()
222
252
local jobstart = opts .is_fzf_tmux and vim .fn .jobstart or vim .fn .termopen
223
253
local shell_cmd = utils .__IS_WINDOWS
@@ -233,7 +263,7 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
233
263
-- temporarily set to `false`, for more info see `:help shellslash` (#1055)
234
264
local nvim_opt_shellslash = utils .__WIN_HAS_SHELLSLASH and vim .o .shellslash
235
265
if nvim_opt_shellslash then vim .o .shellslash = false end
236
- jobstart (shell_cmd , {
266
+ chan_id = jobstart (shell_cmd , {
237
267
cwd = cwd ,
238
268
pty = true ,
239
269
env = {
@@ -263,6 +293,9 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
263
293
and libuv .expand (opts .RIPGREP_CONFIG_PATH ) or " " ,
264
294
},
265
295
on_exit = function (_ , rc , _ )
296
+ -- clear hook
297
+ unhook_onkey ()
298
+ unset_debughook ()
266
299
local output = {}
267
300
local f = io.open (outputtmpname )
268
301
if f then
@@ -285,6 +318,14 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
285
318
end
286
319
})
287
320
321
+ if tonumber (chan_id ) > 0 then
322
+ pid = vim .fn .jobpid (chan_id )
323
+ else
324
+ -- job failed or cmd[0] is not executable
325
+ unhook_onkey ()
326
+ unset_debughook ()
327
+ end
328
+
288
329
-- fzf-tmux spawns outside neovim, don't set filetype/insert mode
289
330
if not opts .is_fzf_tmux then
290
331
vim .bo .filetype = " fzf"
0 commit comments