nvim_oxi_api/opts/
exec_autocmds.rs

1use crate::Buffer;
2use crate::{StringOrInt, StringOrListOfStrings};
3
4/// Options passed to [`exec_autocmds()`](crate::exec_autocmds).
5#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
6#[derive(Clone, Debug, Default, macros::OptsBuilder)]
7#[repr(C)]
8pub struct ExecAutocmdsOpts {
9    #[builder(mask)]
10    mask: u64,
11
12    /// A specific [`Buffer`] for buffer-local autocommands. Cannot be used
13    /// together with [`patterns`](ExecAutocmdsOptsBuilder::patterns).
14    #[builder(argtype = "Buffer", inline = "{0}.0")]
15    buffer: types::BufHandle,
16
17    /// The autocommand group name or id to match against.
18    #[builder(
19        generics = "G: StringOrInt",
20        argtype = "G",
21        inline = "{0}.to_object()"
22    )]
23    group: types::Object,
24
25    /// Whether to process the modeline after the autocommands.
26    #[builder(argtype = "bool")]
27    modeline: types::Boolean,
28
29    /// Patterns to match against. Cannot be used together with
30    /// [`buffer`](ExecAutocmdsOptsBuilder::buffer).
31    #[builder(
32        generics = "P: StringOrListOfStrings",
33        method = "patterns",
34        argtype = "P",
35        inline = "{0}.to_object()"
36    )]
37    pattern: types::Object,
38
39    #[builder(
40        generics = "D: Into<types::Object>",
41        argtype = "D",
42        inline = "{0}.into()"
43    )]
44    data: types::Object,
45}
46
47/// Options passed to [`exec_autocmds()`](crate::exec_autocmds).
48#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
49#[derive(Clone, Debug, Default)]
50#[repr(C)]
51pub struct ExecAutocmdsOpts {
52    data: types::Object,
53    group: types::Object,
54    buffer: types::Object,
55    patterns: types::Object,
56    modeline: types::Object,
57}
58
59#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
60impl ExecAutocmdsOpts {
61    #[inline(always)]
62    pub fn builder() -> ExecAutocmdsOptsBuilder {
63        ExecAutocmdsOptsBuilder::default()
64    }
65}
66
67#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
68#[derive(Clone, Default)]
69pub struct ExecAutocmdsOptsBuilder(ExecAutocmdsOpts);
70
71#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
72impl ExecAutocmdsOptsBuilder {
73    /// A specific [`Buffer`] for buffer-local autocommands. Cannot be used
74    /// together with [`patterns`](ExecAutocmdsOptsBuilder::patterns).
75    #[inline]
76    pub fn buffer(&mut self, buffer: Buffer) -> &mut Self {
77        self.0.buffer = buffer.into();
78        self
79    }
80
81    #[inline]
82    pub fn data(&mut self, any: impl Into<types::Object>) -> &mut Self {
83        self.0.data = any.into();
84        self
85    }
86
87    /// The autocommand group name or id to match against.
88    #[inline]
89    pub fn group<Grp>(&mut self, group: Grp) -> &mut Self
90    where
91        Grp: StringOrInt,
92    {
93        self.0.group = group.to_object();
94        self
95    }
96
97    /// Whether to process the modeline after the autocommands.
98    #[inline]
99    pub fn modeline(&mut self, modeline: bool) -> &mut Self {
100        self.0.modeline = modeline.into();
101        self
102    }
103
104    /// Patterns to match against. Cannot be used together with
105    /// [`buffer`](ExecAutocmdsOptsBuilder::buffer).
106    #[inline]
107    pub fn patterns<Patterns>(&mut self, patterns: Patterns) -> &mut Self
108    where
109        Patterns: StringOrListOfStrings,
110    {
111        self.0.patterns = patterns.to_object();
112        self
113    }
114
115    #[inline]
116    pub fn build(&mut self) -> ExecAutocmdsOpts {
117        std::mem::take(&mut self.0)
118    }
119}