nvim_oxi_api/
vimscript.rs1use types::{self as nvim, conversion::FromObject, Array, Object};
2
3use crate::choose;
4use crate::ffi::vimscript::*;
5#[cfg(feature = "neovim-0-10")] use crate::opts::ExecOpts;
7use crate::types::*;
8use crate::Result;
9
10pub fn call_dict_function<Args, Ret>(
17 dict: &str,
18 func: &str,
19 args: Args,
20) -> Result<Ret>
21where
22 Args: Into<Array>,
23 Ret: FromObject,
24{
25 let dict = Object::from(nvim::String::from(dict));
26 let func = nvim::String::from(func);
27 let args = args.into();
28 let mut err = nvim::Error::new();
29 let res = unsafe {
30 nvim_call_dict_function(
31 dict.non_owning(),
32 func.non_owning(),
33 args.non_owning(),
34 #[cfg(feature = "neovim-0-10")] types::arena(),
36 &mut err,
37 )
38 };
39 choose!(err, Ok(Ret::from_object(res)?))
40}
41
42pub fn call_function<Args, Ret>(func: &str, args: Args) -> Result<Ret>
49where
50 Args: Into<Array>,
51 Ret: FromObject,
52{
53 let func = nvim::String::from(func);
54 let args = args.into();
55 let mut err = nvim::Error::new();
56 let res = unsafe {
57 nvim_call_function(
58 func.non_owning(),
59 args.non_owning(),
60 #[cfg(feature = "neovim-0-10")] types::arena(),
62 &mut err,
63 )
64 };
65 choose!(err, Ok(Ret::from_object(res)?))
66}
67
68pub fn command(command: &str) -> Result<()> {
74 let command = nvim::String::from(command);
75 let mut err = nvim::Error::new();
76 unsafe { nvim_command(command.non_owning(), &mut err) };
77 choose!(err, ())
78}
79
80pub fn eval<V>(expr: &str) -> Result<V>
86where
87 V: FromObject,
88{
89 let expr = nvim::String::from(expr);
90 let mut err = nvim::Error::new();
91 let output = unsafe {
92 nvim_eval(
93 expr.non_owning(),
94 #[cfg(feature = "neovim-0-10")] types::arena(),
96 &mut err,
97 )
98 };
99 choose!(err, Ok(V::from_object(output)?))
100}
101
102#[cfg(feature = "neovim-0-10")] #[cfg_attr(
112 docsrs,
113 doc(cfg(any(feature = "neovim-0-10", feature = "neovim-nightly")))
114)]
115pub fn exec2(src: &str, opts: &ExecOpts) -> Result<Option<nvim::String>> {
116 let src = types::String::from(src);
117 let mut err = types::Error::new();
118 let dict = unsafe {
119 nvim_exec2(crate::LUA_INTERNAL_CALL, src.non_owning(), opts, &mut err)
120 };
121 choose!(err, {
122 Ok(dict
123 .into_iter()
124 .next()
125 .map(|(_s, output)| nvim::String::from_object(output).unwrap()))
126 })
127}
128
129pub fn parse_expression(
135 expr: &str,
136 flags: &str,
137 include_highlight: bool,
138) -> Result<ParsedVimLExpression> {
139 let expr = nvim::String::from(expr);
140 let flags = nvim::String::from(flags);
141 let mut err = nvim::Error::new();
142 let dict = unsafe {
143 nvim_parse_expression(
144 expr.non_owning(),
145 flags.non_owning(),
146 include_highlight,
147 #[cfg(feature = "neovim-0-10")] types::arena(),
149 &mut err,
150 )
151 };
152 choose!(err, Ok(ParsedVimLExpression::from_object(dict.into())?))
153}