nvim_oxi_api/
deprecated.rs1use types::conversion::{FromObject, ToObject};
2
3use crate::LUA_INTERNAL_CALL;
4use crate::Result;
5use crate::choose;
6use crate::ffi::deprecated::*;
7use crate::types::*;
8use crate::{Buffer, Window};
9
10#[cfg_attr(
17 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `exec2` instead")
19)]
20pub fn exec(src: &str, output: bool) -> Result<Option<String>> {
21 let src = types::String::from(src);
22 let mut err = types::Error::new();
23 let output = unsafe {
24 nvim_exec(LUA_INTERNAL_CALL, src.as_nvim_str(), output, &mut err)
25 };
26 choose!(err, {
27 Ok((!output.is_empty()).then(|| output.to_string_lossy().into()))
28 })
29}
30
31#[cfg_attr(
39 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_hl` instead")
41)]
42pub fn get_hl_by_id(hl_id: u32, rgb: bool) -> Result<HighlightInfos> {
43 let mut err = types::Error::new();
44
45 let hl = unsafe {
46 nvim_get_hl_by_id(hl_id.into(), rgb, core::ptr::null_mut(), &mut err)
47 };
48
49 choose!(err, Ok(HighlightInfos::from_object(hl.into())?))
50}
51
52#[cfg_attr(
58 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_hl` instead")
60)]
61pub fn get_hl_by_name(name: &str, rgb: bool) -> Result<HighlightInfos> {
62 let name = types::String::from(name);
63 let mut err = types::Error::new();
64 let hl = unsafe {
65 nvim_get_hl_by_name(
66 name.as_nvim_str(),
67 rgb,
68 core::ptr::null_mut(),
69 &mut err,
70 )
71 };
72 choose!(err, Ok(HighlightInfos::from_object(hl.into())?))
73}
74
75#[cfg_attr(
81 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_option_value` instead")
83)]
84pub fn get_option<Opt>(name: &str) -> Result<Opt>
85where
86 Opt: FromObject,
87{
88 let name = types::String::from(name);
89 let mut err = types::Error::new();
90 let obj = unsafe { nvim_get_option(name.as_nvim_str(), &mut err) };
91 choose!(err, Ok(Opt::from_object(obj)?))
92}
93
94#[cfg_attr(
100 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_option_info2` instead")
102)]
103pub fn get_option_info(name: &str) -> Result<OptionInfos> {
104 let name = types::String::from(name);
105 let mut err = types::Error::new();
106 let obj = unsafe {
107 nvim_get_option_info(name.as_nvim_str(), types::arena(), &mut err)
108 };
109 choose!(err, Ok(OptionInfos::from_object(obj.into())?))
110}
111
112#[cfg_attr(
118 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `set_option_value` instead")
120)]
121pub fn set_option<Opt>(name: &str, value: Opt) -> Result<()>
122where
123 Opt: ToObject,
124{
125 let name = types::String::from(name);
126 let mut err = types::Error::new();
127 unsafe {
128 nvim_set_option(
129 LUA_INTERNAL_CALL,
130 name.as_nvim_str(),
131 value.to_object()?.non_owning(),
132 &mut err,
133 )
134 };
135 choose!(err, ())
136}
137
138impl Buffer {
139 #[cfg_attr(
145 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_option_value` instead")
147 )]
148 pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
149 where
150 Opt: FromObject,
151 {
152 let mut err = types::Error::new();
153 let name = types::String::from(name);
154 let obj = unsafe {
155 nvim_buf_get_option(self.0, name.as_nvim_str(), &mut err)
156 };
157 choose!(err, Ok(Opt::from_object(obj)?))
158 }
159
160 #[cfg_attr(
167 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `set_option_value` instead")
169 )]
170 pub fn set_option<V>(&mut self, name: &str, value: V) -> Result<()>
171 where
172 V: ToObject,
173 {
174 let mut err = types::Error::new();
175 let name = types::String::from(name);
176 unsafe {
177 nvim_buf_set_option(
178 LUA_INTERNAL_CALL,
179 self.0,
180 name.as_nvim_str(),
181 value.to_object()?.non_owning(),
182 &mut err,
183 )
184 };
185 choose!(err, ())
186 }
187}
188
189impl Window {
190 #[cfg_attr(
196 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `get_option_value` instead")
198 )]
199 pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
200 where
201 Opt: FromObject,
202 {
203 let mut err = types::Error::new();
204 let name = types::String::from(name);
205 let obj = unsafe {
206 nvim_win_get_option(self.0, name.as_nvim_str(), &mut err)
207 };
208 choose!(err, Ok(Opt::from_object(obj)?))
209 }
210
211 #[cfg_attr(
218 feature = "neovim-0-11", deprecated(since = "0.5.0", note = "use `set_option_value` instead")
220 )]
221 pub fn set_option<Opt>(&mut self, name: &str, value: Opt) -> Result<()>
222 where
223 Opt: ToObject,
224 {
225 let mut err = types::Error::new();
226 let name = types::String::from(name);
227 unsafe {
228 nvim_win_set_option(
229 LUA_INTERNAL_CALL,
230 self.0,
231 name.as_nvim_str(),
232 value.to_object()?.non_owning(),
233 &mut err,
234 )
235 };
236 choose!(err, ())
237 }
238}