Skip to content

Commit eeb21cd

Browse files
committed
Update sampple plugin to use 0.1.0 neovim-client
1 parent d56da6d commit eeb21cd

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,18 @@ neovim-client.nvim=> (api/command ":echo 'Hello Neovim!'")
4040

4141
[![Repling Neovim](http://img.youtube.com/vi/g-9DdVwbSTo/0.jpg)](https://www.youtube.com/watch?v=g-9DdVwbSTo)
4242

43-
### Sample Plugins
43+
### Examples
4444

45-
Several sample plugins -- consumers of neovim-client -- are included.
45+
#### Included Sample Plugin
4646

47-
#### Installation
47+
##### Installation
4848

49-
While these plugins can be installed locally, the easiest thing to do is to
50-
run them from the repl, as described above. Simply use `lein repl` from the
51-
plugin project's root directory.
49+
One way to install the sample plugin is by running `./deploy-local.sh` script,
50+
included, which copies the sample plugin to `~/.vim/bundle`, and then ensure
51+
Neovim's runtimepath is set correctly by adding `set
52+
runtimepath^=~/.vim/bundle/sample-plugin` to `.vimrc`.
5253

53-
#### Simple Plugin
54-
55-
```
56-
:call RunSamplePluginSimple()
57-
```
58-
59-
#### Count Plugin
54+
##### Running
6055

6156
This plugin stays running, and maintains state. Additionally, it shows how
6257
plugins are actually servers, which Neovim can make requests to via

sample-plugin/deploy-local.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lein uberjar
2+
cp target/uberjar/sample-plugin-0.1.0-standalone.jar .
3+
rm -rf ~/.vim/bundle/sample-plugin
4+
cd ..
5+
cp -rf sample-plugin ~/.vim/bundle

sample-plugin/plugin/sample.vim

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
let s:p_dir = expand('<sfile>:p:h')
2-
let g:is_running = 0
3-
let g:channel = -1
2+
let g:sample_is_running = 0
3+
let g:nvim_tcp_plugin_channel = 0
44

5-
function! StartIfNotRunning()
6-
if g:is_running == 0
5+
function! SampleStartIfNotRunning()
6+
if g:sample_is_running == 0
77
echo 'starting plugin...'
8-
"TODO - This is a dirty hack. We should launch things without changing
9-
"the working directory.
10-
exec ':cd ' . s:p_dir
11-
let g:channel = rpcstart('lein', ['run'])
12-
let g:is_running = 1
8+
let jar_file_path = s:p_dir . '/../' . 'sample-plugin-0.1.0-standalone.jar'
9+
call jobstart(['java', '-jar', jar_file_path], {'rpc': v:true})
10+
let g:sample_is_running = 1
1311
endif
1412
endfunction
1513

1614
function! SamplePluginCount()
17-
call StartIfNotRunning()
18-
let res = rpcrequest(g:channel, 'count', [])
15+
call SampleStartIfNotRunning()
16+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'count', [])
1917
return res
2018
endfunction
2119

sample-plugin/project.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
(defproject sample-plugin "0.1.0-SNAPSHOT"
2-
:description "FIXME: write description"
3-
:url "http://example.com/FIXME"
1+
(defproject sample-plugin "0.1.0"
2+
:description "Sample Neovim plugin"
3+
:url "https://github.com/clojure-vim/neovim-client"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/clojure "1.6.0"]
7-
[neovim-client "0.1.0-SNAPSHOT"]]
6+
:dependencies [[org.clojure/clojure "1.8.0"]
7+
[neovim-client "0.1.0"]]
88
:main ^:skip-aot sample-plugin.core
99
:target-path "target/%s"
1010
:profiles {:uberjar {:aot :all}})
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
(ns sample-plugin.core
2-
(:require [neovim-client.nvim :as nvim])
2+
(:require
3+
[neovim-client.1.api :as api]
4+
[neovim-client.nvim :as nvim])
35
(:gen-class))
46

57
(defn -main
68
[& args]
7-
(let [nvim (nvim/new)
9+
(let [nvim (nvim/new 1)
810
x (atom 0)]
911
(nvim/register-method!
1012
nvim
1113
"count"
1214
(fn [msg]
1315
;; Plugin can call back to nvim if it wants to, while
1416
;; its doing its own thing.
15-
(nvim/vim-command-async nvim
16-
":echo 'incrementing'"
17-
(fn [_] nil))
1817
(swap! x inc)
19-
@x))
18+
(api/command-async nvim
19+
(format ":echo 'incrementing ... %s'" @x)
20+
(fn [_] nil))))
2021

2122
;; Stay alive for a minute!
2223
(dotimes [n 60]
2324
(if (= 0 (mod n 10))
24-
(nvim/vim-command nvim (str ":echo 'plugin alive for " n " seconds.'")))
25+
(api/command nvim (str ":echo 'plugin alive for " n " seconds.'")))
2526
(Thread/sleep 1000))
2627

2728
;; Let nvim know we're shutting down.
28-
(nvim/vim-command nvim ":let g:is_running=0")
29-
(nvim/vim-command nvim ":echo 'plugin stopping.'")))
29+
(api/command nvim ":let g:is_running=0")
30+
(api/command nvim ":echo 'plugin stopping.'")))

0 commit comments

Comments
 (0)