1use types::conversion::{FromObject, ToObject};
2
3use crate::choose;
4use crate::ffi::deprecated::*;
5use crate::types::*;
6use crate::Result;
7use crate::LUA_INTERNAL_CALL;
8use crate::{Buffer, Window};
9
10#[cfg_attr(
17 feature = "neovim-nightly",
18 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.non_owning(), 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-nightly",
40 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-nightly",
59 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.non_owning(),
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-nightly",
82 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 {
91 nvim_get_option(
92 name.non_owning(),
93 #[cfg(not(feature = "neovim-0-10"))] types::arena(),
95 &mut err,
96 )
97 };
98 choose!(err, Ok(Opt::from_object(obj)?))
99}
100
101#[cfg_attr(
107 feature = "neovim-nightly",
108 deprecated(since = "0.5.0", note = "use `get_option_info2` instead")
109)]
110pub fn get_option_info(name: &str) -> Result<OptionInfos> {
111 let name = types::String::from(name);
112 let mut err = types::Error::new();
113 let obj = unsafe {
114 nvim_get_option_info(
115 name.non_owning(),
116 #[cfg(feature = "neovim-0-10")] types::arena(),
118 &mut err,
119 )
120 };
121 choose!(err, Ok(OptionInfos::from_object(obj.into())?))
122}
123
124#[cfg_attr(
130 feature = "neovim-nightly",
131 deprecated(since = "0.5.0", note = "use `set_option_value` instead")
132)]
133pub fn set_option<Opt>(name: &str, value: Opt) -> Result<()>
134where
135 Opt: ToObject,
136{
137 let name = types::String::from(name);
138 let mut err = types::Error::new();
139 unsafe {
140 nvim_set_option(
141 LUA_INTERNAL_CALL,
142 name.non_owning(),
143 value.to_object()?.non_owning(),
144 &mut err,
145 )
146 };
147 choose!(err, ())
148}
149
150impl Buffer {
151 #[cfg_attr(
157 feature = "neovim-nightly",
158 deprecated(since = "0.5.0", note = "use `get_option_value` instead")
159 )]
160 pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
161 where
162 Opt: FromObject,
163 {
164 let mut err = types::Error::new();
165 let name = types::String::from(name);
166 let obj = unsafe {
167 nvim_buf_get_option(
168 self.0,
169 name.non_owning(),
170 #[cfg(not(feature = "neovim-0-10"))] types::arena(),
172 &mut err,
173 )
174 };
175 choose!(err, Ok(Opt::from_object(obj)?))
176 }
177
178 #[cfg_attr(
185 feature = "neovim-nightly",
186 deprecated(since = "0.5.0", note = "use `set_option_value` instead")
187 )]
188 pub fn set_option<V>(&mut self, name: &str, value: V) -> Result<()>
189 where
190 V: ToObject,
191 {
192 let mut err = types::Error::new();
193 let name = types::String::from(name);
194 unsafe {
195 nvim_buf_set_option(
196 LUA_INTERNAL_CALL,
197 self.0,
198 name.non_owning(),
199 value.to_object()?.non_owning(),
200 &mut err,
201 )
202 };
203 choose!(err, ())
204 }
205}
206
207impl Window {
208 #[cfg_attr(
214 feature = "neovim-nightly",
215 deprecated(since = "0.5.0", note = "use `get_option_value` instead")
216 )]
217 pub fn get_option<Opt>(&self, name: &str) -> Result<Opt>
218 where
219 Opt: FromObject,
220 {
221 let mut err = types::Error::new();
222 let name = types::String::from(name);
223 let obj = unsafe {
224 nvim_win_get_option(
225 self.0,
226 name.non_owning(),
227 #[cfg(not(feature = "neovim-0-10"))] types::arena(),
229 &mut err,
230 )
231 };
232 choose!(err, Ok(Opt::from_object(obj)?))
233 }
234
235 #[cfg_attr(
242 feature = "neovim-nightly",
243 deprecated(since = "0.5.0", note = "use `set_option_value` instead")
244 )]
245 pub fn set_option<Opt>(&mut self, name: &str, value: Opt) -> Result<()>
246 where
247 Opt: ToObject,
248 {
249 let mut err = types::Error::new();
250 let name = types::String::from(name);
251 unsafe {
252 nvim_win_set_option(
253 LUA_INTERNAL_CALL,
254 self.0,
255 name.non_owning(),
256 value.to_object()?.non_owning(),
257 &mut err,
258 )
259 };
260 choose!(err, ())
261 }
262}