pub enum ActivationPolicy {
Manual,
Global,
Universal,
Majors(Vec<ModeId>),
}Expand description
A minor mode’s default auto-activation policy — the allowlist of
major modes it activates inside, as the mode itself ships it
(mode-architecture.md §7.4). The host’s minor-activation resolver
subscribes once to [lattice_protocol::Event::MajorEntered] and,
for each registered minor whose policy admits
the entered major, activates it.
This is the mode’s declared default. Config
(<mode>.activation = global | <allowlist> | off) folds over it;
that fold is the host’s job (SN.3), not the mode’s. The default on
the Mode trait is Manual: a mode auto-activates
nowhere until it opts in or the user does. Leaving the onus on the
user is a legitimate choice — some modes won’t ship a sensible
default and shouldn’t guess.
Only enabled minors are auto-activated
(ModeRegistry::is_minor_enabled):
native modes are enabled at registration, plugin modes are not.
§Examples
use lattice_core::BufferKind;
use lattice_mode::{ActivationPolicy, ModeId};
// A content minor: every real document, never a synthetic buffer.
assert!(ActivationPolicy::Global.admits("rust-mode", BufferKind::Document));
assert!(!ActivationPolicy::Global.admits("help-mode", BufferKind::Help));
// A universal leader: everywhere the user can focus.
assert!(ActivationPolicy::Universal.admits("help-mode", BufferKind::Help));
// An allowlist is matched on the major's id, independent of kind.
let tables = ActivationPolicy::Majors(vec![
ModeId::new("markdown-mode"),
ModeId::new("org-mode"),
]);
assert!(tables.admits("org-mode", BufferKind::Document));
assert!(!tables.admits("rust-mode", BufferKind::Document));
// The trait default auto-activates nowhere.
assert!(!ActivationPolicy::default().admits("rust-mode", BufferKind::Document));Variants§
Manual
Never auto-activate; only explicit (user / host / :<mode>)
activation turns the mode on. The trait default.
Global
Auto-activate on every document buffer that enters a major
mode (scoped to [BufferKind::Document]). The right policy for
content modes (snippets, LSP, …) that only make sense over
user-edited text, not synthetic UI buffers.
Universal
Auto-activate on every buffer kind that enters a major mode —
documents and synthetic UI buffers (*messages*, help, file
tree, oil, terminal). For universal contributions like the
emacs-keys <C-x> leader, where navigation chords (switch
buffer, switch pane, quit) should work everywhere the user can
focus — mirroring emacs, whose C-x map is live in *Messages*
and every other buffer. NOT for content modes (use Global).
Mode-local keymaps are gated by binding mode, so Terminal-Insert
keystroke passthrough is unaffected by a Normal-only leader.
Majors(Vec<ModeId>)
Auto-activate only when the entered major’s id is in this
allowlist. An empty list behaves like Manual
(matches no major).
Implementations§
Source§impl ActivationPolicy
impl ActivationPolicy
Sourcepub fn admits(&self, major: &str, buffer_kind: BufferKind) -> bool
pub fn admits(&self, major: &str, buffer_kind: BufferKind) -> bool
Does this policy auto-activate when a buffer of kind
buffer_kind enters the major mode named major?
Global is scoped to real document buffers
([BufferKind::Document]) — every code/text buffer, not the
synthetic UI buffers (file tree, help, *messages*, terminal,
…). Universal admits every kind (documents and synthetic
buffers) for universal-leader modes. A mode that wants a narrow
synthetic opt-in instead names that buffer’s major explicitly
via Majors([..]), which is kind-independent.
Trait Implementations§
Source§impl Clone for ActivationPolicy
impl Clone for ActivationPolicy
Source§fn clone(&self) -> ActivationPolicy
fn clone(&self) -> ActivationPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ActivationPolicy
impl Debug for ActivationPolicy
Source§impl Default for ActivationPolicy
impl Default for ActivationPolicy
Source§fn default() -> ActivationPolicy
fn default() -> ActivationPolicy
impl Eq for ActivationPolicy
Source§impl PartialEq for ActivationPolicy
impl PartialEq for ActivationPolicy
impl StructuralPartialEq for ActivationPolicy
Auto Trait Implementations§
impl Freeze for ActivationPolicy
impl RefUnwindSafe for ActivationPolicy
impl Send for ActivationPolicy
impl Sync for ActivationPolicy
impl Unpin for ActivationPolicy
impl UnsafeUnpin for ActivationPolicy
impl UnwindSafe for ActivationPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.