1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use types as nvim;

use crate::choose;
use crate::ffi::win_config::*;
use crate::types::*;
use crate::Result;
use crate::{Buffer, Window};

/// Binding to [`nvim_open_win()`][1].
///
/// Opens a new floating or external window.
///
/// [1]: https://neovim.io/doc/user/api.html#nvim_open_win()
pub fn open_win(
    buf: &Buffer,
    enter: bool,
    config: &WindowConfig,
) -> Result<Window> {
    let mut err = nvim::Error::new();
    let handle =
        unsafe { nvim_open_win(buf.0, enter, &config.into(), &mut err) };
    choose!(err, Ok(handle.into()))
}

impl Window {
    /// Binding to [`nvim_win_get_config()`][1].
    ///
    /// Gets the window configuration.
    ///
    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_config()
    pub fn get_config(&self) -> Result<WindowConfig> {
        let mut err = nvim::Error::new();

        let out = unsafe {
            nvim_win_get_config(
                self.0,
                #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
                types::arena(),
                &mut err,
            )
        };

        let out = WindowConfig::try_from(out)?;

        choose!(err, Ok(out))
    }

    /// Binding to [`nvim_win_get_config()`][1].
    ///
    /// Configures the window layout. Only for floating and external windows.
    ///
    /// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_config()
    pub fn set_config(&mut self, config: &WindowConfig) -> Result<()> {
        let mut err = nvim::Error::new();
        unsafe { nvim_win_set_config(self.0, &config.into(), &mut err) };
        choose!(err, ())
    }
}