reovim_kernel/core/option/scope.rs
1//! Option scope types.
2//!
3//! Defines where an option applies (global, buffer, window).
4
5use std::fmt;
6
7use crate::mm::{BufferId, WindowId};
8
9/// Scope where an option applies.
10///
11/// Determines the granularity of option storage:
12/// - `Global`: Single value for the entire editor
13/// - `Buffer`: Per-buffer values (e.g., `tabwidth`)
14/// - `Window`: Per-window values (e.g., `number`)
15///
16/// Window-scoped options can also have buffer-local defaults.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18pub enum OptionScope {
19 /// Applies globally to the entire editor.
20 #[default]
21 Global,
22
23 /// Per-buffer setting (e.g., `filetype`, `tabwidth`, `expandtab`).
24 Buffer,
25
26 /// Per-window setting (e.g., `number`, `relativenumber`, `wrap`).
27 Window,
28}
29
30impl OptionScope {
31 /// Get display name for this scope.
32 #[must_use]
33 pub const fn display_name(self) -> &'static str {
34 match self {
35 Self::Global => "global",
36 Self::Buffer => "buffer",
37 Self::Window => "window",
38 }
39 }
40}
41
42impl fmt::Display for OptionScope {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 write!(f, "{}", self.display_name())
45 }
46}
47
48/// Runtime scope identifier for option access.
49///
50/// Used when getting or setting option values to specify the exact
51/// scope context (which buffer, which window, or global).
52#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
53pub enum OptionScopeId {
54 /// Global scope (no buffer/window context).
55 #[default]
56 Global,
57 /// Buffer-local scope with specific buffer ID.
58 Buffer(BufferId),
59 /// Window-local scope with specific window ID.
60 Window(WindowId),
61}
62
63impl fmt::Display for OptionScopeId {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 Self::Global => write!(f, "global"),
67 Self::Buffer(id) => write!(f, "buffer({id:?})"),
68 Self::Window(id) => write!(f, "window({id:?})"),
69 }
70 }
71}