nvim_oxi_api/
deprecated.rs

1use 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/// 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-0-11", // On 0.11 and 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.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/// 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-0-11", // On 0.11 and 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-0-11", // On 0.11 and 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.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/// 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-0-11", // On 0.11 and 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 { nvim_get_option(name.as_nvim_str(), &mut err) };
91    choose!(err, Ok(Opt::from_object(obj)?))
92}
93
94/// Binding to [`nvim_get_option_info()`][1].
95///
96/// Gets all the informations related to an option.
97///
98/// [1]: https://neovim.io/doc/user/api.html#nvim_get_option_info()
99#[cfg_attr(
100    feature = "neovim-0-11", // On 0.11 and Nightly.
101    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/// Binding to [`nvim_set_option()`][1].
113///
114/// Sets the global value of an option.
115///
116/// [1]: https://neovim.io/doc/user/api.html#nvim_set_option()
117#[cfg_attr(
118    feature = "neovim-0-11", // On 0.11 and Nightly.
119    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    /// Binding to [`nvim_buf_get_option()`][1].
140    ///
141    /// Gets a buffer option value.
142    ///
143    /// [1]: https://neovim.io/doc/user/api.html#nvim_buf_get_option()
144    #[cfg_attr(
145        feature = "neovim-0-11", // On 0.11 and Nightly.
146        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    /// Binding to [`nvim_buf_set_option()`][1].
161    ///
162    /// Sets a buffer option value. Passing `None` as value deletes the option
163    /// (only works if there's a global fallback).
164    ///
165    /// [1]: https://neovim.io/doc/user/api.html#nvim_buf_set_option()
166    #[cfg_attr(
167        feature = "neovim-0-11", // On 0.11 and Nightly.
168        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    /// Binding to [`nvim_win_get_option()`][1].
191    ///
192    /// Gets a window option value.
193    ///
194    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_option()
195    #[cfg_attr(
196        feature = "neovim-0-11", // On 0.11 and Nightly.
197        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    /// Binding to [`nvim_win_set_option()`][1].
212    ///
213    /// Sets a window option value. Passing `None` as value deletes the option
214    /// (only works if there's a global fallback).
215    ///
216    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_set_option()
217    #[cfg_attr(
218        feature = "neovim-0-11", // On 0.11 and Nightly.
219        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}