nvim_api/types/
keymap_infos.rs

1use nvim_types::{
2    conversion::{self, FromObject},
3    serde::Deserializer,
4    Function,
5    Object,
6};
7use serde::Deserialize;
8
9use super::Mode;
10use crate::serde_utils as utils;
11
12#[non_exhaustive]
13#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
14pub struct KeymapInfos {
15    /// Whether the mapping is local to a specific buffer.
16    #[serde(deserialize_with = "utils::bool_from_int")]
17    pub buffer: bool,
18
19    /// Optional callback triggered by the keymap.
20    pub callback: Option<Function<(), ()>>,
21
22    /// Whether the keymap argument is an expression.
23    #[serde(deserialize_with = "utils::bool_from_int")]
24    pub expr: bool,
25
26    /// The left-hand side of the mapping.
27    pub lhs: String,
28
29    /// The number where a script-local mapping is defined, if known.
30    #[serde(deserialize_with = "utils::zero_is_none")]
31    pub lnum: Option<u32>,
32
33    /// The modes for which the keymap is enabled.
34    pub mode: Mode,
35
36    /// Whether the right-hand side of the mapping is not remappable.
37    #[serde(deserialize_with = "utils::bool_from_int")]
38    pub noremap: bool,
39
40    /// For buffer-local mappings, whether Neovim should wait for more
41    /// characters to be typed if there's a global mapping that could also
42    /// match. See `:h map-nowait` for more details.
43    #[serde(deserialize_with = "utils::bool_from_int")]
44    pub nowait: bool,
45
46    /// The right-hand side of the mapping.
47    #[serde(default, deserialize_with = "utils::empty_string_is_none")]
48    pub rhs: Option<String>,
49
50    /// Whether the mapping was defined with `<script>`.
51    #[serde(deserialize_with = "utils::bool_from_int")]
52    pub script: bool,
53
54    /// The script-local ID, used for `<sid>` mappings.
55    pub sid: i32,
56
57    /// Whether the keymap is silent.
58    #[serde(deserialize_with = "utils::bool_from_int")]
59    pub silent: bool,
60}
61
62impl FromObject for KeymapInfos {
63    fn from_object(obj: Object) -> Result<Self, conversion::Error> {
64        Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
65    }
66}