summaryrefslogtreecommitdiffstats
path: root/development/eovim/7b320.patch
blob: a2b31e8c7f59cc97550a1a077d3e9b9ef3a6ce43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From 7b320c17b1fc8821eac411f6d6afc14e32f7e093 Mon Sep 17 00:00:00 2001
From: Jean Guyomarc'h <jean@guyomarch.bzh>
Date: Sat, 12 Jan 2019 08:46:44 +0100
Subject: [PATCH] nvim: properly handle the vimenter request

Fixes #38
---
 include/eovim/nvim_api.h    |  3 ++-
 include/eovim/nvim_helper.h |  2 +-
 src/nvim.c                  | 47 +++++++++++++++++++++++++++----------
 src/nvim_api.c              |  6 +++--
 src/nvim_helper.c           |  4 ++--
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/include/eovim/nvim_api.h b/include/eovim/nvim_api.h
index 9885ee1..ca9baab 100644
--- a/include/eovim/nvim_api.h
+++ b/include/eovim/nvim_api.h
@@ -27,7 +27,8 @@
 #include <Eina.h>
 #include <msgpack.h>
 
-Eina_Bool nvim_api_ui_attach(s_nvim *nvim, unsigned int width, unsigned int height);
+Eina_Bool nvim_api_ui_attach(s_nvim *nvim, unsigned int width, unsigned int height,
+                             f_nvim_api_cb func, void *func_data);
 Eina_Bool nvim_api_get_api_info(s_nvim *nvim, f_nvim_api_cb cb, void *data);
 Eina_Bool nvim_api_ui_try_resize(s_nvim *nvim, unsigned int width, unsigned height);
 Eina_Bool nvim_api_ui_ext_cmdline_set(s_nvim *nvim, Eina_Bool externalize);
diff --git a/include/eovim/nvim_helper.h b/include/eovim/nvim_helper.h
index b6ce5f4..9f976d5 100644
--- a/include/eovim/nvim_helper.h
+++ b/include/eovim/nvim_helper.h
@@ -49,6 +49,6 @@ nvim_helper_highlight_group_decode_noop(s_nvim *nvim,
 
 
 void nvim_helper_autocmd_do(s_nvim *nvim, const char *event);
-void nvim_helper_autocmd_vimenter_exec(s_nvim *nvim, f_nvim_api_cb func, void *func_data);
+void nvim_helper_autocmd_vimenter_exec(s_nvim *nvim);
 
 #endif /* ! __EOVIM_NVIM_HELPER_H__ */
diff --git a/src/nvim.c b/src/nvim.c
index 83fdee4..a003a00 100644
--- a/src/nvim.c
+++ b/src/nvim.c
@@ -43,6 +43,8 @@ enum
 static Ecore_Event_Handler *_event_handlers[__HANDLERS_LAST];
 static s_nvim *_nvim_instance = NULL;
 
+static void _api_decode_cb(s_nvim *nvim, void *data, const msgpack_object *result);
+
 /*============================================================================*
  *                                 Private API                                *
  *============================================================================*/
@@ -278,6 +280,15 @@ _handle_notification(s_nvim *nvim,
    return EINA_FALSE;
 }
 
+static Eina_Bool
+_vimenter_request_cb(s_nvim *nvim EINA_UNUSED,
+                     const msgpack_object_array *args EINA_UNUSED,
+                     msgpack_packer *pk)
+{
+  msgpack_pack_nil(pk); /* Error */
+  msgpack_pack_nil(pk); /* Result */
+  return EINA_TRUE;
+}
 
 /*============================================================================*
  *                       Nvim Processes Events Handlers                       *
@@ -298,6 +309,21 @@ _nvim_added_cb(void *data EINA_UNUSED,
 
    const Ecore_Exe_Event_Add *const info = event;
    INF("Process with PID %i was created", ecore_exe_pid_get(info->exe));
+
+   /* Okay, at this point the neovim process is running! Great! Now, we can
+    * start to retrieve the API information and trigger the vimenter autocmd.
+    *
+    * We can start attaching the UI on the fly.
+    * See :help ui-startup for details.
+    */
+   s_nvim *const nvim = _nvim_get();
+   nvim_api_get_api_info(nvim, _api_decode_cb, NULL);
+
+   nvim_helper_autocmd_vimenter_exec(nvim);
+   const s_geometry *const geo = &nvim->opts->geometry;
+   nvim_api_ui_attach(nvim, geo->w, geo->h, _ui_attached_cb, NULL);
+
+
    return ECORE_CALLBACK_PASS_ON;
 }
 
@@ -438,6 +464,7 @@ _nvim_received_error_cb(void *data EINA_UNUSED,
    return ECORE_CALLBACK_PASS_ON;
 }
 
+/* FIXME this is soooooo fragile */
 static void
 _nvim_runtime_load(s_nvim *nvim,
                    const char *filename)
@@ -653,16 +680,6 @@ _api_decode_cb(s_nvim *nvim, void *data EINA_UNUSED, const msgpack_object *resul
   _virtual_interface_setup(nvim);
 }
 
-static void
-_vimenter_cb(s_nvim *nvim,
-             void *data EINA_UNUSED,
-             const msgpack_object *result EINA_UNUSED)
-{
-  _nvim_builtin_runtime_load(nvim);
-  _nvim_eovimrc_load(nvim);
-  nvim_api_var_integer_set(nvim, "eovim_running", 1);
-}
-
 static void
 _nvim_plugins_load(s_nvim *nvim)
 {
@@ -815,6 +832,9 @@ nvim_new(const s_options *opts,
    /* Initialize the virtual interface to safe values (non-NULL pointers) */
    _virtual_interface_init(nvim);
 
+   /* Add a callback to the vimenter request */
+   nvim_request_add("vimenter", _vimenter_request_cb);
+
    /* Create the neovim process */
    nvim->exe = ecore_exe_pipe_run(
       eina_strbuf_string_get(cmdline),
@@ -831,9 +851,10 @@ nvim_new(const s_options *opts,
    DBG("Running %s", eina_strbuf_string_get(cmdline));
    eina_strbuf_free(cmdline);
 
-   nvim_api_get_api_info(nvim, _api_decode_cb, NULL);
-   nvim_helper_autocmd_vimenter_exec(nvim, _vimenter_cb, NULL);
-   nvim_api_ui_attach(nvim, opts->geometry.w, opts->geometry.h);
+   /* FIXME These are sooo fragile. Rework that!!! */
+   _nvim_builtin_runtime_load(nvim);
+   _nvim_eovimrc_load(nvim);
+   nvim_api_var_integer_set(nvim, "eovim_running", 1);
 
    /* Create the GUI window */
    if (EINA_UNLIKELY(! gui_add(&nvim->gui, nvim)))
diff --git a/src/nvim_api.c b/src/nvim_api.c
index 8082352..cf93577 100644
--- a/src/nvim_api.c
+++ b/src/nvim_api.c
@@ -138,8 +138,8 @@ void nvim_api_request_call(s_nvim *nvim,
 
 Eina_Bool
 nvim_api_ui_attach(s_nvim *nvim,
-                   unsigned int width,
-                   unsigned int height)
+                   unsigned int width, unsigned int height,
+                   f_nvim_api_cb func, void *func_data)
 {
    const char api[] = "nvim_ui_attach";
    s_request *const req = _request_new(nvim, api, sizeof(api) - 1);
@@ -148,6 +148,8 @@ nvim_api_ui_attach(s_nvim *nvim,
         CRI("Failed to create request");
         return EINA_FALSE;
      }
+   req->cb.func = func;
+   req->cb.data = func_data;
 
    const s_config *const cfg = nvim->config;
 
diff --git a/src/nvim_helper.c b/src/nvim_helper.c
index 7199203..2ec09fb 100644
--- a/src/nvim_helper.c
+++ b/src/nvim_helper.c
@@ -134,11 +134,11 @@ nvim_helper_autocmd_do(s_nvim *nvim,
 }
 
 void
-nvim_helper_autocmd_vimenter_exec(s_nvim *nvim, f_nvim_api_cb func, void *func_data)
+nvim_helper_autocmd_vimenter_exec(s_nvim *nvim)
 {
   const char cmd[] = "autocmd VimEnter * call rpcrequest(1, 'vimenter')";
   const Eina_Bool ok =
-    nvim_api_command(nvim, cmd, sizeof(cmd) - 1u, func, func_data);
+    nvim_api_command(nvim, cmd, sizeof(cmd) - 1u, NULL, NULL);
   if (EINA_UNLIKELY(! ok))
   { ERR("Failed to execute: %s", cmd); }
 }