Skip to main content

Range

Enum Range 

Source
pub enum Range {
    Span {
        start: RangeBound,
        end: RangeBound,
    },
    CurrentLine,
    Whole,
    Selection,
    Custom(RangeId),
}
Expand description

A vim range argument: which lines an ex-command or operator covers, before it is resolved against a document.

Symbolic on purpose: % or '<,'> means different lines in different buffers and at different times, so the value is carried unresolved (in a crate::CommandInvocation, a recorded macro, a plugin call) and each consumer resolves it at apply time.

Resolution coverage is uneven today. The dispatcher’s operator path resolves CurrentLine, Whole and Selection and rejects Span / Custom with crate::CommandError::InvalidArgs; :narrow resolves every form (patterns fall back to the cursor line, Custom to the cursor line). No parser in the tree produces Span or Custom yet.

§Examples

use lattice_grammar::{Range, RangeBound};

// `:.,+10` -- from the cursor line to ten lines below it.
let r = Range::Span {
    start: RangeBound::CurrentLine,
    end: RangeBound::Offset {
        base: Box::new(RangeBound::CurrentLine),
        delta: 10,
    },
};
assert!(matches!(r, Range::Span { .. }));

// `:'<,'>` -- the last Visual selection, via its marks.
let visual = Range::Span {
    start: RangeBound::Mark('<'),
    end: RangeBound::Mark('>'),
};
assert_ne!(visual, Range::Selection); // same lines, different form

Variants§

§

Span

:1,5, :'<,'>, :.,+10, etc. Both ends inclusive; a consumer that resolves start below end swaps them (vim asks, lattice swaps silently).

Fields

§start: RangeBound

First line of the range.

§end: RangeBound

Last line of the range (inclusive).

§

CurrentLine

:. – the cursor’s line.

§

Whole

:% – every line of the buffer.

§

Selection

The current Visual / active region (the default range while Visual is active). Unlike the other forms it keeps Visual’s shape: the dispatcher resolves it charwise (head-inclusive), linewise or blockwise according to the selection’s mode.

§

Custom(RangeId)

Plugin-registered custom range (e.g., a git-hunk-range plugin), identified by its registry id.

Trait Implementations§

Source§

impl Clone for Range

Source§

fn clone(&self) -> Range

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 Range

Source§

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

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

impl<'de> Deserialize<'de> for Range

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Range

Source§

impl PartialEq for Range

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Range

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Range

Auto Trait Implementations§

§

impl Freeze for Range

§

impl RefUnwindSafe for Range

§

impl Send for Range

§

impl Sync for Range

§

impl Unpin for Range

§

impl UnsafeUnpin for Range

§

impl UnwindSafe for Range

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

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