nvim_oxi_api/
deprecated.rs

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/// Binding to [`nvim_exec()`][1].
11///
12/// Executes a multiline block of Ex commands. If `output` is true the
13/// output is captured and returned.
14///
15/// [1]: https://neovim.io/doc/user/api.html#nvim_exec()
16#[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/// Binding to [`nvim_get_hl_by_id()`][1].
32///
33/// Gets a highlight definition by id.
34///
35/// [1]: https://neovim.io/doc/user/api.html#nvim_get_hl_by_id[1]
36///
37/// [1]: https://neovim.io/doc/user/api.html#nvim_get_current_win()
38#[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/// Binding to [`nvim_get_hl_by_name()`][1].
53///
54/// Gets a highlight definition by name.
55///
56/// [1]: https://neovim.io/doc/user/api.html#nvim_get_hl_by_name()
57#[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/// Binding to [`nvim_get_option()`][1].
76///
77/// Gets the value of a global option.
78///
79/// [1]: https://neovim.io/doc/user/api.html#nvim_get_option()
80#[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"))] // 0nly on 0.9.
94            types::arena(),
95            &mut err,
96        )
97    };
98    choose!(err, Ok(Opt::from_object(obj)?))
99}
100
101/// Binding to [`nvim_get_option_info()`][1].
102///
103/// Gets all the informations related to an option.
104///
105/// [1]: https://neovim.io/doc/user/api.html#nvim_get_option_info()
106#[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")] // On 0.10 and nightly.
117            types::arena(),
118            &mut err,
119        )
120    };
121    choose!(err, Ok(OptionInfos::from_object(obj.into())?))
122}
123
124/// Binding to [`nvim_set_option()`][1].
125///
126/// Sets the global value of an option.
127///
128/// [1]: https://neovim.io/doc/user/api.html#nvim_set_option()
129#[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    /// Binding to [`nvim_buf_get_option()`][1].
152    ///
153    /// Gets a buffer option value.
154    ///
155    /// [1]: https://neovim.io/doc/user/api.html#nvim_buf_get_option()
156    #[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"))] // 0nly on 0.9.
171                types::arena(),
172                &mut err,
173            )
174        };
175        choose!(err, Ok(Opt::from_object(obj)?))
176    }
177
178    /// Binding to [`nvim_buf_set_option()`][1].
179    ///
180    /// Sets a buffer option value. Passing `None` as value deletes the option
181    /// (only works if there's a global fallback).
182    ///
183    /// [1]: https://neovim.io/doc/user/api.html#nvim_buf_set_option()
184    #[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    /// Binding to [`nvim_win_get_option()`][1].
209    ///
210    /// Gets a window option value.
211    ///
212    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_option()
213    #[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"))] // 0nly on 0.9.
228                types::arena(),
229                &mut err,
230            )
231        };
232        choose!(err, Ok(Opt::from_object(obj)?))
233    }
234
235    /// Binding to [`nvim_win_set_option()`][1].
236    ///
237    /// Sets a window option value. Passing `None` as value deletes the option
238    /// (only works if there's a global fallback).
239    ///
240    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_set_option()
241    #[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}