@@ -5,27 +5,6 @@ local tmp_file_watcher
55local uv = vim .loop
66local dirty = true
77
8- local watch_tmp_file = function (chan_id )
9- tmp_file_watcher = uv .new_fs_event ()
10- tmp_file_watcher :start (
11- tmp_file ,
12- {},
13- vim .schedule_wrap (function (_ , fname , status )
14- if dirty then
15- -- Open the current file in the remote Nvim instance
16- vim .rpcrequest (
17- chan_id ,
18- " nvim_exec" ,
19- -- Store the current sequence number that can be reverted back to
20- (" e! %s | lua vim.g._seq_cur = vim.fn.undotree().seq_cur" ):format (tmp_file ),
21- false
22- )
23- dirty = false
24- end
25- end )
26- )
27- end
28-
298-- Starts a new Nvim instance and connects to it via RPC
309M .init_rpc = function (on_chan_id )
3110 -- Avoid an infinite loop
@@ -58,33 +37,34 @@ M.init_rpc = function(on_chan_id)
5837 )
5938 assert (handle )
6039
61- for i = 0 , 100 do
40+ for _ = 0 , 100 do
6241 local ok , chan_id
6342 ok , chan_id = pcall (vim .fn .sockconnect , " pipe" , server_address , { rpc = true })
6443 if ok then
6544 on_chan_id (chan_id )
66- watch_tmp_file (chan_id )
6745 return
6846 end
6947 vim .wait (10 )
7048 end
7149 vim .notify (" [live-command.nvim] failed to connect to remote Neovim instance after 1000 ms" , vim .log .levels .ERROR )
7250end
7351
74- M .shutdown = function ()
75- if tmp_file_watcher then
76- tmp_file_watcher :stop ()
77- end
78- end
79-
8052M .on_text_changed = function ()
8153 dirty = true
8254end
8355
84- M .on_cmdline_enter = function ()
56+ M .sync = function (chan_id )
8557 if dirty then
8658 -- Synchronize buffers by writing out the current buffer contents to a temporary file
87- vim .cmd (" keepalt w! " .. tmp_file )
59+ vim .cmd (" silent keepalt w! " .. tmp_file )
60+ vim .rpcrequest (
61+ chan_id ,
62+ " nvim_exec" ,
63+ -- Store the current sequence number that can be reverted back to
64+ (" e! %s | lua vim.g._seq_cur = vim.fn.undotree().seq_cur" ):format (tmp_file ),
65+ false
66+ )
67+ dirty = false
8868 end
8969end
9070
0 commit comments