|
6 | 6 | [clojure.java.io :as io] |
7 | 7 | [clojure.string :as string] |
8 | 8 | [clojure.tools.logging :as log] |
| 9 | + [neovim-client.1.api :as api] |
| 10 | + [neovim-client.1.api.buffer :as api.buffer] |
| 11 | + [neovim-client.1.api.buffer-ext :as api.buffer-ext] |
| 12 | + [neovim-client.1.api-ext :as api-ext] |
9 | 13 | [neovim-client.message :as message] |
10 | 14 | [neovim-client.nvim :as nvim] |
11 | 15 | [socket-repl.nrepl :as nrepl] |
|
49 | 53 | (if-not (or (socket-repl/connected? socket-repl) |
50 | 54 | (nrepl/connected? nrepl)) |
51 | 55 | (async/thread |
52 | | - (nvim/vim-command |
| 56 | + (api/command |
53 | 57 | nvim ":echo 'Use :Connect host:port to connect to a socket repl'")) |
54 | 58 | (async/thread (f msg))) |
55 | 59 | ;; Don't return an async channel, return something msg-pack can serialize. |
|
58 | 62 | (defn get-rlog-buffer |
59 | 63 | "Returns the buffer w/ b:rlog set, if one exists." |
60 | 64 | [nvim] |
61 | | - (some->> (nvim/vim-get-buffers nvim) |
62 | | - (filter #(nvim/buffer-get-var nvim % "rlog")) |
| 65 | + (some->> (api/list-bufs nvim) |
| 66 | + (filter #(api.buffer/get-var nvim % "rlog")) |
63 | 67 | first)) |
64 | 68 |
|
65 | 69 | (defn get-rlog-buffer-name |
66 | 70 | "Returns the name of the buffer w/ b:rlog set, if one exists." |
67 | 71 | [nvim] |
68 | 72 | (let [buffer (get-rlog-buffer nvim)] |
69 | | - (when buffer (nvim/buffer-get-name nvim buffer)))) |
| 73 | + (when buffer (api.buffer/get-name nvim buffer)))) |
70 | 74 |
|
71 | 75 | (defn get-rlog-buffer-number |
72 | 76 | "Returns the number of the buffer w/ b:rlog set, if one exists." |
73 | 77 | [nvim] |
74 | 78 | (let [buffer (get-rlog-buffer nvim)] |
75 | | - (when buffer (nvim/buffer-get-number nvim buffer)))) |
| 79 | + (when buffer (api.buffer/get-number nvim buffer)))) |
76 | 80 |
|
77 | 81 | (defn code-channel |
78 | 82 | [plugin] |
|
102 | 106 | (socket-repl/connect socket-repl host port) |
103 | 107 | (catch Throwable t |
104 | 108 | (log/error t "Error connecting to socket repl") |
105 | | - (async/thread (nvim/vim-command |
| 109 | + (async/thread (api/command |
106 | 110 | nvim |
107 | 111 | ":echo 'Unable to connect to socket repl.'")))) |
108 | 112 | :done))) |
|
120 | 124 | (nrepl/connect nrepl host port) |
121 | 125 | (catch Throwable t |
122 | 126 | (log/error t "Error connecting to nrepl") |
123 | | - (async/thread (nvim/vim-command |
| 127 | + (async/thread (api/command |
124 | 128 | nvim |
125 | 129 | ":echo 'Unable to connect to nrepl.'")))) |
126 | 130 | :done))) |
|
131 | 135 | (run-command |
132 | 136 | plugin |
133 | 137 | (fn [msg] |
134 | | - (let [coords (nvim/get-cursor-location nvim) |
135 | | - buffer-text (nvim/get-current-buffer-text nvim)] |
| 138 | + (let [coords (api-ext/get-cursor-location nvim) |
| 139 | + buffer-text (api-ext/get-current-buffer-text nvim)] |
136 | 140 | (try |
137 | 141 | (async/>!! code-channel (get-form-at buffer-text coords)) |
138 | 142 | (catch Throwable t |
|
145 | 149 | (run-command |
146 | 150 | plugin |
147 | 151 | (fn [msg] |
148 | | - (let [buffer (nvim/vim-get-current-buffer nvim) |
149 | | - filename (nvim/buffer-get-name nvim buffer)] |
| 152 | + (let [buffer (api/get-current-buf nvim) |
| 153 | + filename (api.buffer/get-name nvim buffer)] |
150 | 154 | (if (.exists (io/as-file filename)) |
151 | 155 | (do |
152 | 156 | ;; Not sure if saving the file is really always what we want, |
153 | 157 | ;; but if we don't, stale data will be loaded. |
154 | | - (nvim/vim-command nvim ":w") |
| 158 | + (api/command nvim ":w") |
155 | 159 | (async/>!! code-channel (format "(load-file \"%s\")" filename))) |
156 | | - (let [code (string/join "\n" (nvim/buffer-get-line-slice |
| 160 | + (let [code (string/join "\n" (api.buffer-ext/get-lines |
157 | 161 | nvim buffer 0 -1))] |
158 | 162 | (async/>!! code-channel (format "(eval '(do %s))" code)))))))) |
159 | 163 |
|
|
163 | 167 | (run-command |
164 | 168 | plugin |
165 | 169 | (fn [msg] |
166 | | - (nvim/get-current-word-async |
| 170 | + (api-ext/get-current-word-async |
167 | 171 | nvim |
168 | 172 | (fn [word] |
169 | 173 | (let [code (format "(clojure.repl/doc %s)" word)] |
|
176 | 180 | plugin |
177 | 181 | (fn [msg] |
178 | 182 | (let [file (-> repl-log repl-log/file .getAbsolutePath)] |
179 | | - (let [original-window (nvim/vim-get-current-window nvim) |
| 183 | + (let [original-window (api/get-current-win nvim) |
180 | 184 | buffer-cmd (first (message/params msg)) |
181 | 185 | rlog-buffer (get-rlog-buffer-name nvim) |
182 | 186 | rlog-buffer-visible? (when rlog-buffer |
183 | | - (async/<!! (nvim/buffer-visible?-async |
184 | | - nvim rlog-buffer)))] |
| 187 | + (async/<!! |
| 188 | + (api-ext/buffer-visible?-async |
| 189 | + nvim rlog-buffer)))] |
185 | 190 | (when-not rlog-buffer-visible? |
186 | | - (nvim/vim-command |
| 191 | + (api/command |
187 | 192 | nvim |
188 | 193 | (format "%s | nnoremap <buffer> q :q<cr> | :let b:rlog=1 | :call termopen('tail -f %s') | :set ft=clojurerepl" |
189 | 194 | buffer-cmd file)) |
190 | | - (nvim/vim-set-current-window nvim original-window))))))) |
| 195 | + (api/set-current-win nvim original-window))))))) |
191 | 196 |
|
192 | 197 | (nvim/register-method! |
193 | 198 | nvim |
194 | 199 | "dismiss-log" |
195 | 200 | (run-command |
196 | 201 | plugin |
197 | 202 | (fn [msg] |
198 | | - (nvim/vim-command |
| 203 | + (api/command |
199 | 204 | nvim (format "bd! %s" (get-rlog-buffer-number nvim)))))) |
200 | 205 |
|
201 | 206 | (async/thread |
202 | | - (nvim/vim-command nvim "let g:socket_repl_plugin_ready = 1") |
203 | | - (nvim/vim-command nvim "echo 'SocketREPL plugin ready'")) |
| 207 | + (api/command nvim "let g:socket_repl_plugin_ready = 1") |
| 208 | + (api/command nvim "echo 'SocketREPL plugin ready'")) |
204 | 209 |
|
205 | 210 | plugin)) |
206 | 211 |
|
|
210 | 215 | "plugin" |
211 | 216 |
|
212 | 217 | ;; Close the repl log buffer |
213 | | - (nvim/vim-command |
| 218 | + (api/command |
214 | 219 | nvim (format "bd! %s" (get-rlog-buffer-number nvim))) |
215 | 220 |
|
216 | 221 | (async/close! (:code-channel plugin)) |
|
0 commit comments