This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_plugin.d
59 lines (46 loc) · 1.46 KB
/
demo_plugin.d
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
import nvimhost.plugin;
import nvimhost.api;
struct DemoPlugin {
NvimAPI nvim;
this(ref NvimAPI nvim) {
this.nvim = nvim;
}
// sync function with one argument
@NvimFunc("Greet")
string greet(string name) {
return "Hello " ~ name;
}
// sync function with multiple arguments
@NvimFunc("SumBeginToEnd")
int sumBeginToEnd(int begin, int end) {
import std.range;
import std.algorithm.iteration;
import std.stdio;
return cast(int) iota(begin, end).sum();
}
// sync function calling async (non blocking) nvim functions
@NvimFunc("SetVarValueSync")
int setVarValue(int i) {
import std.conv;
nvim.commandAsync("let g:test_var_value=" ~ i.to!string);
return i;
}
// async function calling both async and sync nvim functions
@NvimFunc("SetVarValueAsync", Async)
void setVarValueAsync(int i) {
import std.conv;
nvim.commandAsync("let g:testasync_var_value=" ~ i.to!string);
nvim.command("echomsg 'hello world sync!'");
}
}
void main() {
// make sure you source this .vim file in neovim, since this will bootstrap
// the binary and register the plugin
auto pluginDstFile = "~/.config/nvim/settings/demo-plugin.vim";
// template instantiate DemoPlugin
auto plugin = NvimPlugin!(DemoPlugin)("demo-plugin", pluginDstFile);
// keep it running
scope (exit) {
plugin.keepRunning();
}
}