@@ -5,27 +5,6 @@ local tmp_file_watcher
5
5
local uv = vim .loop
6
6
local dirty = true
7
7
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
-
29
8
-- Starts a new Nvim instance and connects to it via RPC
30
9
M .init_rpc = function (on_chan_id )
31
10
-- Avoid an infinite loop
@@ -58,33 +37,34 @@ M.init_rpc = function(on_chan_id)
58
37
)
59
38
assert (handle )
60
39
61
- for i = 0 , 100 do
40
+ for _ = 0 , 100 do
62
41
local ok , chan_id
63
42
ok , chan_id = pcall (vim .fn .sockconnect , " pipe" , server_address , { rpc = true })
64
43
if ok then
65
44
on_chan_id (chan_id )
66
- watch_tmp_file (chan_id )
67
45
return
68
46
end
69
47
vim .wait (10 )
70
48
end
71
49
vim .notify (" [live-command.nvim] failed to connect to remote Neovim instance after 1000 ms" , vim .log .levels .ERROR )
72
50
end
73
51
74
- M .shutdown = function ()
75
- if tmp_file_watcher then
76
- tmp_file_watcher :stop ()
77
- end
78
- end
79
-
80
52
M .on_text_changed = function ()
81
53
dirty = true
82
54
end
83
55
84
- M .on_cmdline_enter = function ()
56
+ M .sync = function (chan_id )
85
57
if dirty then
86
58
-- 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
88
68
end
89
69
end
90
70
0 commit comments