Skip to content

Commit

Permalink
api: update ExecAutocmdsOpts for nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Oct 1, 2023
1 parent c8b4df3 commit 566a32d
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions crates/oxi-api/src/opts/exec_autocmds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use oxi_types::Object;
#[cfg(feature = "neovim-nightly")]
use oxi_types::{Boolean, BufHandle};

use crate::Buffer;
use crate::{StringOrInt, StringOrListOfStrings};
Expand All @@ -20,10 +22,22 @@ pub struct ExecAutocmdsOpts {
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct ExecAutocmdsOpts {
buffer: Object,
/// <modeline><patterns><buffer><group><data>1
mask: u64,

/// 3rd in the mask.
buffer: BufHandle,

/// 2nd in the mask.
group: Object,
modeline: Object,

/// 5th in the mask.
modeline: Boolean,

/// 4th in the mask.
patterns: Object,

/// 1st in the mask.
data: Object,
}

Expand All @@ -42,13 +56,25 @@ impl ExecAutocmdsOptsBuilder {
/// together with [`patterns`](ExecAutocmdsOptsBuilder::patterns).
#[inline]
pub fn buffer(&mut self, buffer: Buffer) -> &mut Self {
self.0.data = buffer.into();
#[cfg(not(feature = "neovim-nightly"))]
{
self.0.buffer = buffer.into();
}
#[cfg(feature = "neovim-nightly")]
{
self.0.buffer = buffer.0;
self.0.mask |= 0b1001;
}
self
}

#[inline]
pub fn data(&mut self, any: impl Into<Object>) -> &mut Self {
self.0.data = any.into();
#[cfg(feature = "neovim-nightly")]
{
self.0.mask |= 0b11;
}
self
}

Expand All @@ -59,13 +85,25 @@ impl ExecAutocmdsOptsBuilder {
Grp: StringOrInt,
{
self.0.group = group.to_object();
#[cfg(feature = "neovim-nightly")]
{
self.0.mask |= 0b101;
}
self
}

/// Whether to process the modeline after the autocommands.
#[inline]
pub fn modeline(&mut self, modeline: bool) -> &mut Self {
self.0.modeline = modeline.into();
#[cfg(not(feature = "neovim-nightly"))]
{
self.0.modeline = modeline.into();
}
#[cfg(feature = "neovim-nightly")]
{
self.0.modeline = modeline;
self.0.mask |= 0b100001;
}
self
}

Expand All @@ -77,6 +115,10 @@ impl ExecAutocmdsOptsBuilder {
Patterns: StringOrListOfStrings,
{
self.0.patterns = patterns.to_object();
#[cfg(feature = "neovim-nightly")]
{
self.0.mask |= 0b10001;
}
self
}

Expand Down

0 comments on commit 566a32d

Please sign in to comment.