use types::conversion::{FromObject, ToObject};
use crate::choose;
use crate::ffi::deprecated::*;
use crate::types::*;
use crate::Result;
use crate::LUA_INTERNAL_CALL;
use crate::{Buffer, Window};
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `exec2` instead")
)]
pub fn exec(src: &str, output: bool) -> Result<Option<String>> {
let src = types::String::from(src);
let mut err = types::Error::new();
let output = unsafe {
nvim_exec(LUA_INTERNAL_CALL, src.non_owning(), output, &mut err)
};
choose!(err, {
Ok((!output.is_empty()).then(|| output.to_string_lossy().into()))
})
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_hl` instead")
)]
pub fn get_hl_by_id(hl_id: u32, rgb: bool) -> Result<HighlightInfos> {
let mut err = types::Error::new();
let hl = unsafe {
nvim_get_hl_by_id(hl_id.into(), rgb, core::ptr::null_mut(), &mut err)
};
choose!(err, Ok(HighlightInfos::from_object(hl.into())?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_hl` instead")
)]
pub fn get_hl_by_name(name: &str, rgb: bool) -> Result<HighlightInfos> {
let name = types::String::from(name);
let mut err = types::Error::new();
let hl = unsafe {
nvim_get_hl_by_name(
name.non_owning(),
rgb,
core::ptr::null_mut(),
&mut err,
)
};
choose!(err, Ok(HighlightInfos::from_object(hl.into())?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_option_value` instead")
)]
pub fn get_option<Opt>(name: &str) -> Result<Opt>
where
Opt: FromObject,
{
let name = types::String::from(name);
let mut err = types::Error::new();
let obj = unsafe {
nvim_get_option(
name.non_owning(),
#[cfg(not(feature = "neovim-0-10"))] types::arena(),
&mut err,
)
};
choose!(err, Ok(Opt::from_object(obj)?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_option_info2` instead")
)]
pub fn get_option_info(name: &str) -> Result<OptionInfos> {
let name = types::String::from(name);
let mut err = types::Error::new();
let obj = unsafe {
nvim_get_option_info(
name.non_owning(),
#[cfg(feature = "neovim-0-10")] types::arena(),
&mut err,
)
};
choose!(err, Ok(OptionInfos::from_object(obj.into())?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `set_option_value` instead")
)]
pub fn set_option<Opt>(name: &str, value: Opt) -> Result<()>
where
Opt: ToObject,
{
let name = types::String::from(name);
let mut err = types::Error::new();
unsafe {
nvim_set_option(
LUA_INTERNAL_CALL,
name.non_owning(),
value.to_object()?.non_owning(),
&mut err,
)
};
choose!(err, ())
}
impl Buffer {
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_option_value` instead")
)]
pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
where
Opt: FromObject,
{
let mut err = types::Error::new();
let name = types::String::from(name);
let obj = unsafe {
nvim_buf_get_option(
self.0,
name.non_owning(),
#[cfg(not(feature = "neovim-0-10"))] types::arena(),
&mut err,
)
};
choose!(err, Ok(Opt::from_object(obj)?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `set_option_value` instead")
)]
pub fn set_option<V>(&mut self, name: &str, value: V) -> Result<()>
where
V: ToObject,
{
let mut err = types::Error::new();
let name = types::String::from(name);
unsafe {
nvim_buf_set_option(
LUA_INTERNAL_CALL,
self.0,
name.non_owning(),
value.to_object()?.non_owning(),
&mut err,
)
};
choose!(err, ())
}
}
impl Window {
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `get_option_value` instead")
)]
pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
where
Opt: FromObject,
{
let mut err = types::Error::new();
let name = types::String::from(name);
let obj = unsafe {
nvim_win_get_option(
self.0,
name.non_owning(),
#[cfg(not(feature = "neovim-0-10"))] types::arena(),
&mut err,
)
};
choose!(err, Ok(Opt::from_object(obj)?))
}
#[cfg_attr(
feature = "neovim-nightly",
deprecated(since = "0.5.0", note = "use `set_option_value` instead")
)]
pub fn set_option<Opt>(&mut self, name: &str, value: Opt) -> Result<()>
where
Opt: ToObject,
{
let mut err = types::Error::new();
let name = types::String::from(name);
unsafe {
nvim_win_set_option(
LUA_INTERNAL_CALL,
self.0,
name.non_owning(),
value.to_object()?.non_owning(),
&mut err,
)
};
choose!(err, ())
}
}