nvim_utils/vim/
ext.rs

1//! Utilities that don't directly map to the Neovim API but make use of it or extend it
2
3use crate::prelude::*;
4use std::path::PathBuf;
5
6/// Creats a session at the given path using `mksession!`
7///
8/// ## Example
9/// ```rust
10/// use nvim_utils::prelude::*;
11/// use std::path::PathBuf;
12///
13/// fn my_module(lua: &Lua) -> LuaResult<()> {
14///     vim::ext::mksession(lua, PathBuf::from("~/.sessions/session.vim"))?;
15///     Ok(())
16/// }
17/// ```
18pub fn mksession<'a>(lua: &Lua, path: PathBuf) -> LuaResult<()> {
19    vim::cmd(
20        lua,
21        &format!("mksession! {}", String::from(path.to_string_lossy())),
22    )
23}
24
25pub mod log {
26    //! Utility functions for calling `vim.notify` with different log levels
27    use crate::prelude::*;
28
29    /// Calls notify with log level `Info`
30    pub fn info(lua: &Lua, msg: &str) -> LuaResult<()> {
31        vim::notify(lua, msg, vim::log::LogLevel::Info)
32    }
33
34    /// Calls notify with log level `Warn`
35    pub fn warn(lua: &Lua, msg: &str) -> LuaResult<()> {
36        vim::notify(lua, msg, vim::log::LogLevel::Warn)
37    }
38
39    /// Calls notify with log level `Error`
40    pub fn error(lua: &Lua, msg: &str) -> LuaResult<()> {
41        vim::notify(lua, msg, vim::log::LogLevel::Error)
42    }
43
44    /// Calls notify with log level `Trace`
45    pub fn trace(lua: &Lua, msg: &str) -> LuaResult<()> {
46        vim::notify(lua, msg, vim::log::LogLevel::Trace)
47    }
48
49    /// Calls notify with log level `Debug`
50    pub fn debug(lua: &Lua, msg: &str) -> LuaResult<()> {
51        vim::notify(lua, msg, vim::log::LogLevel::Debug)
52    }
53}