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
//! # Semi-direct mapping of the `vim` module in Neovim's lua api
//!
//! The goal for this module is to provide an idiomatic way to call Neovim's lua api from Rust, without needing to repeat the boilerplate for loading specific functions.
//!
//! Notable differences from the lua api:
//! - `vim.fn` has been renamed to `vim::func`, since fn is a keyword in Rust
//! - Added `vim::ext` for functions that don't directly map to the Neovim api but make use of it or extend it
//! - Not all functions are implemented yet
use crate*;
/// Get global `vim`
///
/// ## Example
/// ```rust
/// use nvim_utils::prelude::*;
/// fn my_module(lua: &mlua::prelude::Lua) -> mlua::prelude::LuaResult<()> {
/// let global_vim = vim::get(lua)?;
/// let vim_version: LuaTable = global_vim.call_function("version", ())?;
/// println!("Vim version: {}", vim::inspect(lua, vim_version)?);
/// Ok(())
/// }
/// ```
/// Corresponds to `vim.cmd()`
///
/// ## Example
/// ```rust
/// use nvim_utils::prelude::*;
/// fn my_module(lua: &mlua::prelude::Lua) -> mlua::prelude::LuaResult<()> {
/// vim::cmd(lua, "echo 'Hello, world!'")?;
/// vim::cmd(lua, "terminal")
/// }
/// ```
/// Corresponds to `vim.inspect()`
///
/// ## Example
/// ```rust
/// use nvim_utils::prelude::*;
/// fn my_module(lua: &Lua) -> LuaResult<()> {
/// let table = lua.create_table()?;
/// table.set("foo", "bar")?;
/// let inspect = vim::inspect(lua, table)?;
/// Ok(())
/// }
/// ```
/// Corresponds to `vim.notify()`
///
/// ## Example
/// ```rust
/// use nvim_utils::prelude::*;
/// fn my_module(lua: &mlua::prelude::Lua) -> mlua::prelude::LuaResult<()> {
/// vim::notify(lua, "Loaded module!", vim::log::LogLevel::Info)
/// }
/// ```