nvim_oxi_api/opts/
get_autocmds.rs

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