rsvim_core 0.1.3-alpha.2

The core library for RSVIM text editor.
Documentation
//! Buffer options.

pub mod file_encoding;
pub mod file_format;

#[cfg(test)]
mod file_encoding_tests;
#[cfg(test)]
mod file_format_tests;

pub use file_encoding::*;
pub use file_format::*;

// Default values.
pub const TAB_STOP: u8 = 8;
pub const EXPAND_TAB: bool = false;
pub const SHIFT_WIDTH: u8 = 8;
pub const FILE_ENCODING: FileEncodingOption = FileEncodingOption::Utf8;
#[cfg(target_family = "windows")]
pub const FILE_FORMAT: FileFormatOption = FileFormatOption::Dos;
#[cfg(not(target_family = "windows"))]
pub const FILE_FORMAT: FileFormatOption = FileFormatOption::Unix;
pub const FIX_END_OF_LINE: bool = true;

#[derive(Debug, Copy, Clone, derive_builder::Builder)]
/// Buffer options.
pub struct BufferOptions {
  #[builder(default = EXPAND_TAB)]
  expand_tab: bool,

  #[builder(default = TAB_STOP)]
  tab_stop: u8,

  #[builder(default = SHIFT_WIDTH)]
  shift_width: u8,

  #[builder(default = FILE_ENCODING)]
  file_encoding: FileEncodingOption,

  #[builder(default = FILE_FORMAT)]
  file_format: FileFormatOption,

  #[builder(default = FIX_END_OF_LINE)]
  fix_end_of_line: bool,
}

impl BufferOptions {
  /// Buffer 'tab-stop' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27tabstop%27>.
  pub fn tab_stop(&self) -> u8 {
    self.tab_stop
  }

  pub fn set_tab_stop(&mut self, value: u8) {
    self.tab_stop = value;
  }

  /// Buffer 'expand-tab' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27expandtab%27>.
  pub fn expand_tab(&self) -> bool {
    self.expand_tab
  }

  pub fn set_expand_tab(&mut self, value: bool) {
    self.expand_tab = value;
  }

  /// Buffer 'shift-width' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27shiftwidth%27>.
  pub fn shift_width(&self) -> u8 {
    self.shift_width
  }

  pub fn set_shift_width(&mut self, value: u8) {
    self.shift_width = value;
  }

  /// Buffer 'file-encoding' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27fileencoding%27>.
  pub fn file_encoding(&self) -> FileEncodingOption {
    self.file_encoding
  }

  pub fn set_file_encoding(&mut self, value: FileEncodingOption) {
    self.file_encoding = value;
  }

  /// Buffer 'file-format' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27fileformat%27>.
  pub fn file_format(&self) -> FileFormatOption {
    self.file_format
  }

  pub fn set_file_format(&mut self, value: FileFormatOption) {
    self.file_format = value;
  }

  /// Buffer 'fix-end-of-line' option.
  ///
  /// See: <https://vimhelp.org/options.txt.html#%27fixendofline%27>.
  pub fn fix_end_of_line(&self) -> bool {
    self.fix_end_of_line
  }

  pub fn set_fix_end_of_line(&mut self, value: bool) {
    self.fix_end_of_line = value;
  }
}