Skip to main content

ActivationPolicy

Enum ActivationPolicy 

Source
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

Source

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

Source§

fn clone(&self) -> ActivationPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ActivationPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ActivationPolicy

Source§

fn default() -> ActivationPolicy

Returns the “default value” for a type. Read more
Source§

impl Eq for ActivationPolicy

Source§

impl PartialEq for ActivationPolicy

Source§

fn eq(&self, other: &ActivationPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ActivationPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more