1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::Buffer;
use crate::{StringOrInt, StringOrListOfStrings};

/// Options passed to [`exec_autocmds()`](crate::exec_autocmds).
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[derive(Clone, Debug, Default, macros::OptsBuilder)]
#[repr(C)]
pub struct ExecAutocmdsOpts {
    #[builder(mask)]
    mask: u64,

    /// A specific [`Buffer`] for buffer-local autocommands. Cannot be used
    /// together with [`patterns`](ExecAutocmdsOptsBuilder::patterns).
    #[builder(argtype = "Buffer", inline = "{0}.0")]
    buffer: types::BufHandle,

    /// The autocommand group name or id to match against.
    #[builder(
        generics = "G: StringOrInt",
        argtype = "G",
        inline = "{0}.to_object()"
    )]
    group: types::Object,

    /// Whether to process the modeline after the autocommands.
    #[builder(argtype = "bool")]
    modeline: types::Boolean,

    /// Patterns to match against. Cannot be used together with
    /// [`buffer`](ExecAutocmdsOptsBuilder::buffer).
    #[builder(
        generics = "P: StringOrListOfStrings",
        method = "patterns",
        argtype = "P",
        inline = "{0}.to_object()"
    )]
    pattern: types::Object,

    #[builder(
        generics = "D: Into<types::Object>",
        argtype = "D",
        inline = "{0}.into()"
    )]
    data: types::Object,
}

/// Options passed to [`exec_autocmds()`](crate::exec_autocmds).
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct ExecAutocmdsOpts {
    data: types::Object,
    group: types::Object,
    buffer: types::Object,
    patterns: types::Object,
    modeline: types::Object,
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl ExecAutocmdsOpts {
    #[inline(always)]
    pub fn builder() -> ExecAutocmdsOptsBuilder {
        ExecAutocmdsOptsBuilder::default()
    }
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Default)]
pub struct ExecAutocmdsOptsBuilder(ExecAutocmdsOpts);

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl ExecAutocmdsOptsBuilder {
    /// A specific [`Buffer`] for buffer-local autocommands. Cannot be used
    /// together with [`patterns`](ExecAutocmdsOptsBuilder::patterns).
    #[inline]
    pub fn buffer(&mut self, buffer: Buffer) -> &mut Self {
        self.0.buffer = buffer.into();
        self
    }

    #[inline]
    pub fn data(&mut self, any: impl Into<types::Object>) -> &mut Self {
        self.0.data = any.into();
        self
    }

    /// The autocommand group name or id to match against.
    #[inline]
    pub fn group<Grp>(&mut self, group: Grp) -> &mut Self
    where
        Grp: StringOrInt,
    {
        self.0.group = group.to_object();
        self
    }

    /// Whether to process the modeline after the autocommands.
    #[inline]
    pub fn modeline(&mut self, modeline: bool) -> &mut Self {
        self.0.modeline = modeline.into();
        self
    }

    /// Patterns to match against. Cannot be used together with
    /// [`buffer`](ExecAutocmdsOptsBuilder::buffer).
    #[inline]
    pub fn patterns<Patterns>(&mut self, patterns: Patterns) -> &mut Self
    where
        Patterns: StringOrListOfStrings,
    {
        self.0.patterns = patterns.to_object();
        self
    }

    #[inline]
    pub fn build(&mut self) -> ExecAutocmdsOpts {
        std::mem::take(&mut self.0)
    }
}