nvim_api/
lib.rs

1//! This module contains the bindings to the [Neovim
2//! API](https://neovim.io/doc/user/api.html), exposed in Lua through the
3//! `vim.api` table.
4//!
5//! # Naming convention
6//!
7//! All the functions have been renamed by dropping the leading `nvim_` prefix,
8//! e.g. `nvim_get_current_buf` simply becomes [`get_current_buf`].
9//!
10//! Also, the functions starting with `nvim_buf_*`, `nvim_win_*` and
11//! `nvim_tabpage_*` are implemented as methods on the [`Buffer`], [`Window`]
12//! and [`TabPage`] objects respectively.
13
14mod autocmd;
15mod buffer;
16mod error;
17mod extmark;
18mod ffi;
19mod global;
20pub(crate) mod iterator;
21pub mod opts;
22pub(crate) mod serde_utils;
23mod tabpage;
24mod trait_utils;
25pub mod types;
26pub(crate) mod utils;
27mod vimscript;
28mod win_config;
29mod window;
30
31pub use autocmd::*;
32pub use buffer::*;
33pub use error::Error;
34use error::Result;
35pub use extmark::*;
36pub use global::*;
37pub use tabpage::*;
38pub use trait_utils::*;
39pub use vimscript::*;
40pub use win_config::*;
41pub use window::*;
42
43// https://github.com/neovim/neovim/blob/master/src/nvim/api/private/defs.h#L41
44const INTERNAL_CALL_MASK: u64 = 1u64 << (std::mem::size_of::<u64>() * 8 - 1);
45
46// https://github.com/neovim/neovim/blob/master/src/nvim/api/private/defs.h#L44
47const VIML_INTERNAL_CALL: u64 = INTERNAL_CALL_MASK;
48
49// https://github.com/neovim/neovim/blob/master/src/nvim/api/private/defs.h#L47
50const LUA_INTERNAL_CALL: u64 = VIML_INTERNAL_CALL + 1;
51
52macro_rules! choose {
53    ($err:expr, ()) => {
54        if $err.is_err() {
55            Err($err.into())
56        } else {
57            Ok(())
58        }
59    };
60
61    ($err:expr, $other:expr) => {
62        if $err.is_err() {
63            Err($err.into())
64        } else {
65            $other
66        }
67    };
68}
69
70pub(crate) use choose;