nvim_api/opts/
set_keymap.rs1use derive_builder::Builder;
2use nvim_types::{self as nvim, NonOwning, Object};
3
4use crate::ToFunction;
5
6#[derive(Clone, Debug, Default, PartialEq, Builder)]
9#[builder(default, build_fn(private, name = "fallible_build"))]
10pub struct SetKeymapOpts {
11 #[builder(setter(custom))]
12 callback: Object,
13
14 #[builder(setter(custom))]
15 desc: Object,
16
17 #[builder(setter(strip_option))]
19 expr: Option<bool>,
20
21 #[builder(setter(strip_option))]
23 noremap: Option<bool>,
24
25 #[builder(setter(strip_option))]
29 nowait: Option<bool>,
30
31 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
35 #[cfg_attr(
36 docsrs,
37 doc(cfg(any(feature = "neovim-0-8", feature = "neovim-nightly")))
38 )]
39 #[builder(setter(strip_option))]
40 replace_keycodes: Option<bool>,
41
42 #[builder(setter(strip_option))]
45 script: Option<bool>,
46
47 #[builder(setter(strip_option))]
49 silent: Option<bool>,
50
51 #[builder(setter(strip_option))]
54 unique: Option<bool>,
55}
56
57impl SetKeymapOpts {
58 #[inline(always)]
59 pub fn builder() -> SetKeymapOptsBuilder {
61 SetKeymapOptsBuilder::default()
62 }
63}
64
65impl SetKeymapOptsBuilder {
66 pub fn callback<F>(&mut self, fun: F) -> &mut Self
68 where
69 F: ToFunction<(), ()>,
70 {
71 self.callback = Some(fun.to_object());
72 self
73 }
74
75 pub fn desc(&mut self, desc: &str) -> &mut Self {
77 self.desc = Some(nvim::String::from(desc).into());
78 self
79 }
80
81 pub fn build(&mut self) -> SetKeymapOpts {
82 self.fallible_build().expect("never fails, all fields have defaults")
83 }
84}
85
86#[derive(Default)]
87#[allow(non_camel_case_types)]
88#[repr(C)]
89pub(crate) struct KeyDict_keymap<'a> {
90 desc: NonOwning<'a, Object>,
91 expr: Object,
92 script: Object,
93 silent: Object,
94 unique: Object,
95 nowait: Object,
96 noremap: Object,
97 callback: NonOwning<'a, Object>,
98 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
99 replace_keycodes: Object,
100}
101
102impl<'a> From<&'a SetKeymapOpts> for KeyDict_keymap<'a> {
103 fn from(opts: &'a SetKeymapOpts) -> Self {
104 Self {
105 desc: opts.desc.non_owning(),
106 expr: opts.expr.into(),
107 script: opts.script.into(),
108 silent: opts.silent.into(),
109 unique: opts.unique.into(),
110 nowait: opts.nowait.into(),
111 noremap: opts.noremap.into(),
112 callback: opts.callback.non_owning(),
113 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
114 replace_keycodes: opts.replace_keycodes.into(),
115 }
116 }
117}