nvim_oxi_api/opts/
clear_autocmds.rs

1use crate::Buffer;
2use crate::StringOrInt;
3
4/// Options passed to [`clear_autocmds()`](crate::clear_autocmds).
5#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
6#[derive(Clone, Debug, Default)]
7#[repr(C)]
8pub struct ClearAutocmdsOpts {
9    event: types::Object,
10    group: types::Object,
11    buffer: types::Object,
12    pattern: types::Object,
13}
14
15#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
16impl ClearAutocmdsOpts {
17    /// Creates a new [`ClearAutocmdsOptsBuilder`].
18    #[inline(always)]
19    pub fn builder() -> ClearAutocmdsOptsBuilder {
20        ClearAutocmdsOptsBuilder::default()
21    }
22}
23
24#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
25#[derive(Clone, Default)]
26pub struct ClearAutocmdsOptsBuilder(ClearAutocmdsOpts);
27
28#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
29impl ClearAutocmdsOptsBuilder {
30    /// Only clear the autocommands local to a specific `Buffer`. Cannot be
31    /// used together with [`patterns`](ClearAutocmdsOptsBuilder::patterns).
32    #[inline]
33    pub fn buffer(&mut self, buffer: Buffer) -> &mut Self {
34        self.0.buffer = buffer.into();
35        self
36    }
37
38    /// Clear all the autocommands triggered by one or more of the specified
39    /// events.
40    #[inline]
41    pub fn events<'a, I>(&mut self, iter: I) -> &mut Self
42    where
43        I: IntoIterator<Item = &'a str>,
44    {
45        self.0.event = types::Array::from_iter(iter).into();
46        self
47    }
48
49    /// Only clear the autocommands matching specific patterns. For example, if
50    /// you have `"*.py"` as a pattern for a particular autocommand, you must
51    /// pass that exact pattern to clear it. Cannot be used together with
52    /// [`buffer`](ClearAutocmdsOptsBuilder::buffer).
53    #[inline]
54    pub fn patterns<'a, I>(&mut self, iter: I) -> &mut Self
55    where
56        I: IntoIterator<Item = &'a str>,
57    {
58        self.0.pattern = types::Array::from_iter(iter).into();
59        self
60    }
61
62    /// Only clear the autocommands belonging to a specific augroup. The
63    /// augroup can be specified by both id and name.
64    #[inline]
65    pub fn group<Grp>(&mut self, group: Grp) -> &mut Self
66    where
67        Grp: StringOrInt,
68    {
69        self.0.group = group.to_object();
70        self
71    }
72
73    #[inline]
74    pub fn build(&mut self) -> ClearAutocmdsOpts {
75        std::mem::take(&mut self.0)
76    }
77}
78
79/// Options passed to [`clear_autocmds()`](crate::clear_autocmds).
80#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
81#[derive(Clone, Debug, Default, macros::OptsBuilder)]
82#[repr(C)]
83pub struct ClearAutocmdsOpts {
84    #[builder(mask)]
85    mask: u64,
86
87    /// Only clear the autocommands local to a specific `Buffer`. Cannot be
88    /// used together with [`patterns`](ClearAutocmdsOptsBuilder::patterns).
89    #[builder(argtype = "Buffer", inline = "{0}.0")]
90    buffer: types::BufHandle,
91
92    /// Clear all the autocommands triggered by one or more of the specified
93    /// events.
94    #[builder(
95        generics = "'a, I: IntoIterator<Item = &'a str>",
96        method = "events",
97        argtype = "I",
98        inline = "types::Array::from_iter({0}).into()"
99    )]
100    event: types::Object,
101
102    /// Only clear the autocommands matching specific patterns. For example, if
103    /// you have `"*.py"` as a pattern for a particular autocommand, you must
104    /// pass that exact pattern to clear it. Cannot be used together with
105    /// [`buffer`](ClearAutocmdsOptsBuilder::buffer).
106    #[builder(
107        generics = "G: StringOrInt",
108        argtype = "G",
109        inline = "{0}.to_object()"
110    )]
111    group: types::Object,
112
113    /// Only clear the autocommands belonging to a specific augroup. The
114    /// augroup can be specified by both id and name.
115    #[builder(
116        generics = "'a, I: IntoIterator<Item = &'a str>",
117        method = "patterns",
118        argtype = "I",
119        inline = "types::Array::from_iter({0}).into()"
120    )]
121    pattern: types::Object,
122}