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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/// Contains utility functions useful for neovim/vim operations
pub mod utils;

mod var;
pub use var::*;

use serde::de::DeserializeOwned;
use serde_json::Value;
use std::io;

/// Retrieves a vim variable with `b:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_buffer_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Buffer;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_buffer_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_buffer_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Buffer;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `w:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_window_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Window;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_window_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_window_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Window;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `t:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_tabpage_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Tabpage;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_tabpage_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_tabpage_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Tabpage;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `l:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_local_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Local;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_local_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_local_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Local;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `s:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_script_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Script;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_script_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_script_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Script;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `a:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_function_arg_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::FunctionArg;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_function_arg_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_function_arg_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::FunctionArg;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `g:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_global_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Global;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_global_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_global_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Global;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}

/// Retrieves a vim variable with `v:` scope using whatever neovim/vim
/// instance is available in the current path
pub fn load_vim_var(name: &str, allow_zero: bool) -> io::Result<Option<Value>> {
    let cmd = utils::find_cmd()?;
    let scope = Scope::Vim;
    VimVar::new(cmd, scope, name).load(allow_zero)
}

/// Same as [`Self::load_vim_var`], but converts to the specified type
/// after being loaded, returing an [`io::Error`] if failing to convert
pub fn load_typed_vim_var<T>(name: &str, allow_zero: bool) -> io::Result<Option<T>>
where
    T: DeserializeOwned,
{
    let cmd = utils::find_cmd()?;
    let scope = Scope::Vim;
    VimVar::new(cmd, scope, name).load_typed(allow_zero)
}